[英]How can I use launch4j to wrap a GUI application that also provides a command line interface?
我正在開發Java應用程序,主要是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>
launch4j的文檔說,設置headerType=gui
和stayAlive=true
的給定組合將等待應用程序關閉 ,情況並非如此。
由於我沒有可用的Windows計算機,因此無法嘗試設置headerType=console
時發生的情況。 文檔說,這會使包裝程序始終等待並返回應用程序的退出代碼 。 但是,由於我的應用程序主要是GUI應用程序,所以我想知道此設置是否有負面影響。 在這一點上,我開始問自己,為什么我希望包裝的應用程序具有不同於jar文件的其他命令行行為。
我終於啟動了Windows機器,並自行運行對其進行測試。
我通過替換這個解決了這個問題
<headerType>gui</headerType>
<stayAlive>true</stayAlive>
通過那個
<headerType>console</headerType>
根據文檔, stayAlive=true
實際上由headerType=console
隱含,因此我可以安全地將其從配置中刪除。
我無法注意到GUI的任何副作用。 唯一令人討厭的是,這將打開一個控制台,該控制台顯示控制台輸出。
因此,我猜想對此的預期解決方案是問題中所述的配置: headerType=gui
和stayAlive=true
。 但是,這不起作用。 我認為這是launch4j中的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.