简体   繁体   English

如何为 java jar 文件创建 Windows 安装程序?

[英]How do I create a Windows installer for a java jar file?

I want to create a windows installer for my jar file.我想为我的 jar 文件创建一个 windows 安装程序。 I don't want to have to install jre/jdk on the target computer I want to deploy to.我不想在要部署到的目标计算机上安装 jre/jdk。

I tried out jpackage (part of Java 14) and it didn't work for me.我尝试了 jpackage(Java 14 的一部分),但它对我不起作用。 I tried the following command:我尝试了以下命令:

jpackage --input target/ --name my_pkg --main-jar NtbnsProj.jar --main-class myJFrame --type exe --java-options '--enable-preview'

It generates a my_pkg-1.0.exe, but I can't get it to run.它会生成一个 my_pkg-1.0.exe,但我无法让它运行。

At this point, I'm willing to try even third party tools.在这一点上,我什至愿意尝试第三方工具。 I've tried install4j with no success.我试过 install4j 没有成功。 Another website I found said to use install4j with Inno Setup Compiler.我发现另一个网站说将 install4j 与 Inno Setup Compiler 一起使用。 This was more complicated and didn't work either.这更复杂,也不起作用。 I thought maybe WiX Toolset might work.我想也许 WiX 工具集可能会工作。

If someone could provide step by step instructions, especially if the solution involves install4j, as there are many different steps where you can miss something.如果有人可以提供分步说明,特别是如果解决方案涉及 install4j,因为有许多不同的步骤您可能会错过一些东西。 I was using a newer version of install4j, and it didn't match the online tutorials and videos.我使用的是较新版本的 install4j,它与在线教程和视频不匹配。 The menu selections have changed significantly.菜单选择发生了显着变化。 Perhaps I need to use an older version of install4j.也许我需要使用旧版本的 install4j。

See my related article: How do I package a java jar file to run on a Mac without JRE installed?请参阅我的相关文章: 如何在未安装 JRE 的 Mac 上运行 package 和 java jar 文件?

Double check that your app runs directly then fix any issues before continuing:仔细检查您的应用程序是否直接运行,然后在继续之前修复所有问题:

java -cp NtbnsProj.jar myJFrame 

It looks as though jpackage has worked, and generated your installer my_pkg-1.0.exe .看起来jpackage似乎已经工作,并生成了您的安装程序my_pkg-1.0.exe When you run my_pkg-1.0.exe check that you have this file, then run it:当你运行my_pkg-1.0.exe检查你是否有这个文件,然后运行它:

C:\Program Files\my_pkg\my_pkg.exe

If that fails, re-run jpackage with extra arguments --win-console --app-version 1.1 , this will generate my_pkg-1.1.exe with console enabled.如果失败,请使用额外的 arguments --win-console --app-version 1.1重新运行 jpackage,这将生成my_pkg-1.1.exe并启用控制台。 Re-install and running C:\Program Files\my_pkg\my_pkg.exe might report a useful error message indicating what is your real issue.重新安装并运行C:\Program Files\my_pkg\my_pkg.exe可能会报告一条有用的错误消息,指出您的真正问题。

If you don't upgrade the --app-version each time, Windows will NOT update the existing release 1.0, or you must un-install before re-applying a re-build of same version my_pkg-1.0.exe .如果您不每次都升级--app-version ,Windows 将不会更新现有的 1.0 版本,或者您必须在重新应用相同版本的重新构建之前my_pkg-1.0.exe It just runs and stops without warning you.它只是在没有警告你的情况下运行和停止。

See this post on how to set app-ver automatically.请参阅这篇文章,了解如何自动设置 app-ver。

I got it to work.我让它工作。 @DuncG was very helpful with answering my question, I had a bunch of extra files in the directory where the jar file was. @DuncG 对回答我的问题非常有帮助,我在 jar 文件所在的目录中有一堆额外的文件。 so I just created a new directory and only put NtbnsProj.jar in it: I then ran the following command: jpackage --name Test --input. --main-jar NtbnsProj.jar所以我刚刚创建了一个新目录,只将 NtbnsProj.jar 放入其中:然后我运行以下命令: jpackage --name Test --input. --main-jar NtbnsProj.jar jpackage --name Test --input. --main-jar NtbnsProj.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM