【问题标题】:Package JRE for Java application为 Java 应用程序打包 JRE
【发布时间】:2017-01-28 17:01:54
【问题描述】:

我的目标是通过 Maven 自动将独立的 JRE 与我的 Java 应用程序一起打包。

为了实现这一点,我使用了来自 JDK 的 exec-maven-pluginjavapackager。我的 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)

Unknown argument 似乎是我的-srcdir 参数。

我做错了什么?我想将我的原生 JRE 打包到目标目录中。

【问题讨论】:

    标签: java maven exec-maven-plugin javapackager


    【解决方案1】:

    如果您想将基本 jre 添加到您的捆绑包中,请使用 ths

    <argument>-Bruntime</argument>
    <argument>${env.JAVA_HOME}</argument>
    

    -srcdir 是所有依赖文件的目录,所以我只需要 1 排除 -srcdir 并使用 -srcfiles

    如果你不想,在它的末尾添加一个 path.separator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-27
      • 1970-01-01
      • 2010-09-05
      • 2021-12-29
      • 2014-07-04
      相关资源
      最近更新 更多