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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6060560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:09:47  来源:igfitidea点击:

Trying to integrate Launch4j in a Maven project using Alakai plugin

javamavenintegrationlaunch4j

提问by Jér?me Verstrynge

I am trying to integrate the generation of an installer as part of a maven compilation process.

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

I have found Alakai's pluginfor Launch4j. I have create a simple Hello World application using Maven. I have tried to use configuration examples provided by Alakai, but when I compile my project, I get:

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

Failed to execute goal org.bluestemsoftware.open.maven.plugin:launch4j-plugin:1.5.0.0:launch4j (launch4j) on project Launch4j: Failed to build the executable; please verify your configuration. Application jar doesnt exist. -> [Help 1]

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

Unfortunately, Alakai's documentation is limited and I could not find much with Googling.

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

  • Does anyone know where the Launch4j config.xml should be set? Is it within the project? Is it in a separate directory?
  • Do I need to use the assembly plugin?
  • I have installed Launch4j on my PC. Do I need to specify the installation directory in my pom.xml? If yes how?
  • Does anyone have an operational pom.xml sample/example to share?
  • 有谁知道 Launch4j config.xml 应该在哪里设置?是在项目内吗?它在单独的目录中吗?
  • 我需要使用程序集插件吗?
  • 我已经在我的 PC 上安装了 Launch4j。我需要在我的 pom.xml 中指定安装目录吗?如果是如何?
  • 有没有人有可操作的 pom.xml 示例/示例要分享?

Thanks.

谢谢。

回答by BrunoJCM

  1. There's no config.xml, you need to configure launch4j inside your pom.xml file.
  2. You could use maven-assembly-plugin, but I recommend you to use maven-shade-plugin.
  3. Don't need to specify launch4j installation, this plugin works 100% maven.
  4. Sure. Follows the shade and launch4j configs I use, that generates two exes, one console and one gui, using different main classes:
  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>

Alternatively, You can omit the 'jar' tag on launch4j-plugin and remove the extra configs of the shade-plugin, but be aware that this will replace the main jar of the flow (without embedded dependencies) by the shaded jar (with embedded dependencies), and this one will be installed on your local repo, or used in the reactor if needed.

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

回答by Jon Onstott

For how to define the main class for the shade plugin, see http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html.

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