我的目标是通过 Maven 自动将独立的 JRE 与我的 Java 应用程序一起打包。
为了实现这一点,我使用 JDK 中的 exec-maven-plugin
和 javapackager
。我的 POM 设置如下所示:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>package-jar2</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
${env.JAVA_HOME}/bin/javapackager
</executable>
<arguments>
<argument>-deploy</argument>
<argument>-native</argument>
<argument>exe</argument>
<argument>-appclass</argument>
<argument>${app.main.class}</argument>
<argument>-srcdir</argument>
<argument>${project.build.directory}</argument>
<argument>-srcfiles</argument>
<argument>${project.build.directory}\${artifactId}-${version}.jar</argument>
<argument>-outdir</argument>
<argument>${project.build.directory}</argument>
<argument>-outfile</argument>
<argument>${project.artifactId}-${version}</argument>
<argument>-v</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
最后,javapackager
发出以下错误:
[INFO] --- exec-maven-plugin:1.5.0:exec (package-jar2) @ cli-api ---
Error: Unknown argument: D:\Archiv\Dokumente\Entwicklung\PEProjekt\repository\core\cli-api\target
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: -1 (Exit value: -1)
未知参数
似乎是我的-srcdir
参数。
我做错了什么?我想将我的 native JRE 打包到目标目录中。
最佳答案
如果你想将基础 jre 添加到你的包中,请使用 ths
<argument>-Bruntime</argument>
<argument>${env.JAVA_HOME}</argument>
-srcdir
是所有依赖文件的目录,因此您只需要 1 排除 -srcdir
并使用 -srcfiles
如果您不想,请在其末尾添加一个path.separator
关于java - 为 Java 应用程序打包 JRE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39599707/