0

我有一个用 Java 11 编写的小型 Quarkus webapp。它使用 hibernate-orm 扩展连接到 Postgres DB 并执行基本的 CRUD 操作。应用程序在 JVM 上运行良好,但容器中的本机映像构建器失败。我试过同时使用默认的builder-imagequay.io/quarkus/ubi-quarkus-native-image:20.1.0-java11心轴,但错误总是一样的:

mvn clean package -DskipTests -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel:20.1-java11
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< org.example:my-project-x >------------------------
[INFO] Building my-project-x 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ my-project-x ---
[INFO] Deleting /home/user-x/IdeaProjects/project-xyz/target
[INFO] 
[INFO] --- quarkus-maven-plugin:1.7.1.Final:prepare (default) @ my-project-x ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ my-project-x ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ my-project-x ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 28 source files to /home/user-x/IdeaProjects/project-xyz/target/classes
[INFO] 
[INFO] --- quarkus-maven-plugin:1.7.1.Final:prepare-tests (default) @ my-project-x ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ my-project-x ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/user-x/IdeaProjects/project-xyz/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ my-project-x ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/user-x/IdeaProjects/project-xyz/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ my-project-x ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ my-project-x ---
[INFO] Building jar: /home/user-x/IdeaProjects/project-xyz/target/my-project-x-1.0.0-SNAPSHOT.jar
[INFO] 
[INFO] --- quarkus-maven-plugin:1.7.1.Final:build (default) @ my-project-x ---
[INFO] [org.jboss.threads] JBoss Threads version 3.1.1.Final
[INFO] [org.hibernate.Version] HHH000412: Hibernate ORM core version 5.4.19.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /home/user-x/IdeaProjects/project-xyz/target/my-project-x-1.0.0-SNAPSHOT-native-image-source-jar/my-project-x-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /home/user-x/IdeaProjects/project-xyz/target/my-project-x-1.0.0-SNAPSHOT-native-image-source-jar/my-project-x-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Checking image status quay.io/quarkus/ubi-quarkus-mandrel:20.1-java11
20.1-java11: Pulling from quarkus/ubi-quarkus-mandrel
57de4da701b5: Already exists 
cf0f3ebe9f53: Already exists 
cb972249a74f: Pull complete 
Digest: sha256:bc5a542165aef56c2974e9478c4a53ed5445884be0cf2044a215618cfdc8f004
Status: Downloaded newer image for quay.io/quarkus/ubi-quarkus-mandrel:20.1-java11
quay.io/quarkus/ubi-quarkus-mandrel:20.1-java11
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 20.1.0.1.Final 287bbb343e (Mandrel Distribution) (Java Version 11.0.8)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] docker run -v /home/user-x/IdeaProjects/project-xyz/target/my-project-x-1.0.0-SNAPSHOT-native-image-source-jar:/project:z --env LANG=C --user 1001:1001 --rm quay.io/quarkus/ubi-quarkus-mandrel:20.1-java11 -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-DCoordinatorEnvironmentBean.transactionStatusManagerEnable=false -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=1 -J-Duser.language=en -J-Dfile.encoding=UTF-8 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -jar my-project-x-1.0.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:-UseServiceLoaderFeature -H:+StackTrace my-project-x-1.0.0-SNAPSHOT-runner
[my-project-x-1.0.0-SNAPSHOT-runner:54]    classlist:   9,079.72 ms,  1.68 GB
[my-project-x-1.0.0-SNAPSHOT-runner:54]        (cap):     645.81 ms,  1.68 GB
[my-project-x-1.0.0-SNAPSHOT-runner:54]        setup:   1,980.99 ms,  1.68 GB
21:55:42,006 INFO  [org.hib.val.int.uti.Version] HV000001: Hibernate Validator 6.1.5.Final
21:55:42,139 INFO  [org.hib.Version] HHH000412: Hibernate ORM core version 5.4.19.Final
21:55:42,143 INFO  [org.hib.ann.com.Version] HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
21:55:42,168 INFO  [org.hib.dia.Dialect] HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
21:55:42,214 INFO  [org.hib.orm.beans] HHH10005002: No explicit CDI BeanManager reference was passed to Hibernate, but CDI is available on the Hibernate ClassLoader.
21:56:01,321 INFO  [org.jbo.threads] JBoss Threads version 3.1.1.Final
[my-project-x-1.0.0-SNAPSHOT-runner:54]     analysis:  39,734.17 ms,  5.07 GB
2 fatal errors detected:
Fatal error:com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing com.oracle.svm.reflect.Class_getNestHost_d0409f1154f6242e625526eadd05fbcd60e7d7e9.invoke(java.lang.Object, java.lang.Object[]) 
Parsing context:
    parsing java.base@11.0.8/java.lang.reflect.Method.invoke(Method.java:566)
    parsing javax.enterprise.util.AnnotationLiteral.invoke(AnnotationLiteral.java:288)
    parsing javax.enterprise.util.AnnotationLiteral.getMemberValue(AnnotationLiteral.java:276)
    parsing javax.enterprise.util.AnnotationLiteral.hashCode(AnnotationLiteral.java:246)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.getHashIndex(EconomicMapImpl.java:414)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.findHash(EconomicMapImpl.java:285)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.find(EconomicMapImpl.java:254)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.put(EconomicMapImpl.java:426)
    parsing platform/jdk.internal.vm.compiler/org.graalvm.compiler.options.ModifiableOptionValues.update(ModifiableOptionValues.java:103)
    parsing app//com.oracle.svm.core.option.RuntimeOptionParser.parse(RuntimeOptionParser.java:174)
    parsing app//com.oracle.svm.core.option.RuntimeOptionParser.parseAndConsumeAllOptions(RuntimeOptionParser.java:77)
    parsing app//com.oracle.svm.jni.functions.JNIInvocationInterface$Exports.JNI_CreateJavaVM(JNIInvocationInterface.java:151)
    parsing com.oracle.svm.core.code.IsolateEnterStub.JNIInvocationInterface$Exports_JNI_CreateJavaVM_8df18e9ea6eb1ed7b1c899a0bbc578da0e2cc0ad(generated:0)

    at com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:138)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:340)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:311)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:112)
    at com.oracle.graal.pointsto.DefaultAnalysisPolicy$DefaultVirtualInvokeTypeFlow.onObservedUpdate(DefaultAnalysisPolicy.java:228)
    at com.oracle.graal.pointsto.flow.TypeFlow.notifyObservers(TypeFlow.java:470)
    at com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:542)
    at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:530)
    at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:173)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.getNestHost() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
    at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.lookup(AnnotationSubstitutionProcessor.java:183)
    at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128)
    at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:397)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:377)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:75)
    at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaMethod(UniverseMetaAccess.java:93)
    at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:66)
    at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:39)
    at com.oracle.svm.reflect.hosted.ReflectionSubstitutionType$ReflectiveInvokeMethod.buildGraph(ReflectionSubstitutionType.java:511)
    at com.oracle.graal.pointsto.meta.AnalysisMethod.buildGraph(AnalysisMethod.java:333)
    at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:189)
    at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:352)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:322)
    ... 13 more
Fatal error:com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing com.oracle.svm.reflect.Class_getNestHost_d0409f1154f6242e625526eadd05fbcd60e7d7e9.invoke(java.lang.Object, java.lang.Object[]) 
Parsing context:
    parsing java.base@11.0.8/java.lang.reflect.Method.invoke(Method.java:566)
    parsing javax.enterprise.util.AnnotationLiteral.invoke(AnnotationLiteral.java:288)
    parsing javax.enterprise.util.AnnotationLiteral.getMemberValue(AnnotationLiteral.java:276)
    parsing javax.enterprise.util.AnnotationLiteral.hashCode(AnnotationLiteral.java:246)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.getHashIndex(EconomicMapImpl.java:414)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.findHash(EconomicMapImpl.java:285)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.find(EconomicMapImpl.java:254)
    parsing app/org.graalvm.sdk/org.graalvm.collections.EconomicMapImpl.put(EconomicMapImpl.java:426)
    parsing platform/jdk.internal.vm.compiler/org.graalvm.compiler.options.ModifiableOptionValues.update(ModifiableOptionValues.java:103)
    parsing app//com.oracle.svm.core.option.RuntimeOptionParser.parse(RuntimeOptionParser.java:174)
    parsing app//com.oracle.svm.core.option.RuntimeOptionParser.parseAndConsumeAllOptions(RuntimeOptionParser.java:77)
    parsing app//com.oracle.svm.jni.functions.JNIInvocationInterface$Exports.JNI_CreateJavaVM(JNIInvocationInterface.java:151)
    parsing com.oracle.svm.core.code.IsolateEnterStub.JNIInvocationInterface$Exports_JNI_CreateJavaVM_8df18e9ea6eb1ed7b1c899a0bbc578da0e2cc0ad(generated:0)

    at com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:138)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:340)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:311)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:112)
    at com.oracle.graal.pointsto.DefaultAnalysisPolicy$DefaultVirtualInvokeTypeFlow.onObservedUpdate(DefaultAnalysisPolicy.java:228)
    at com.oracle.graal.pointsto.flow.TypeFlow.notifyObservers(TypeFlow.java:470)
    at com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:542)
    at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:530)
    at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:173)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.getNestHost() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
    at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.lookup(AnnotationSubstitutionProcessor.java:183)
    at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128)
    at com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor$ChainedSubstitutionProcessor.lookup(SubstitutionProcessor.java:128)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:397)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:377)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:75)
    at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaMethod(UniverseMetaAccess.java:93)
    at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:66)
    at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaMethod(AnalysisMetaAccess.java:39)
    at com.oracle.svm.reflect.hosted.ReflectionSubstitutionType$ReflectiveInvokeMethod.buildGraph(ReflectionSubstitutionType.java:511)
    at com.oracle.graal.pointsto.meta.AnalysisMethod.buildGraph(AnalysisMethod.java:333)
    at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:189)
    at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:352)
    at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:322)
    ... 13 more
Error: Image build request failed with exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ----------------------------

后来我决定直接用 GraalVM 编译。我下载graalvm-ce-java11-20.2.0了,安装了 native-image 扩展,相应地设置了 JAVA_HOME,它编译时没有任何抱怨,并且本机可执行文件运行良好。我仍然想在 docker 容器中编译而无需安装 GraalVM。

环境:

Quarkus 1.7.1.Final

$ echo $JAVA_HOME
/opt/jdk-14/

$ java -version
openjdk version "14" 2020-03-17
OpenJDK Runtime Environment (build 14+36-1461)
OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

pom.xml:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

更新:我刚刚docker run自己运行了命令并添加了-H:+ReportUnsupportedElementsAtRuntime,这次错误信息不那么模糊了:

Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/PolicyContextException
4

1 回答 1

1

尝试在容器中构建时,您是否使用 Java 11 编译您的应用程序?

因为它看起来很像我们在使用 JDK 8 编译然后使用 GraalVM/Mandrel Java 11 容器构建应用程序时遇到的问题。

于 2020-09-03T15:34:32.790 回答