【问题标题】:How can I use launch4j to wrap a GUI application that also provides a command line interface?我如何使用 launch4j 来包装还提供命令行界面的 GUI 应用程序?
【发布时间】:2016-05-14 07:11:12
【问题描述】:

我正在开发一个 Java 应用程序,它主要是一个 GUI 应用程序。但是,它也提供了一个命令行界面。我可以将命令行参数分为三种不同的类型:

  • 第一类参数改变了 GUI 的行为。
  • 第二种类型以特定状态启动 GUI。
  • 第三种类型使应用程序直接执行操作而不显示 GUI。

当我使用java -jar <application-name>.jar -parameter 执行应用程序时,一切正常。应用程序执行它被要求做的事情。应用程序关闭或完成后,shell 提示符返回。

问题

当我使用 launch4j 从 jar 文件创建 Windows 包装器时,这种行为会发生变化。 shell 提示符总是立即返回。因此,我仍然可以传递命令行参数,但无法通过终端与应用程序交互。它不会打印写入 stdout 或 stderr 的任何内容,也无法从 stdin 读取任何内容。

问题

如何配置 launch4j 以创建一个 exe 包装器,该包装器提供与包装的 jar 文件相同的命令行行为?

其他信息

我使用具有以下配置的launch4j maven插件:

<plugin>
    <groupId>com.akathist.maven.plugins.launch4j</groupId>
    <artifactId>launch4j-maven-plugin</artifactId>
    <version>1.7.8</version>
    <executions>
        <execution>
            <id>launch4j</id>
            <phase>package</phase>
            <goals>
                <goal>launch4j</goal>
            </goals>
            <configuration>
                <headerType>gui</headerType>
                <stayAlive>true</stayAlive>
                <outfile>path/to/outfile.exe</outfile>
                <jar>path/to/infile.jar</jar>
                <dontWrapJar>false</dontWrapJar>
                <errTitle>Error in Launcher</errTitle>
                <classPath>
                    <mainClass>com.example.Launch</mainClass>
                    <addDependencies>false</addDependencies>
                </classPath>
                <icon>path/to/icon.ico</icon>
                <jre>
                    <minVersion>1.8.0</minVersion>
                    <initialHeapSize>512</initialHeapSize>
                    <maxHeapSize>1024</maxHeapSize>
                </jre>
            </configuration>
        </execution>
    </executions>
</plugin>

documentation of launch4j 表示,headerType=guistayAlive=true 设置的给定组合将等待应用程序关闭,但事实并非如此。

由于我没有可用的 Windows 机器,我无法尝试设置 headerType=console 时会发生什么。文档说这会导致包装器始终等待并返回应用程序的退出代码。但是,由于我的应用程序主要是一个 GUI 应用程序,我想知道这个设置是否有任何负面影响。在这一点上,我开始问自己,为什么我希望被包装的应用程序具有与 jar 文件不同的命令行行为。

【问题讨论】:

    标签: java shell maven launch4j


    【解决方案1】:

    我终于启动并运行了一台 Windows 机器来自己测试。

    我通过替换这个解决了这个问题

    <headerType>gui</headerType>
    <stayAlive>true</stayAlive>
    

    就这样

    <headerType>console</headerType>
    

    根据文档stayAlive=true实际上是由headerType=console暗示的,所以我可以安全地从配置中删除它。

    我没有注意到这对 GUI 的任何副作用。唯一烦人的是,这会打开一个显示控制台输出的控制台。

    所以,我想这个问题的预期解决方案是问题中描述的配置:headerType=guistayAlive=true。但是,这不起作用。我认为这是 launch4j 中的一个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 2021-06-01
      • 2011-10-31
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多