Closed ft0907 closed 1 year ago
Try to add mergeServiceFiles()
to shadowJar task.
I'll close this issue due to inactivity, if you're still having the issue you can comment to reopen it.
I may have run into the same problem. For some reason I don't manage to get sl4j2 into my jpackage deployment.
Steps to reproduce, checkout this branch on a Windows machine.
Build the destribution
gradlew :jpackageImage
Run the application
build\jpackage\listFix()\listFix().exe
Throws the following error:
ERROR StatusLogger Unable to load services for service class org.apache.logging.log4j.spi.Provider
java.util.ServiceConfigurationError: org.apache.logging.log4j.spi.Provider: module listFix.merged.module does not declare `uses`
at java.base/java.util.ServiceLoader.fail(Unknown Source)
at java.base/java.util.ServiceLoader.checkCaller(Unknown Source)
at java.base/java.util.ServiceLoader.<init>(Unknown Source)
at java.base/java.util.ServiceLoader.load(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ServiceLoaderUtil.callServiceLoader(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ServiceLoaderUtil$ServiceLoaderSpliterator.<init>(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ServiceLoaderUtil.loadClassloaderServices(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ProviderUtil.<init>(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ProviderUtil.lazyInit(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.util.ProviderUtil.hasProviders(Unknown Source)
at listFix.merged.module@3.0.1.6/org.apache.logging.log4j.LogManager.<clinit>(Unknown Source)
at listFix.app/listfix.view.GUIScreen.<clinit>(Unknown Source)
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Exception while removing reference.
Based on given suggestions I tried to use com.github.johnrengelman.shadow
plugin in combination with mergeServiceFiles()
, but it did not resolve this issue.
References:
Seems also related to: #209
I manage to get it to working by each class generating a uses Exception, until no more exceptions are thrown. I wonder if the "merged.module" is merging module dependencies correctly.
jlink {
//.....
mergedModule {
additive = true
uses "org.apache.logging.log4j.spi.Provider"
uses "org.apache.logging.log4j.core.util.WatchEventService"
uses "org.apache.logging.log4j.core.util.ContextDataProvider"
}
}
I manage to get it to working by each class generating a uses Exception, until no more exceptions are thrown. I wonder if the "merged.module" is merging module dependencies correctly.
This is the correct solution. Not all uses can be automatically detected and some have to be manually added. Maybe there's a way to improve the detection, but I'm not sure how.
above is my gradle dependency configuration and module-info.java file configuration,There is no problem when I directly use the jar to start, but as long as the package generated by jlink is run, the following error will be prompted
Exception in thread "JavaFX Application Thread" java.util.ServiceConfigurationError: cn.hutool.core.convert.Converter: module com.zlg.merged.module does not declare uses
Am I missing any configuration or there is a problem with jlink packaging and using modules, I hope friends who know can answer, thank you @aalmiray @larsroe @siordache @xp-vit @DJViking