如何使用 quarkus 创建本机可执行文件?
How to create native executable using quarkus?
我使用 quarkus maven 插件创建了一个 quarkus 应用程序。
我的maven pom如下
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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</groupId>
<artifactId>quarkus-poc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<quarkus.version>0.11.0</quarkus.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>4.0.0.Beta5</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<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>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
但是当我尝试使用 mvn package -Pnative -Dnative-image.docker-build=true
创建本机构建时,我收到以下错误消息,与平台无关。
[INFO] --- quarkus-maven-plugin:0.11.0:native-image (default) @ quarkus-poc ---
[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] Running Quarkus native-image plugin on Java HotSpot(TM) 64-Bit Server VM
[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] docker run -v C:\Users\nicolas-delsaux\Documents\Adeo\inhabitant-referential--api-poc-challenge\quarkus\target:/project:z --rm swd847/centos-graal-native-image-rc12 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar quarkus-poc-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:+PrintAnalysisCallTree -H:EnableURLProtocols=http -H:-SpawnIsolates -H:-JNI -H:-UseServiceLoaderFeature -H:+StackTrace
Error: No main manifest attribute, in /project/quarkus-poc-1.0-SNAPSHOT-runner.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.308 s
[INFO] Finished at: 2019-03-12T16:11:43+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:0.11.0:native-image (default) on project quarkus-poc: Failed to generate a native image: Failed to build native image: Image generation failed -> [Help 1]
我知道我没有创建任何类型的主程序 class,因为 quarkus 似乎不需要它。但是我如何向 Java 平台声明我打算让 quarkus 决定主 class ?
EDIT 回应c。鸣叫,这里有更多信息
-runner.jar
内容是
+---com
| \---company
| \---service
| \---domain
| \---poc
| Customer.class
| CustomerService.class
| CustomerService_Bean.class
| CustomersResource.class
| CustomersResource_Bean.class
|
+---io
| \---quarkus
| +---arc
| | | ActivateRequestContextInterceptor_Bean.class
| | |
| | +---runtime
| | | LifecycleEventRunner_Bean.class
| | |
| | \---setup
| | Default_ComponentsProvider.class
| |
| +---deployment
| | \---steps
| | ArcAnnotationProcessor$build4.class
| | LifecycleEventsBuildStep$startupEvent9.class
| | LoggingResourceProcessor$setupLoggingRuntimeInit1.class
| | LoggingResourceProcessor$setupLoggingRuntimeInit2.class
| | LoggingResourceProcessor$setupLoggingStaticInit1.class
| | LoggingResourceProcessor$setupLoggingStaticInit2.class
| | ResteasyScanningProcessor$setupInjection5.class
| | ResteasyScanningProcessor$setupInjection6.class
| | UndertowArcIntegrationBuildStep$integrateRequestContext5.class
| | UndertowArcIntegrationBuildStep$integrateRequestContext6.class
| | UndertowBuildStep$boot8.class
| | UndertowBuildStep$build7.class
| |
| +---runner
| | ApplicationImpl1.class
| | AutoFeature.class
| | GeneratedMain.class
| |
| \---runtime
| \---generated
| ConfigHelper.class
| ConfigHelperData.class
| ConfigRoot.class
|
+---javax
| \---enterprise
| \---context
| \---control
| ActivateRequestContext_Shared_AnnotationLiteral.class
|
\---META-INF
| MANIFEST.MF
| microprofile-config.properties
| quarkus-default-config.properties
|
+---maven
| \---com
| \---quarkus-poc
| pom.properties
| pom.xml
|
+---resources
| index.html
|
\---services
io.quarkus.arc.ComponentsProvider
我很确定你们中的一些人会要求 MANIFEST.MF 内容
Manifest-Version: 1.0
Built-By: nicolas-delsaux
Build-Jdk: 1.8.0_131
Created-By: Maven Integration for Eclipse
我觉得清单文件很奇怪...
我猜 eclipse 已经为您自动创建了一个清单文件,我们没有正确处理这种情况。根据添加清单的方式,运行 'mvn clean package' 可能会修复它,或者 'src/main/resources' 中可能有一个 MANIFEST.MF 文件需要删除。
我已提交 https://github.com/quarkusio/quarkus/issues/1443 以改进我们处理此问题的方式。
一些额外的无关评论:
- 您可以使用
resteasy-jsonb
扩展名代替 Jackson
- 如果你真的想要 Jackson,版本应该在我们的 BOM 中定义,你可以放弃你的(无论如何,它不是正确的)
- 我们现在建议使用
src/main/resources/application.properties
作为您的配置文件(我们最近修复了项目创建)
- 您不需要
quarkus-arc
依赖项
- 您应该将
quarkus-junit5
的范围定义为 test
。目前,它包含在 BOM 中,但我们会尽快更改。
我使用 quarkus maven 插件创建了一个 quarkus 应用程序。
我的maven pom如下
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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</groupId>
<artifactId>quarkus-poc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<quarkus.version>0.11.0</quarkus.version>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>4.0.0.Beta5</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<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>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
但是当我尝试使用 mvn package -Pnative -Dnative-image.docker-build=true
创建本机构建时,我收到以下错误消息,与平台无关。
[INFO] --- quarkus-maven-plugin:0.11.0:native-image (default) @ quarkus-poc ---
[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] Running Quarkus native-image plugin on Java HotSpot(TM) 64-Bit Server VM
[INFO] [io.quarkus.creator.phase.nativeimage.NativeImagePhase] docker run -v C:\Users\nicolas-delsaux\Documents\Adeo\inhabitant-referential--api-poc-challenge\quarkus\target:/project:z --rm swd847/centos-graal-native-image-rc12 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime -jar quarkus-poc-1.0-SNAPSHOT-runner.jar -J-Djava.util.concurrent.ForkJoinPool.common.parallelism=1 -H:+PrintAnalysisCallTree -H:EnableURLProtocols=http -H:-SpawnIsolates -H:-JNI -H:-UseServiceLoaderFeature -H:+StackTrace
Error: No main manifest attribute, in /project/quarkus-poc-1.0-SNAPSHOT-runner.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.308 s
[INFO] Finished at: 2019-03-12T16:11:43+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus:quarkus-maven-plugin:0.11.0:native-image (default) on project quarkus-poc: Failed to generate a native image: Failed to build native image: Image generation failed -> [Help 1]
我知道我没有创建任何类型的主程序 class,因为 quarkus 似乎不需要它。但是我如何向 Java 平台声明我打算让 quarkus 决定主 class ?
EDIT 回应c。鸣叫,这里有更多信息
-runner.jar
内容是
+---com
| \---company
| \---service
| \---domain
| \---poc
| Customer.class
| CustomerService.class
| CustomerService_Bean.class
| CustomersResource.class
| CustomersResource_Bean.class
|
+---io
| \---quarkus
| +---arc
| | | ActivateRequestContextInterceptor_Bean.class
| | |
| | +---runtime
| | | LifecycleEventRunner_Bean.class
| | |
| | \---setup
| | Default_ComponentsProvider.class
| |
| +---deployment
| | \---steps
| | ArcAnnotationProcessor$build4.class
| | LifecycleEventsBuildStep$startupEvent9.class
| | LoggingResourceProcessor$setupLoggingRuntimeInit1.class
| | LoggingResourceProcessor$setupLoggingRuntimeInit2.class
| | LoggingResourceProcessor$setupLoggingStaticInit1.class
| | LoggingResourceProcessor$setupLoggingStaticInit2.class
| | ResteasyScanningProcessor$setupInjection5.class
| | ResteasyScanningProcessor$setupInjection6.class
| | UndertowArcIntegrationBuildStep$integrateRequestContext5.class
| | UndertowArcIntegrationBuildStep$integrateRequestContext6.class
| | UndertowBuildStep$boot8.class
| | UndertowBuildStep$build7.class
| |
| +---runner
| | ApplicationImpl1.class
| | AutoFeature.class
| | GeneratedMain.class
| |
| \---runtime
| \---generated
| ConfigHelper.class
| ConfigHelperData.class
| ConfigRoot.class
|
+---javax
| \---enterprise
| \---context
| \---control
| ActivateRequestContext_Shared_AnnotationLiteral.class
|
\---META-INF
| MANIFEST.MF
| microprofile-config.properties
| quarkus-default-config.properties
|
+---maven
| \---com
| \---quarkus-poc
| pom.properties
| pom.xml
|
+---resources
| index.html
|
\---services
io.quarkus.arc.ComponentsProvider
我很确定你们中的一些人会要求 MANIFEST.MF 内容
Manifest-Version: 1.0
Built-By: nicolas-delsaux
Build-Jdk: 1.8.0_131
Created-By: Maven Integration for Eclipse
我觉得清单文件很奇怪...
我猜 eclipse 已经为您自动创建了一个清单文件,我们没有正确处理这种情况。根据添加清单的方式,运行 'mvn clean package' 可能会修复它,或者 'src/main/resources' 中可能有一个 MANIFEST.MF 文件需要删除。
我已提交 https://github.com/quarkusio/quarkus/issues/1443 以改进我们处理此问题的方式。
一些额外的无关评论:
- 您可以使用
resteasy-jsonb
扩展名代替 Jackson - 如果你真的想要 Jackson,版本应该在我们的 BOM 中定义,你可以放弃你的(无论如何,它不是正确的)
- 我们现在建议使用
src/main/resources/application.properties
作为您的配置文件(我们最近修复了项目创建) - 您不需要
quarkus-arc
依赖项 - 您应该将
quarkus-junit5
的范围定义为test
。目前,它包含在 BOM 中,但我们会尽快更改。