建立失败

mvn package -Pnative -Dnative-image.docker-build=true


我遵循了https://quarkus.io/guides/building-native-image-guide#creating-a-container

mvn package -Pnative -> success

[io.quarkus.creator.phase.nativeimage.NativeImagePhase] Running Quarkus native-image plugin on OpenJDK 64-Bit GraalVM CE 19.2.0
[io.quarkus.creator.phase.nativeimage.NativeImagePhase] /usr/lib/jvm/graalvm-ce-19.2.0/jre/bin/native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dio.netty.leakDetection.level=DISABLED -J-Dvertx.disableDnsResolver=true -J-Dio.netty.noUnsafe=true -H:ReflectionConfigurationFiles=/shared_data/quarkus_jaxrs/reflection-config.json -H:ResourceConfigurationFiles=/shared_data/quarkus_jaxrs/resources-config.json --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar ph-quarkus-jwt-1.0-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -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


mvn package -Pnative -Dnative-image.docker-build=true -> failure

docker run -v /shared_data/quarkus_jaxrs/target:/project:z --rm --user 0:0 quay.io/quarkus/ubi-quarkus-native-image:19.1.1 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dio.netty.leakDetection.level=DISABLED -J-Dvertx.disableDnsResolver=true -J-Dio.netty.noUnsafe=true -H:ReflectionConfigurationFiles=/shared_data/quarkus_jaxrs/reflection-config.json -H:ResourceConfigurationFiles=/shared_data/quarkus_jaxrs/resources-config.json --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar ph-quarkus-jwt-1.0-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -H:+PrintAnalysisCallTree -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services -H:-SpawnIsolates -H:+JNI --no-server -H:-UseServiceLoaderFeature -H:+StackTrace
Error: Invalid Path entry /shared_data/quarkus_jaxrs/reflection-config.json
Caused by: java.nio.file.NoSuchFileException: /shared_data/quarkus_jaxrs/reflection-config.json


> mvn package -Pnative -Dnative-image.docker-build=true ( running dockerised way)
  -> docker run -v /shared_data/quarkus_jaxrs/target:/project .....
  ->
Error: Invalid Path entry /shared_data/quarkus_jaxrs/reflection-config.json
Caused by: java.nio.file.NoSuchFileException: /shared_data/quarkus_jaxrs/reflection-config.json

> mvn package -Pnative ( running from graal vm locally installed )
  -> /usr/lib/jvm/graalvm-ce-19.2.0/jre/bin/native-image


两者都应导致天真的图像可执行文件。

最佳答案

试试这个。

将Reflection-config.json移至

src/main/resources/reflection-config.json


然后像这样更改pom.xml

      <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>
                <additionalBuildArg>-H:ReflectionConfigurationFiles=classes/reflection-config.json</additionalBuildArg>
              </additionalBuildArgs>
            </configuration>
          </execution>
        </executions>
      </plugin>

关于java - Quarkus使用-Dnative-image.docker-build = true构建 native 可执行NoSuchFileException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57900399/

10-11 14:23