2

我正在尝试调整我的构建过程以生成独立的可执行文件。有一些工具可以做到这一点,Packr 似乎是一个完美的工具。据我所知,它是我的 Maven 官方支持的。

在花了大约一个时期的谷歌搜索之后,我没有找到一个简单的打包器构建步骤的简单 maven XML 示例。此外,我对 Maven 很陌生,这使得这变得更加复杂。但在我看来,应该有一个相当标准的 XML 块,只需要更改几个 jar 名称即可使其正常工作。

我也在 eclipse 中工作并尝试为 windows 和 linux 构建可执行文件。

打包器:https ://github.com/libgdx/packr

Maven 中的 Packr:https ://mvnrepository.com/artifact/com.badlogicgames.packr/packr

4

3 回答 3

4

我编写了一个包装了 packr java api 的 maven 构建插件。该插件是围绕 packr 的第 2 版构建的。

https://github.com/stevenmz/packer-maven-plugin

于 2017-02-09T17:23:01.893 回答
2

我也找不到任何 Maven 插件。

maven Central 中有 1.2 版的 packr,但请记住,这现在是一个相当旧的版本(https://github.com/libgdx/packr/issues/58)。

您可以使用标准 exec-maven-plugin 来利用 packr 1.2 依赖项,然后运行它(请参阅http://www.mojohaus.org/exec-maven-plugin/examples/example-exec-using-plugin-dependencies .html)。

pom.xml 构建文件中的相关片段可能类似于:

<build>
  <plugins>         
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>1.5.0</version>
      <dependencies>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.packr/packr -->
        <dependency>
          <groupId>com.badlogicgames.packr</groupId>
          <artifactId>packr</artifactId>
          <version>1.2</version>
        </dependency>
      </dependencies>

      <executions>
        <execution>
          <id>package-native-windows</id>

          <phase>package</phase>
          <goals>
            <goal>java</goal>
          </goals>

          <configuration>
            <includeProjectDependencies>false</includeProjectDependencies>
            <includePluginDependencies>true</includePluginDependencies>
            <executableDependency>
              <groupId>com.badlogicgames.packr</groupId>
              <artifactId>packr</artifactId>
            </executableDependency>

            <mainClass>com.badlogicgames.packr.Packr</mainClass>
            <arguments>
              <argument>packr-windows-config.json</argument>
            </arguments>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

如果您的 pom.xml 中已经有一个<build>and<plugins>部分,那么只需<plugin>将其放入其中。

json 配置文件可能类似于:

{
  "platform": "windows",
  "jdk": "jre-8u102-windows-x64.zip",
  "executable": "MyApp",
  "appjar": "target/MyApp-jar-with-dependencies.jar",
  "classpath": [ "MyApp-jar-with-dependencies.jar" ],
  "mainclass": "com.foo.MyAppMain",
  "outdir": "target/native-windows"
}

需要注意的一件事是,packr 1.2 似乎删除了“outdir”目录,所以要小心使用“target”目录以外的东西。

如果有帮助,我个人最终使用带有launch4j-maven-plugin 的launch4j 为windows 打包,并通过javafx-maven-plugin 使用Oracle 的标准javapackager 工具为linux/mac 打包。我会链接到这两个,但 StackOverflow 告诉我我没有足够的代表来包含两个以上的链接。

于 2016-09-23T11:14:35.483 回答
1

1.在 pom.xml 中定义配置文件,适用于 Windows、Linux 和 Mac OS X 2.假设我下载了 packr.jar,只需调用必要的配置文件

<profiles>
    <profile>
        <id>windows-profile</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.6.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>exec</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <executable>java</executable>
                        <arguments>
                            <argument>-jar</argument>
                            <argument>${basedir}/packaging/packr.jar</argument>
                            <argument>${basedir}/packaging/config-windows.json</argument>
                        </arguments>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

要获得您的 windows 分布,请告诉 maven 所需的配置文件:

clean install -Pwindows-profile

您还可以在下面看到 config-windows.json :

{
  "platform": "windows64",
  "jdk": "C:/Program Files/Java/jdk1.8.0_144",
  "executable": "file-sort",
  "classpath": [
    "target/file-sort-jar-with-dependencies.jar"
  ],
  "mainclass": "com.iscorobogaci.fx.FxApplication",
  "output": "../windows64"
}

在 GitHub 上查看:https ://github.com/scorobogaci/file-sorting-app

于 2018-11-16T14:14:25.463 回答