从我的项目的根目录中,我发出以下命令来创建一个特定于我的操作系统的本机可执行文件。 See the following guide for details
mvn package -Pnative -Dquarkus.native.container-build=true
这是输出。
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< com.example:quarkus-spring >---------------------
[INFO] Building quarkus-spring 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:generate-code (default) @ quarkus-spring ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ quarkus-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ quarkus-spring ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:generate-code-tests (default) @ quarkus-spring ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ quarkus-spring ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ quarkus-spring ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M5:test (default-test) @ quarkus-spring ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.controller.GreetingControllerTest
2021-06-22 21:17:05,339 WARN [io.qua.dat.dep.dev.DevServicesDatasourceProcessor] (build-10) Unable to determine a database type for default datasource
2021-06-22 21:17:05,340 WARN [io.qua.agr.dep.AgroalProcessor] (build-16) The Agroal dependency is present but no JDBC datasources have been defined.
2021-06-22 21:17:06,080 INFO [io.quarkus] (main) Quarkus 1.13.7.Final on JVM started in 1.004s. Listening on: http://localhost:8081
2021-06-22 21:17:06,081 INFO [io.quarkus] (main) Profile test activated.
2021-06-22 21:17:06,081 INFO [io.quarkus] (main) Installed features: [agroal, cdi, hibernate-orm, hibernate-orm-panache, mongodb-client, mutiny, narayana-jta, resteasy, smallrye-context-propagation, spring-boot-properties, spring-data-jpa, spring-data-rest, spring-di]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.755 s - in com.example.controller.GreetingControllerTest
2021-06-22 21:17:06,699 INFO [io.quarkus] (main) Quarkus stopped in 0.020s
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ quarkus-spring ---
[INFO]
[INFO] --- quarkus-maven-plugin:1.13.7.Final:build (default) @ quarkus-spring ---
[INFO] [org.jboss.threads] JBoss Threads version 3.2.0.Final
[WARNING] [io.quarkus.agroal.deployment.AgroalProcessor] The Agroal dependency is present but no JDBC datasources have been defined.
[INFO] [org.hibernate.Version] HHH000412: Hibernate ORM core version 5.4.29.Final
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building native image source jar: /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar/quarkus-spring-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Building native image from /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar/quarkus-spring-1.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Using docker to run the native image builder
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildContainerRunner] Checking image status quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
21.0-java11: Pulling from quarkus/ubi-quarkus-native-image
Digest: sha256:356624049da5f564e14acbaf167a341a01b332569db83e9967b1e72cfdf06653
Status: Image is up to date for quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
quay.io/quarkus/ubi-quarkus-native-image:21.0-java11
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildStep] Running Quarkus native-image plugin on GraalVM Version 21.0.0.2 (Java Version 11.0.10+8-jvmci-21.0-b06)
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] docker run --env LANG=C --rm -v /Users/viswanath/projects/quarkus-spring/target/quarkus-spring-1.0-SNAPSHOT-native-image-source-jar:/project:z quay.io/quarkus/ubi-quarkus-native-image:21.0-java11 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 -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-Duser.country=GB -J-Dfile.encoding=UTF-8 --initialize-at-build-time= -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy\$BySpaceAndTime -H:+JNI -H:+AllowFoldMethods -jar quarkus-spring-1.0-SNAPSHOT-runner.jar -H:FallbackThreshold=0 -H:+ReportExceptionStackTraces -J-Xmx8192m -H:-AddAllCharsets -H:EnableURLProtocols=http,https --enable-all-security-services --no-server -H:-UseServiceLoaderFeature -H:+StackTrace quarkus-spring-1.0-SNAPSHOT-runner
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
^C%
本地映像生成失败,因为构建只是挂起。
我选择在我的主机上安装 Graal VM 并选择基于非容器的方法,如下所示。
使用以下命令在 M1 Mac 上安装 Graal VM
❯ brew install --cask graalvm/tap/graalvm-ce-lts-java11
将 Graal VM 添加到 Java 的 JEnv 托管版本
❯ jenv add /Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home 添加了 graalvm64-11.0.10
对于项目,设置 Graal VM 的 Java 11。从项目的目录中,发出以下命令
❯ jenv 本地 graalvm64-11.0.10
将 GRAALVM_HOME 环境变量设置为 GraalVM 安装目录。将以下内容添加到 ~/.zshrc
❯ export GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-lts-java11-20.3.1/Contents/Home
并通过发出命令重新加载对 .zshrc 所做的更改
❯ source ~/.zshrc
使用以下命令安装本机图像工具。默认情况下,GraalVM 的一些先前版本包含本机映像工具。这已不再是这种情况;必须在安装 GraalVM 之后作为第二步安装。
❯ ${GRAALVM_HOME}/bin/gu install native-image
安装binutils并添加到路径
❯ brew install binutils
❯ echo 'export PATH="/opt/homebrew/opt/binutils/bin:$PATH"' >> ~/.zshrc ❯ 源代码 ~/.zshrc
使用以下命令从项目的根目录创建本机可执行文件
❯ mvn clean install -Pnative -Dnative-image.docker-build=true -Dquarkus.native.native-image-xmx=4g
最后当我运行原生镜像时,它失败了。
❯ ~/projects/quarkus-spring/target ./quarkus-spring-1.0-SNAPSHOT-runner
[1] 11638 killed ./quarkus-spring-1.0-SNAPSHOT-runner
有什么帮助吗?
答案 0 :(得分:1)
documentation 说明 -Dquarkus.native.container-build=true
选项意味着您要构建 Linux 可执行文件,并且构建应该在容器中进行。
您甚至可以通过以下方式控制该 Docker/Podman 的运行时:
# Docker
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=docker
# Podman
./mvnw package -Pnative -Dquarkus.native.container-build=true -Dquarkus.native.container-runtime=podman
这可能是执行上一个命令后可执行文件在 MacOS 上无法运行的原因,因为它是 Linux 二进制文件。您可以通过以下方式检查:
file ./quarkus-spring-1.0-SNAPSHOT-runner
虽然在命令行中您使用的是“-Dquarkus.native.docker-build=true”而不是“-Dquarkus.native.container-build.true”,但我不知道是否有任何相关性。