尝试使用 Alakai 插件将 Launch4j 集成到 Maven 项目中

Posted

技术标签:

【中文标题】尝试使用 Alakai 插件将 Launch4j 集成到 Maven 项目中【英文标题】:Trying to integrate Launch4j in a Maven project using Alakai plugin 【发布时间】:2011-08-28 23:14:24 【问题描述】:

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

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

未能执行目标 org.bluestemsoftware.open.maven.plugin:launch4j-plugin:1.5.0.0:launch4j (launch4j)项目Launch4j:失败 构建可执行文件;请核实 你的配置。应用程序罐子 不存在。 -> [帮助 1]

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

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

谢谢。

【问题讨论】:

只是相关信息:此问题的答案也适用于 9 St. Mary Rd。 launch4j 插件,这是原始插件(AFAIK)。如果您使用这个旧版本,我建议您迁移到 Alakai 的最新版本。 【参考方案1】:
    没有config.xml,需要在pom.xml文件中配置launch4j。 您可以使用 maven-assembly-plugin,但我建议您使用 maven-shade-plugin。 不需要指定launch4j安装,这个插件100% maven工作。 当然。遵循我使用的 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 替换流的主 jar(没有嵌入式依赖项) (带有嵌入式依赖项),并且这个将安装在您的本地 repo 中,或者在需要时在反应器中使用。

【讨论】:

太棒了,它有效。但是,我在你的例子中发现了一个小转折。 maven-shade-plugin 似乎没有在清单中保留主类名。所以,当我双击 exe 时,我得到一个找不到的类。我改用了汇编插件(我认识的魔鬼)。 AFAIK,我们不需要清单上的主类来使其工作。您是否双重检查了完全限定的类名?我只是从一个已经投入生产的项目中获取它,只是更改了名称。如果你想把你的 pom 发给我,我可以帮你,我的电子邮件是我的昵称,在 gmail。无论如何,很好,你可以解决你的问题! 感谢您的奉献。我可以在程序集插件中设置主类。现在都干净了。 这里有更新更好的插件版本:github.com/vorburger/launch4j-maven-plugin 有人可以提供一个关于如何使用程序集插件的示例(片段)吗?【参考方案2】:

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

【讨论】:

@Damian 修复了链接 不鼓励仅链接答案,请至少添加一个如何做的摘要。

以上是关于尝试使用 Alakai 插件将 Launch4j 集成到 Maven 项目中的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Gradle 中使用带有混淆 jar 的 Launch4J

在用 launch4j 包装的 Firefox 上阻止 .exe 下载

将 Java 可执行文件(使用 launch4j)固定到 Windows 7 任务栏

使用 Launch4j VM 参数路径包装的 JavaFX 项目

Win 7 pin 到任务栏 + launch4j + NSIS

launch4j:通过命令行覆盖默认 JVM 堆大小