在本机编译期间,如何在 Quarkus maven 插件中将参数添加到 GraalVM?
Posted
技术标签:
【中文标题】在本机编译期间,如何在 Quarkus maven 插件中将参数添加到 GraalVM?【英文标题】:How in Quarkus maven plugin can I add param to GraalVM during Native compilation? 【发布时间】:2019-09-15 18:41:39 【问题描述】:当我为我的应用程序构建本机映像时,我遇到了一些我不明白的错误。
Error: unsupported features in 3 methods
Detailed message:
Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.getConstantPool() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
Graal 建议我设置此选项 --report-unsupported-elements-at-runtime
我看了NativeImageMojo的代码
我想写一些类似的东西:
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>$quarkus.version</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
<containerRuntimeOptions>--report-unsupported-elements-at-runtime</containerRuntimeOptions>
</configuration>
</execution>
</executions>
</plugin>
但是选项没有出现:
[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] /sandbox/Resources/GraalVm/graalvm-ce-1.0.0-rc15/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar portfolio-app-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+PrintAnalysisCallTree -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:NativeLinkerOption=-no-pie -H:-SpawnIsolates -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace
如何添加 --report-unsupported-elements-at-runtime ? (我使用 Quarkus-bom 0.14.0 和 graalvm-ce-1.0.0-rc15)
【问题讨论】:
【参考方案1】:你的两个命题运作良好,但不完全一样。 选项 -H:+ReportUnsupportedElementsAtRuntime 返回:
Fatal error: java.lang.NoClassDefFoundError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:459)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:288)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:422)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:108)
Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/EJBMethodPermission
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:865)
at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:820)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:522)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:442)
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: javax.security.jacc.EJBMethodPermission
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more
Error: Image build request failed with exit status 1
选项 --report-unsupported-elements-at-runtime return :
Fatal error: java.lang.NoClassDefFoundError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005)
at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:459)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:288)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:422)
at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:108)
Caused by: java.lang.NoClassDefFoundError: javax/security/jacc/PolicyContextException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleDeletedClass(AnnotationSubstitutionProcessor.java:437)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.handleClass(AnnotationSubstitutionProcessor.java:270)
at com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor.init(AnnotationSubstitutionProcessor.java:230)
at com.oracle.svm.hosted.NativeImageGenerator.createDeclarativeSubstitutionProcessor(NativeImageGenerator.java:865)
at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:820)
at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:522)
at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:442)
at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.lang.ClassNotFoundException: javax.security.jacc.PolicyContextException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 15 more
Error: Image build request failed with exit status 1
我找到了一些documentation
--report-unsupported-elements-at-runtime 在第一次访问时报告运行时不支持的方法和字段的使用情况,而不是在构建映像期间报告错误。
我在website 中找到了有关 -H:+ReportUnsupportedElementsAtRuntime 的信息
在运行时报告不受支持的方法和字段的使用情况 第一次访问,而不是在图像期间作为错误 建筑
描述完全一样,但我不明白为什么返回不同。
【讨论】:
为了完整起见:我得到完全相同的缺失javax.security.jacc
类,解决方案是添加以下依赖项:<dependency> <groupId>org.jboss.spec.javax.security.jacc</groupId> <artifactId>jboss-jacc-api_1.5_spec</artifactId> <!-- managed in io.quarkus:quarkus-bom --> </dependency>
thx @PeterPalaga 这也解决了我的问题。但是在我的情况下,我遇到了下一个 java.lang.NoClassDefFoundError,这次是 com/sun/jna/LastErrorException。可以通过添加 在这种情况下,最好的方法是使用:
<reportErrorsAtRuntime>true</reportErrorsAtRuntime>
在您的原生图像目标的配置中。
【讨论】:
它工作得很好,这个参数添加了 -H:+ReportUnsupportedElementsAtRuntime 参数。谢谢纪尧姆 @bmeynier 如果它对您有用,请您接受这个答案,以便将来的读者无需阅读 cmets 即可轻松知道它是正确的吗?谢谢!【参考方案3】:可以使用additionalBuildArgs
参数:
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>$quarkus.version</version>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableHttpUrlHandler>true</enableHttpUrlHandler>
<additionalBuildArgs>--report-unsupported-elements-at-runtime</additionalBuildArgs>
</configuration>
</execution>
</executions>
</plugin>
【讨论】:
它也很好用,它向 GraalVm 添加了 --report-unsupported-elements-at-runtime 参数。谢谢奥列格以上是关于在本机编译期间,如何在 Quarkus maven 插件中将参数添加到 GraalVM?的主要内容,如果未能解决你的问题,请参考以下文章
Quarkus Mongodb 在本机构建中更改流 NullPointerException
如何在 google cloudbuild 上构建 quarkus 原生镜像
在 ubuntu 上安装 npm 期间,使用 c++ 17 编译本机节点插件失败
应"云"而生的 Java 框架 Quarkus:构建本机可执行文件