13

我正在尝试将安装程序的生成集成为 Maven 编译过程的一部分。

我找到了Alakai 的Launch4j插件。我使用 Maven 创建了一个简单的 Hello World 应用程序。我尝试使用 Alakai 提供的配置示例,但是当我编译我的项目时,我得到:

无法在项目 Launch4j 上执行目标 org.bluestemsoftware.open.maven.plugin:launch4j-plugin:1.5.0.0:launch4j (launch4j):无法构建可执行文件;请验证您的配置。应用程序 jar 不存在。-> [帮助 1]

不幸的是,Alakai 的文档是有限的,我在谷歌上找不到太多。

  • 有谁知道 Launch4j config.xml 应该设置在哪里?是在项目内吗?它在单独的目录中吗?
  • 我需要使用组装插件吗?
  • 我已经在我的电脑上安装了 Launch4j。我需要在我的 pom.xml 中指定安装目录吗?如果是怎么办?
  • 有没有人可以分享一个可操作的 pom.xml 示例/示例?

谢谢。

4

2 回答 2

27
  1. 没有config.xml,你需要在你的pom.xml 文件中配置launch4j。
  2. 您可以使用 maven-assembly-plugin,但我建议您使用 maven-shade-plugin。
  3. 不需要指定launch4j安装,这个插件100% maven工作。
  4. 当然。遵循我使用的 shade 和 launch4j 配置,生成两个 exe,一个控制台和一个 gui,使用不同的主类:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
        <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
    </configuration>
</plugin>

<plugin>
    <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
    <artifactId>launch4j-plugin</artifactId>
    <version>1.5.0.0</version>
    <executions>

        <!-- GUI exe -->
        <execution>
            <id>l4j-gui</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>gui</headerType>
                <outfile>target/app-gui.exe</outfile>
                <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                <errTitle>App Err</errTitle>
                <classPath>
                    <mainClass>package.AppGUI</mainClass>
                </classPath>
                <icon>src/main/resources/icons/exeIcon.ico</icon>
                <jre>
                    <minVersion>1.5.0</minVersion>
                    <maxVersion>1.6.0</maxVersion>
                    <initialHeapSize>128</initialHeapSize>
                    <maxHeapSize>1024</maxHeapSize>
                </jre>
                <versionInfo>
                    <fileVersion>1.0.0.0</fileVersion>
                    <txtFileVersion>1.0.0.0</txtFileVersion>
                    <fileDescription>Desc</fileDescription>
                    <copyright>C</copyright>
                    <productVersion>1.0.0.0</productVersion>
                    <txtProductVersion>1.0.0.0</txtProductVersion>
                    <productName>Product</productName>
                    <internalName>Product</internalName>
                    <originalFilename>App.exe</originalFilename>
                </versionInfo>
            </configuration>
        </execution>

        <!-- Command-line exe -->
        <execution>
            <id>l4j-cli</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>console</headerType>
                <outfile>target/app-cli.exe</outfile>
                <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                <errTitle>App Err</errTitle>
                <classPath>
                    <mainClass>package.AppCLI</mainClass>
                </classPath>
                <icon>src/main/resources/icons/exeIcon.ico</icon>
                <jre>
                    <minVersion>1.5.0</minVersion>
                    <maxVersion>1.6.0</maxVersion>
                    <initialHeapSize>128</initialHeapSize>
                    <maxHeapSize>1024</maxHeapSize>
                </jre>
            </configuration>
        </execution>
    </executions>
</plugin>

或者,您可以省略 launch4j-plugin 上的“jar”标签并删除 shade-plugin 的额外配置,但请注意,这将用阴影 jar(嵌入依赖项),并且这个将安装在您的本地存储库中,或者在需要时在反应器中使用。

于 2011-05-31T22:16:35.697 回答
1

有关如何定义阴影插件的主类,请参见http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html

于 2012-01-08T00:45:53.960 回答