图像堆中不允许...的实例,因为此类应在图像运行时初始化

时间:2019-11-23 19:47:13

标签: quarkus graalvm-native-image

我正在运行一个简单的Java应用程序(只是一个REST端点,一个“ Hello”响应-正是Quarkus maven原型生成的示例,未经修改),并带有以下堆栈:

  • Quarkus(MicroProfile)
  • JDK 1.8热点1.8.0_231-b11
  • GraalVM 19.3.0(本机图像)
  • MacOS Catalina

第一个错误是(尽管似乎不是主要问题)

[code-with-quarkus-1.0.0-SNAPSHOT-runner:1868]        setup:   8,524.65 ms
java.lang.NoSuchMethodException: com.oracle.svm.core.jdk.LocalizationSupport.addBundleToCache(java.lang.String)
    at java.lang.Class.getDeclaredMethod(Class.java:2130)
    at io.quarkus.runner.AutoFeature.beforeAnalysis(AutoFeature.zig:744)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:669)
    at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:63)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:669)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:530)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:445)
    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)
20:17:42,508 INFO  [org.jbo.threads] JBoss Threads version 3.0.0.Final
[code-with-quarkus-1.0.0-SNAPSHOT-runner:1868]   (typeflow):  34,257.18 ms
[code-with-quarkus-1.0.0-SNAPSHOT-runner:1868]    (objects):  19,361.86 ms
[code-with-quarkus-1.0.0-SNAPSHOT-runner:1868]   (features):     866.06 ms
[code-with-quarkus-1.0.0-SNAPSHOT-runner:1868]     analysis:  56,364.44 ms

真正的问题(我认为)在这里:

Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of java.net.Inet4Address are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:
    at parsing org.wildfly.common.net.CidrAddress.<clinit>(CidrAddress.java:46)
Call path from entry point to org.wildfly.common.net.CidrAddress.<clinit>():
    no path found from entry point to target method

所以,我尝试做的第一件事是指示不要在Image BuildTime上初始化类org.wildfly.common.net.CidrAddress,而是在Image RunTime上使用以下配置进行初始化:

quarkus.native.additional-build-args=--initialize-at-run-time=org.wildfly.common.net.CidrAddress
quarkus.native.enable-jni=true 

但是,什么都没有改变。我还尝试激活(按照说明)参数-H:+ TraceClassInitialization,以找出正在初始化的类可能会导致问题。没有效果!此参数没有任何区别(无额外信息)。

其他人是否经历过这种情况?有什么提示,想法吗?

谢谢!

2 个答案:

答案 0 :(得分:3)

Quarals尚不支持GraalVM 19.3.0,它刚刚发布,需要进行一些更改。

特别是您遇到了这个问题:  -https://github.com/quarkusio/quarkus/pull/5353

我希望Quarkus 1.1支持GraalVM 19.3,但是我不确定。

答案 1 :(得分:0)

我的多阶段构建存在相同的问题:

首先,我修改了pom.xml:

          <build>
            <plugins>
                <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>
                                <enableHttpsUrlHandler>true</enableHttpsUrlHandler>
                                <enableJni>true</enableJni>
                                <additionalBuildArgs>--initialize-at-run-time=java.net.Inet6Address -H:+TraceClassInitialization</additionalBuildArgs>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

仍然是相同的错误...

然后,我将Dockerfile的基础映像从FROM quay.io/quarkus/centos-quarkus-maven:19.3.0-java8 AS构建更改为 FROM quay.io/quarkus /centos-quarkus-maven:19.2.1 AS构建,这是我完整的Dockerfile.multistage:

FROM quay.io/quarkus/centos-quarkus-maven:19.2.1 AS build
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app/pom.xml
USER root
RUN chown -R quarkus /usr/src/app
USER quarkus
RUN mvn -f /usr/src/app/pom.xml -Pnative clean package

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal
WORKDIR /work/
COPY --from=build /usr/src/app/target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]