Open boncey opened 3 years ago
I can replicate this by checking out this project and running ApplicationValidatorTest
under Java 11.
Failed to call configuration validation method
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.common.base.Throwables.propagate(Throwables.java:160)
at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:71)
at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:48)
at com.jamierf.dropwizard.debpkg.validation.ApplicationValidatorTest.testValidConfiguration(ApplicationValidatorTest.java:50)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:59)
... 27 more
Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource
at io.dropwizard.hibernate.HibernateBundle.<init>(HibernateBundle.java:20)
at com.example.helloworld.HelloWorldApplication$1.<init>(HelloWorldApplication.java:26)
at com.example.helloworld.HelloWorldApplication.<init>(HelloWorldApplication.java:25)
at com.example.helloworld.HelloWorldApplication.main(HelloWorldApplication.java:22)
... 32 more
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 36 more
This change fixes the problem.
--- a/src/main/java/com/jamierf/dropwizard/debpkg/validation/ApplicationValidator.java
+++ b/src/main/java/com/jamierf/dropwizard/debpkg/validation/ApplicationValidator.java
@@ -26,7 +26,7 @@ public class ApplicationValidator {
this.log = log;
// Set parent to null to avoid pulling in SLF4J and other conflicts from our self
- classLoader = new URLClassLoader(new URL[]{artifactFile.toURI().toURL()}, null);
+ classLoader = new URLClassLoader(new URL[]{artifactFile.toURI().toURL()}, ClassLoader.getPlatformClassLoader());
}
private Class<?> getMainClass() throws IOException, ClassNotFoundException {
There was a change in Java 11 to the ClassLoader.
In Java 11, the boot class loader only loads core modules. If you create a class loader with a null parent, it may not find all platform classes. In Java 11, you need to pass ClassLoader.getPlatformClassLoader() instead of null as the parent class loader in such cases.
However, that change requires at least Java version 9 so it will no longer work with Java 8. Also, the HelloWorld application used in the tests will need updating to Java 11 too.
-Also, I was unable to get the code to build locally so I can't even roll my own fork.-
Got it built locally by upgrading maven-plugin-plugin
to 3.6.0
. 👍
Update:
I've pushed my various hacks and fixes to https://github.com/boncey/dropwizard-debpkg-maven-plugin/tree/java-11-changes. I won't raise a PR as I think it will need some cleanup work and it will also most like break Java 8 compatibility.
I switched to OpenJDK 11 and it now fails with an error.
The relevant part from the stack trace seems to be:
The important part from above seems to be:
It looks like it's related to the jars that are no longer part of the OpenJDK.
If I run the DW
check
command against my app's jar it works fine.Thanks, Darren.