mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
105 stars 76 forks source link

JDK11, Unable to load source code of com.sun.tools.xjc.runtime.ZeroOneBooleanAdapter as a resource #152

Open vercevales opened 4 years ago

vercevales commented 4 years ago

Hi!

Having multiple XSD for SAML (official and standard XSDs) and trying to use them to generate classes I got an error: Exception in thread "main" java.lang.InternalError: Unable to load source code of com.sun.tools.xjc.runtime.ZeroOneBooleanAdapter as a resource.

Digging deeper into the issue I have discovered that the missing resources were removed from jaxb-xjc 2.3.2 (which is used in jaxb2-maven-plugin 2.5.0) whereas in jaxb-xjc 2.2.11 (which is used in jaxb2-maven-plugin 2.3.1) they are present.


POM's build section: `

org.springframework.boot spring-boot-maven-plugin org.codehaus.mojo jaxb2-maven-plugin 2.5.0 xjc xjc ${project.basedir}/src/main/resources/ org.apache.maven.plugins maven-compiler-plugin 11 11
</build>`

mvn clean compile output (the classes are generated, but file ZeroOneBooleanAdapter.java is empty): [INFO] ------------------------------------------------------------------------ Exception in thread "main" java.lang.InternalError: Unable to load source code of com.sun.tools.xjc.runtime.ZeroOneBooleanAdapter as a resource at com.sun.codemodel.fmt.JStaticJavaFile$ResourceLoader.getResourceAsStream(JStaticJavaFile.java:234) at com.sun.codemodel.fmt.JStaticJavaFile.build(JStaticJavaFile.java:84) at com.sun.codemodel.JPackage.build(JPackage.java:446) at com.sun.codemodel.JCodeModel.build(JCodeModel.java:327) at com.sun.codemodel.JCodeModel.build(JCodeModel.java:317) at com.sun.tools.xjc.Driver.run(Driver.java:384) at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution(AbstractJavaGeneratorMojo.java:475) at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute(AbstractJaxbMojo.java:337) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) 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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) at org.codehaus.classworlds.Launcher.main(Launcher.java:47)


when I downgrade the plugin to version `org.codehaus.mojo

jaxb2-maven-plugin 2.3.1` I get another error (and nothing is genrated in target directory): `[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project adap-microservice-authentication-webapp: Execution xjc of goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc failed: A required class was missing while executing org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc: com/sun/codemodel/CodeWriter [ERROR] ----------------------------------------------------- [ERROR] realm = plugin>org.codehaus.mojo:jaxb2-maven-plugin:2.3.1 [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy [ERROR] urls[0] = file:/home/pi26808/.m2/repository/org/codehaus/mojo/jaxb2-maven-plugin/2.3.1/jaxb2-maven-plugin-2.3.1.jar [ERROR] urls[1] = file:/home/pi26808/.m2/repository/javax/xml/bind/jaxb-api/2.2.11/jaxb-api-2.2.11.jar [ERROR] urls[2] = file:/home/pi26808/.m2/repository/org/glassfish/jaxb/jaxb-core/2.2.11/jaxb-core-2.2.11.jar [ERROR] urls[3] = file:/home/pi26808/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.2.11/jaxb-runtime-2.2.11.jar [ERROR] urls[4] = file:/home/pi26808/.m2/repository/org/glassfish/jaxb/jaxb-xjc/2.2.11/jaxb-xjc-2.2.11.jar [ERROR] urls[5] = file:/home/pi26808/.m2/repository/org/glassfish/jaxb/jaxb-jxc/2.2.11/jaxb-jxc-2.2.11.jar [ERROR] urls[6] = file:/home/pi26808/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M3/qdox-2.0-M3.jar [ERROR] urls[7] = file:/home/pi26808/.m2/repository/org/sonatype/sisu/sisu-inject-bean/2.3.0/sisu-inject-bean-2.3.0.jar [ERROR] urls[8] = file:/home/pi26808/.m2/repository/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar [ERROR] urls[9] = file:/home/pi26808/.m2/repository/org/sonatype/sisu/sisu-guava/0.9.9/sisu-guava-0.9.9.jar [ERROR] urls[10] = file:/home/pi26808/.m2/repository/org/sonatype/aether/aether-util/1.13.1/aether-util-1.13.1.jar [ERROR] urls[11] = file:/home/pi26808/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar [ERROR] urls[12] = file:/home/pi26808/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar [ERROR] urls[13] = file:/home/pi26808/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar [ERROR] urls[14] = file:/home/pi26808/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar [ERROR] urls[15] = file:/home/pi26808/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.5/plexus-compiler-api-2.5.jar [ERROR] urls[16] = file:/home/pi26808/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar [ERROR] urls[17] = file:/home/pi26808/.m2/repository/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar [ERROR] Number of foreign imports: 1 [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]] [ERROR] [ERROR] -----------------------------------------------------: com.sun.codemodel.CodeWriter [ERROR] -> [Help 1]`
eriknellessen commented 4 years ago

I have the same problem. I can reproduce both errors (with jaxb2-maven-plugin 2.5.0 and 2.3.1). Are there any known workarounds for this problem yet?

eriknellessen commented 4 years ago

As @vercevales already wrote, the problem is that jaxb-xjc 2.3.2 does not include the missing resources. It seems like this problem has already been fixed in jaxb-xjc in the following commit: https://github.com/eclipse-ee4j/jaxb-ri/commit/0042068395f720bbe368762832e33ede1141f67a

When using jaxb-xjc 2.3.3-b01 (the next version following 2.3.2), I ran into other problems. So I cloned jaxb-xjc, checked out the tag 2.3.2 and cherry-picked commit 0042068395f720bbe368762832e33ede1141f67a. I then installed jaxb-xjc and rebuilt my project. The problem with the missing ZeroOneBooleanAdapter file was gone.

eriknellessen commented 4 years ago

The corresponding issue in the jaxb-ri project is the following: https://github.com/eclipse-ee4j/jaxb-ri/issues/1287