Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory when using jaxb for native image #5558

Closed
chriskn opened this issue Nov 18, 2019 · 6 comments · Fixed by #5568
Closed
Assignees
Labels
area/jaxb kind/bug Something isn't working
Milestone

Comments

@chriskn
Copy link

chriskn commented Nov 18, 2019

Describe the bug
I try to desirialize xml content based on quarkus-jaxb and a set of classes generated from schema. When I run my service in jvm mode everything work as expected. When I run it in native mode the ContextCactory can't be found. The issue persists even when I set javax.xml.bind.context.factory property. Stack trace:

10:27:00 INFO  [io.quarkus] (main) Profile prod activated.
10:27:00 INFO  [io.quarkus] (main) Installed features: [cdi, kubernetes, resteasy, resteasy-jackson]
10:27:04 DEBUG [or.jb.re.re.i18n] (vert.x-worker-thread-0) RESTEASY002315: PathInfo: /facilities
10:27:04 DEBUG [de.co.pa.ParkingFacilityResource] (vert.x-worker-thread-0) delivering static facilities
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0) Trying to locate eu/datex2/schema/_2/_2_0/jaxb.properties
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0)   not found
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0) Trying to locate eu/datex2/schema/_2/_2_0/jaxb.properties
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0)   not found
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0) Checking system property javax.xml.bind.context.factory
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0)   found com.sun.xml.bind.v2.ContextFactory
10:27:04 FINE  [ja.xm.bind] (vert.x-worker-thread-0) Trying to load com.sun.xml.bind.v2.ContextFactory
10:27:04 ERROR [io.qu.ve.ht.ru.QuarkusErrorHandler] (vert.x-worker-thread-0) HTTP Request to /facilities failed, error id: 27120855-2cda-43fd-8eb9-e6eae6ad9da5-1: org.jboss.resteasy.spi.UnhandledException: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:106)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:372)
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:209)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:252)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:153)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:363)
        at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:156)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:238)
        at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:109)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatchRequestContext(VertxRequestHandler.java:84)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.lambda$handle$0(VertxRequestHandler.java:71)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)

I work on windows and build the native image inside the docker container using the following commands:

./mvnw clean package -Pnative -DskipTests "-Dquarkus.native.container-build=true"
docker build -f src/main/docker/Dockerfile.native  .

To Reproduce

  1. Run the docker container provided here: https://hub.docker.com/repository/docker/incck/static-provider for example with docker run -i --rm -p 8080:8080 incck/static-provider
  2. Open the url http://localhost:8080/facilities

Environment (please complete the following information):

  • Output of uname -a or ver: Windows 10
  • Output of java -version: java version "1.8.0_231"
    Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
  • GraalVM version (if different from Java): Same as java version
  • Quarkus version or git rev: 1.0.0.CR1

Additional context
Maven dependencies:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------< de.codecentric.parking:data.provider.static >-------------
[INFO] Building data.provider.static 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ data.provider.static ---
[INFO] de.codecentric.parking:data.provider.static:jar:1.0.0-SNAPSHOT
[INFO] +- io.quarkus:quarkus-resteasy:jar:1.0.0.CR1:compile
[INFO] |  +- io.quarkus:quarkus-vertx-http:jar:1.0.0.CR1:compile
[INFO] |  |  +- io.quarkus.security:quarkus-security:jar:1.0.0.Beta1:compile
[INFO] |  |  +- jakarta.enterprise:jakarta.enterprise.cdi-api:jar:2.0.2:compile
[INFO] |  |  |  +- jakarta.el:jakarta.el-api:jar:3.0.3:compile
[INFO] |  |  |  \- jakarta.interceptor:jakarta.interceptor-api:jar:1.2.5:compile
[INFO] |  |  |     \- jakarta.ejb:jakarta.ejb-api:jar:3.2.6:compile
[INFO] |  |  |        \- jakarta.transaction:jakarta.transaction-api:jar:1.3.3:compile
[INFO] |  |  +- io.quarkus:quarkus-vertx-core:jar:1.0.0.CR1:compile
[INFO] |  |  |  +- io.quarkus:quarkus-netty:jar:1.0.0.CR1:compile
[INFO] |  |  |  |  +- io.netty:netty-codec:jar:4.1.42.Final:compile
[INFO] |  |  |  |  \- io.netty:netty-handler:jar:4.1.42.Final:compile
[INFO] |  |  |  \- io.vertx:vertx-core:jar:3.8.3:compile
[INFO] |  |  |     +- io.netty:netty-common:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-buffer:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-transport:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-handler-proxy:jar:4.1.42.Final:compile
[INFO] |  |  |     |  \- io.netty:netty-codec-socks:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-codec-http:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-codec-http2:jar:4.1.42.Final:compile
[INFO] |  |  |     +- io.netty:netty-resolver:jar:4.1.42.Final:compile
[INFO] |  |  |     \- io.netty:netty-resolver-dns:jar:4.1.42.Final:compile
[INFO] |  |  |        \- io.netty:netty-codec-dns:jar:4.1.42.Final:compile
[INFO] |  |  \- io.vertx:vertx-web:jar:3.8.3-01:compile
[INFO] |  |     +- io.vertx:vertx-web-common:jar:3.8.3-01:compile
[INFO] |  |     +- io.vertx:vertx-auth-common:jar:3.8.3:compile
[INFO] |  |     \- io.vertx:vertx-bridge-common:jar:3.8.3:compile
[INFO] |  \- io.quarkus:quarkus-resteasy-server-common:jar:1.0.0.CR1:compile
[INFO] |     +- io.quarkus:quarkus-arc:jar:1.0.0.CR1:compile
[INFO] |     |  +- io.quarkus.arc:arc:jar:1.0.0.CR1:compile
[INFO] |     |  \- org.eclipse.microprofile.context-propagation:microprofile-context-propagation-api:jar:1.0.1:compile
[INFO] |     +- io.quarkus:quarkus-resteasy-common:jar:1.0.0.CR1:compile
[INFO] |     |  \- org.jboss.resteasy:resteasy-core:jar:4.4.0.Final:compile
[INFO] |     |     +- org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_2.1_spec:jar:2.0.1.Final:compile
[INFO] |     |     +- org.jboss.resteasy:resteasy-core-spi:jar:4.4.0.Final:compile
[INFO] |     |     \- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] |     \- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] +- io.quarkus:quarkus-junit5:jar:1.0.0.CR1:test
[INFO] |  +- io.quarkus:quarkus-bootstrap-core:jar:1.0.0.CR1:test
[INFO] |  |  +- com.google.guava:guava:jar:27.0.1-jre:compile
[INFO] |  |  |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  |  |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  |  |  +- org.checkerframework:checker-qual:jar:2.5.2:compile
[INFO] |  |  |  +- com.google.errorprone:error_prone_annotations:jar:2.2.0:compile
[INFO] |  |  |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  |  |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.17:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.9:test
[INFO] |  |  +- org.apache.maven:maven-embedder:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-settings:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-core:jar:3.5.4:test
[INFO] |  |  |  |  \- org.apache.maven:maven-artifact:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-plugin-api:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-model:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-model-builder:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-builder-support:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven.resolver:maven-resolver-api:jar:1.1.1:test
[INFO] |  |  |  +- org.apache.maven.resolver:maven-resolver-util:jar:1.1.1:test
[INFO] |  |  |  +- org.apache.maven.shared:maven-shared-utils:jar:3.2.1:test
[INFO] |  |  |  |  \- commons-io:commons-io:jar:2.6:test
[INFO] |  |  |  +- com.google.inject:guice:jar:no_aop:4.2.0:test
[INFO] |  |  |  |  \- aopalliance:aopalliance:jar:1.0:test
[INFO] |  |  |  +- org.codehaus.plexus:plexus-utils:jar:3.0.24:test
[INFO] |  |  |  +- org.codehaus.plexus:plexus-classworlds:jar:2.5.2:test
[INFO] |  |  |  +- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.3:test
[INFO] |  |  |  +- org.codehaus.plexus:plexus-component-annotations:jar:1.7.1:test
[INFO] |  |  |  \- commons-cli:commons-cli:jar:1.4:test
[INFO] |  |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] |  |  +- jakarta.inject:jakarta.inject-api:jar:1.0:compile
[INFO] |  |  +- org.apache.maven:maven-settings-builder:jar:3.5.4:test
[INFO] |  |  |  +- org.codehaus.plexus:plexus-interpolation:jar:1.24:test
[INFO] |  |  |  \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.4:test
[INFO] |  |  |     \- org.sonatype.plexus:plexus-cipher:jar:1.4:test
[INFO] |  |  +- org.apache.maven:maven-resolver-provider:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven:maven-repository-metadata:jar:3.5.4:test
[INFO] |  |  |  +- org.apache.maven.resolver:maven-resolver-spi:jar:1.1.1:test
[INFO] |  |  |  \- org.apache.maven.resolver:maven-resolver-impl:jar:1.1.1:test
[INFO] |  |  +- org.apache.maven.resolver:maven-resolver-connector-basic:jar:1.1.1:test
[INFO] |  |  +- org.apache.maven.resolver:maven-resolver-transport-wagon:jar:1.1.1:test
[INFO] |  |  |  \- org.apache.maven.wagon:wagon-provider-api:jar:3.0.0:test
[INFO] |  |  +- org.apache.maven.wagon:wagon-http:jar:3.0.0:test
[INFO] |  |  |  \- org.apache.maven.wagon:wagon-http-shared:jar:3.0.0:test
[INFO] |  |  |     \- org.jsoup:jsoup:jar:1.7.2:test
[INFO] |  |  +- org.apache.maven.wagon:wagon-file:jar:3.0.0:test
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- org.jboss.logging:commons-logging-jboss-logging:jar:1.0.0.Final:test
[INFO] |  +- io.quarkus:quarkus-test-common:jar:1.0.0.CR1:test
[INFO] |  |  +- io.quarkus:quarkus-core-deployment:jar:1.0.0.CR1:test
[INFO] |  |  |  +- io.quarkus.gizmo:gizmo:jar:1.0.0.Alpha8:test
[INFO] |  |  |  |  \- org.ow2.asm:asm-util:jar:7.1:test
[INFO] |  |  |  |     +- org.ow2.asm:asm-tree:jar:7.1:test
[INFO] |  |  |  |     \- org.ow2.asm:asm-analysis:jar:7.1:test
[INFO] |  |  |  +- org.ow2.asm:asm:jar:7.1:test
[INFO] |  |  |  \- io.quarkus:quarkus-builder:jar:1.0.0.CR1:test
[INFO] |  |  +- io.quarkus:quarkus-jsonp-deployment:jar:1.0.0.CR1:test
[INFO] |  |  |  \- io.quarkus:quarkus-jsonp:jar:1.0.0.CR1:test
[INFO] |  |  |     \- org.glassfish:jakarta.json:jar:1.1.6:test
[INFO] |  |  \- org.jboss:jandex:jar:2.1.1.Final:test
[INFO] |  +- org.junit.jupiter:junit-jupiter:jar:5.5.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-api:jar:5.5.2:test
[INFO] |  |  |  +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |  |  |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  |  |  \- org.junit.platform:junit-platform-commons:jar:1.5.2:test
[INFO] |  |  +- org.junit.jupiter:junit-jupiter-params:jar:5.5.2:test
[INFO] |  |  \- org.junit.jupiter:junit-jupiter-engine:jar:5.5.2:test
[INFO] |  |     \- org.junit.platform:junit-platform-engine:jar:1.5.2:test
[INFO] |  \- io.quarkus:quarkus-core:jar:1.0.0.CR1:compile
[INFO] |     +- io.smallrye:smallrye-config:jar:1.3.9:compile
[INFO] |     |  \- org.eclipse.microprofile.config:microprofile-config-api:jar:1.3:compile
[INFO] |     +- org.jboss.logmanager:jboss-logmanager-embedded:jar:1.0.3:compile
[INFO] |     +- org.jboss.logging:jboss-logging-annotations:jar:2.1.0.Final:compile
[INFO] |     +- org.jboss.threads:jboss-threads:jar:3.0.0.Final:compile
[INFO] |     +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |     +- org.jboss.slf4j:slf4j-jboss-logging:jar:1.2.0.Final:compile
[INFO] |     +- org.graalvm.sdk:graal-sdk:jar:19.2.1:compile
[INFO] |     \- org.wildfly.common:wildfly-common:jar:1.5.0.Final-format-001:compile
[INFO] +- io.rest-assured:rest-assured:jar:4.1.1:test
[INFO] |  +- org.codehaus.groovy:groovy:jar:2.5.6:test
[INFO] |  +- org.codehaus.groovy:groovy-xml:jar:2.5.6:test
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.9:test
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.4.11:test
[INFO] |  |  \- commons-codec:commons-codec:jar:1.13:test
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.5.3:test
[INFO] |  +- org.hamcrest:hamcrest:jar:2.1:test
[INFO] |  +- org.ccil.cowan.tagsoup:tagsoup:jar:1.2.1:test
[INFO] |  +- io.rest-assured:json-path:jar:4.1.1:test
[INFO] |  |  +- org.codehaus.groovy:groovy-json:jar:2.5.6:test
[INFO] |  |  \- io.rest-assured:rest-assured-common:jar:4.1.1:test
[INFO] |  \- io.rest-assured:xml-path:jar:4.1.1:test
[INFO] |     +- javax.xml.bind:jaxb-api:jar:2.3.1:test
[INFO] |     \- org.apache.sling:org.apache.sling.javax.activation:jar:0.1.0:test
[INFO] +- org.projectlombok:lombok:jar:1.18.10:provided
[INFO] +- io.quarkus:quarkus-resteasy-jackson:jar:1.0.0.CR1:compile
[INFO] |  +- io.quarkus:quarkus-jackson:jar:1.0.0.CR1:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.10.1:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.10:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.10:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.10:compile
[INFO] |  +- org.jboss.resteasy:resteasy-jackson2-provider:jar:4.4.0.Final:compile
[INFO] |  |  +- org.jboss.resteasy:resteasy-jaxb-provider:jar:4.4.0.Final:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.9.10:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.10:compile
[INFO] |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.9.10:compile
[INFO] |  |  |  +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.9.10:compile
[INFO] |  |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.10:compile
[INFO] |  |  \- com.github.fge:json-patch:jar:1.9:compile
[INFO] |  |     \- com.github.fge:jackson-coreutils:jar:1.6:compile
[INFO] |  |        \- com.github.fge:msg-simple:jar:1.1:compile
[INFO] |  |           \- com.github.fge:btf:jar:1.2:compile
[INFO] |  \- org.jboss.spec.javax.xml.bind:jboss-jaxb-api_2.3_spec:jar:2.0.0.Final:compile
[INFO] +- io.quarkus:quarkus-kubernetes:jar:1.0.0.CR1:compile
[INFO] \- io.quarkus:quarkus-jaxb:jar:1.0.0.CR1:compile
[INFO]    \- org.glassfish.jaxb:jaxb-runtime:jar:2.3.3-b01:compile
[INFO]       +- org.glassfish.jaxb:txw2:jar:2.3.3-b01:compile
[INFO]       +- com.sun.istack:istack-commons-runtime:jar:3.0.10:compile
[INFO]       \- com.sun.activation:jakarta.activation:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.352 s
[INFO] Finished at: 2019-11-18T12:04:52+01:00
[INFO] ------------------------------------------------------------------------
@chriskn chriskn added the kind/bug Something isn't working label Nov 18, 2019
@gsmet
Copy link
Member

gsmet commented Nov 18, 2019

Any chance you could show me the sources of the reproducer?

What I'm wondering is if you are using annotations to declare your JAXB entities? Or if maybe the JAXB entities are in a separate module that is not included in the Jandex index?

@chriskn
Copy link
Author

chriskn commented Nov 18, 2019

You can find the code here https://github.com/chriskn/data.provider.static
I also included a build.sh so you can reproduce how I build the native image.
I am using annotations. See package eu.datex2...
I tried it also with the entities located in an external jar but no success

@gsmet gsmet self-assigned this Nov 18, 2019
@gsmet
Copy link
Member

gsmet commented Nov 18, 2019

I fixed the first issue, it was an easy one.

But I stumbled upon another one that is a bit harder to diagnose/fix. I'll let you know when I come up with something.

@gsmet
Copy link
Member

gsmet commented Nov 18, 2019

@chriskn #5568 should solve your issues and there were 3 different ones :).

Thanks for reporting it!

@gsmet
Copy link
Member

gsmet commented Nov 18, 2019

@chriskn btw, you should remove all the javax.xml.bind.context.factory properties from your code. Otherwise, it doesn't even work in JVM mode.

@chriskn
Copy link
Author

chriskn commented Nov 18, 2019

@gsmet thank you for the fast reply and fix! I will remove the properties. I just added them for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jaxb kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants