当前位置: 首页 > 知识库问答 >
问题:

Quarkus本机映像生成使用AWS SDK失败

叶煌
2023-03-14

在使用amazon sdk的实现与amazon Rekognion和amazon Understand工具进行交互后,它在开发人员(mvn compile quarkus:dev)上运行得非常好,但在尝试进行REST Web服务的本机编译时崩溃,该服务是使用以下技术开发的;

GraalVM CE 22.0.0.2。

Quarkus框架(Quarkus bom.io.Quarkus.platform)2.8.0。最终的

O. S.:Windows 10 Enterprise LTSC。

马文:3.8.4。

AWSSDK:1.12.198。

POM文件

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.lum</groupId>
    <artifactId>casccb</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.release>11</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
        <quarkus.platform.version>2.8.0.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>aws-java-sdk-bom</artifactId>
                <version>1.12.198</version>
                <!-- <version>1.11.1000</version> -->
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>

        <!-- -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-arc</artifactId>
        </dependency>

        <!-- -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>

        <!-- -->
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Hibernate ORM Panache -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-hibernate-orm-panache</artifactId>
        </dependency>

        <!-- JDBC Driver -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-jdbc-h2</artifactId>
            <!-- <artifactId>quarkus-jdbc-oracle</artifactId> -->
        </dependency>

        <!-- IO Commons -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>

        <!-- AWS sdk core -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-core</artifactId>
        </dependency>
        
        <!-- AWS s3 client -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
        </dependency>

        <!-- AWS rekognition client -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-rekognition</artifactId>
        </dependency>
        
        <!-- AWS comprehend client-->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-comprehend</artifactId>
        </dependency>

        <!-- quarkus -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-apache-httpclient</artifactId>
        </dependency>

        <!-- OpenAPI -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-smallrye-openapi</artifactId>
        </dependency>

        <!-- JUnit 5 -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Mockito -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5-mockito</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus.platform.version}</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                            <goal>generate-code</goal>
                            <goal>generate-code-tests</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
                <configuration>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                                        <maven.home>${maven.home}</maven.home>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>

这是VS 2022推荐的x64 Native Tools命令提示符显示的输出。执行“mvn包-Plocal-DskipTest=true”

Error: Unsupported features in 2 methods
    Detailed message:
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy@2ab7cc8 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.equalJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy@2aa3a8a2 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.fullJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    
    com.oracle.svm.core.util.UserError$UserException: Unsupported features in 2 methods
    Detailed message:
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy@2ab7cc8 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.equalJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy@2aa3a8a2 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.fullJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    
            at com.oracle.svm.core.util.UserError.abort(UserError.java:87)
            at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:233)
            at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:759)
            at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:529)
            at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
            at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
            at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
            at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
            at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
    Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported features in 2 methods
    Detailed message:
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy@2ab7cc8 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.equalJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
    Trace: Object was reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy.random of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy@2aa3a8a2 reached by
            reading field com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy.fullJitterBackoffStrategy of
                    constant com.amazonaws.retry.PredefinedBackoffStrategies$SDKDefaultBackoffStrategy@6a24d5e3 reached by
            reading field com.amazonaws.retry.RetryPolicy.backoffStrategy of
                    constant com.amazonaws.retry.RetryPolicy@5dc90142 reached by
            scanning method com.amazonaws.ClientConfiguration.<init>(ClientConfiguration.java:155)
    Call path from entry point to com.amazonaws.ClientConfiguration.<init>(ClientConfiguration):
            no path found from entry point to target method
    
    
            at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:129)
            at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:756).

附言:几分钟前应用这个;

<properties>
    <quarkus.package.type>native</quarkus.package.type>
        <quarkus.native.additional-build-args>
            --initialize-at-run-time=com.amazonaws.ClientConfiguration\
                com.amazonaws.retry.PredefinedBackoffStrategies$EqualJitterBackoffStrategy\
                com.amazonaws.retry.PredefinedBackoffStrategies$FullJitterBackoffStrategy
        </quarkus.native.additional-build-args>
</properties>

它避免了几个例外。。。但它仍然抱怨如下;

[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:2.8.0.Final:build (default) on project casccb: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR]         [error]: Build step io.quarkus.deployment.pkg.steps.NativeImageBuildStep#build threw an exception: io.quarkus.deployment.pkg.steps.NativeImageBuildStep$ImageGenerationFailureException: Image generation failed. Exit code: 1
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.imageGenerationFailed(NativeImageBuildStep.java:396)
[ERROR]         at io.quarkus.deployment.pkg.steps.NativeImageBuildStep.build(NativeImageBuildStep.java:237)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR]         at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:925)
[ERROR]         at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR]         at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
[ERROR]         at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
[ERROR]         at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR]         at org.jboss.threads.JBossThread.run(JBossThread.java:501).

希望你能帮我解决这个问题。

提前谢谢。

JJ

共有1个答案

甄德寿
2023-03-14

这是您需要Quarkus扩展才能以原生方式工作的情况之一。

我们在Quarkiverse:https://github.com/quarkiverse/quarkus-amazon-services中有Amazon Services的扩展。

一旦有了这些扩展,就可以使用它的配置基础设施并注入CDIBeans,或者也可以自己做一些事情。

您可以在这里找到关于这些扩展的文档:https://quarkiverse.github.io/quarkiverse-docs/quarkus-amazon-services/dev/index.html .

 类似资料:
  • 当我建立一个本土形象时,我面临着一个反思的问题 通用域名格式。神谕svm。主持。代替DeletedElementException:不支持的java字段。朗,同学们。newInstanceCallerCache是可访问的:此元素的声明类已被替换,但替换类中不存在此元素 我该怎么修?我的环境GraalVM 20和Zulu OpenJdk11 我的pom

  • 我正在尝试使用GraalVM构建本机Quarkus映像,但遇到以下构建失败错误: 这是我第一次与GraalVM合作,所以我有点困惑。 以下是基本信息:Java版本17 Graavl VM版本graalvm-ce-javaV-22.1.0 我按照提供的步骤:https://stackoverflow.com/a/65837409/7584240和https://github.com/graalvm/

  • 我有以下简化设置: 4)应用程序.属性 当我使用本机maven配置文件(mvn clean package-pnative)运行该文件时,我得到: 使用--report-unsupport-elements-at-runtime运行它也没有太大帮助。当我删除MyEntity类时,它在Mac+GRAALVM-CE-Java11-20.0.0上成功地编译为本机可执行文件

  • 在我的项目的根目录中,我发出了以下命令来创建一个特定于我的操作系统的本机可执行文件。有关详细信息,请参阅以下指南 这是输出。 本机映像生成失败,因为构建刚刚挂起。 我选择在主机上安装Graal VM,并选择非基于容器的方法,如下所示。 > ❯ brew安装——cask GRALVM/tap/GRALVM-ce-lts-java11 将Graal VM添加到JEnv管理的Java版本 ❯ jenv

  • 失败:生成失败,出现异常。 错误:执行任务“:QuarkusBuild”失败。Io.Quarkus.Builder.BuildException:生成失败:由于错误导致生成失败[error]:生成步骤Io.Quarkus.Deployment.Pkg.Steps.NativeImageBuildStep#Build引发异常:java.lang.RuntimeException:未能在io.Quar

  • 我已经成功地用Quarkus/Graal构建了一个本机映像,我可以在终端中运行它(还没有容器)。但是,它会因“分段错误(堆芯转储)”消息而崩溃。如何获得有关错误的更多信息?是否有标志要传递给本机可执行文件或在构建映像时传递? 我使用的是GraalVM版本20.2.0(Java版本11.0.8) 任何帮助都是非常感激的。 谢谢