如何使 java 程序可安装?
我的 Eclipse 工作区中保存了一个应用程序。
我可以将其导出为 .jar
文件。
这是针对“现实世界”的应用程序。
如何导出为“.exe”文件或“.dmg”以便可以安装在另一台计算机上?
由于 Java 是平台无关的,我认为这是针对特定操作系统导出的问题。
我用谷歌搜索了很多,读了很多不同的故事,所以我更喜欢有经验的人的答案。
How can I make a java program installable?
I have an application saved in my Eclipse workspace.
I can export it as a .jar
file.
This is for a "real-world" application.
How can I export to be a ".exe" file or ".dmg" so that it can be installed on another machine?
Since Java is platform-independent I think it is a matter of exporting for a specific operating system.
I've googled a lot and read so many different stories, so I would prefer an answer from an experienced person.
发布评论
评论(6)
我想您所寻找的不仅是使程序可运行(如 lobster1234 建议的那样),而且是使其实际可安装。我们最近使用了 IzPack。它实际上看起来不错。
还有一些关于细节的不错的教程此处和此处
I guess what you are looking for is not only to make the program runnable (as lobster1234 proposed) but to make it actually installable. We have recently used IzPack. It actually looks nice.
There are also some decent tutorials on the details here and here
Jar 文件通常是最佳选择,因为 JVM 可以通过 java -jar 命令直接执行打包的文件。如果您想从网站等分发应用程序,Java WebStart 是很好的选择。但是,某些操作系统没有安装该“功能”,即使 JVM 在那里也是如此。另一个解决方案是至少有 3 个脚本来启动您的应用程序(Windows 的批处理、Linux 的 shell 脚本以及 Mac 需要的任何内容 - 抱歉,没有 Mac - )。
不要创建本机可执行文件(即 Windows 的 exe),它们是多余的,因为您已经为此拥有了 JVM。
Jar files are usually the way to go, since the JVM can directly execute the packaged files through the
java -jar <jarfile>
command. Java WebStart is good if you want to distribute your app from a web site, etc. However, some OS don't have that "feature" installed, even if the JVM is there. Another solution is to have at least 3 scripts to launch your app (batch for Windows, shell script for Linux, and whatever Mac needs -- sorry, don't have a Mac -- ).Don't create native executable files (i.e. exe for Windows), they are redundant since you already have a JVM for that.
我在这里冒着一场口水战的风险,但我愿意:)
除非您所在的平台已知存在 JRE(例如 OS X),否则这会给您和/或最终用户带来麻烦。问题是 Java 应用程序根本不是独立的,而是依赖于一个庞大的框架。
JRE、Java Web Start 或任何您使用的东西都必须放在目标系统上。另外你还必须有某种启动器。它可以是像运行java、提供类路径等的脚本一样简单的东西。如果java“编译”为.exe或其他东西,则不需要这,但这就是它的工作原理。
这是我不再将 Java 部署到最终用户计算机的原因之一。只是很麻烦而已。我曾经参与过一个项目,我们实际上嵌入了由安装程序部署的整个私有 jre。它并不漂亮,但它完成了工作。
I'm risking a flamewar here but I'm game :)
Unless you're on a platform where the JRE is already known to exist (ex. OS X) it's going to be a hassle for you and/or end users. The problem is java apps are simply not standalone and depend on a massive framework.
The JRE, Java Web Start, or whatever you use has to be put on the target system. Also you have to have a launcher of some sort. It could be something as simple as a script which runs java, supplies the classpath, etc. This wouldn't be needed if java "compiled" to an .exe or something but that's just how it works.
This is one of the reasons I've turned off on deploying Java to end-user machines. It's just a lot of trouble. I once worked on a project where we actually embedded an entire private jre that got deployed by the installer. It wasn't pretty but it got the job done.
从 Java 8 开始,jdk 现在能够为 Windows、OSX 和 Linux 生成自己的可安装文件。但是,在 Windows 上,它取决于 Inno Setup 5 或更高版本或者 WiX 3.0 或更高版本。
https://docs.oracle .com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html#A1324980
As of Java 8, jdk is now capable of generating it's own Installables for Windows, OSX, and Linux. However, on Windows it depends on either Inno Setup 5 or later or WiX 3.0 or later.
https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html#A1324980
伙计们已经给了你们很多选择,所以我不想再提了。这里缺少的唯一选项是当您确实需要安装程序时,这意味着执行一些逻辑,修改(或至少读取)系统配置,创建桌面快捷方式,复制许多文件,配置第三方产品(可能是已安装)等。
在这种情况下,您可以使用 InstallAnywere、EzPack 或类似的解决方案(请参阅 http://java-source.net/open-source/installer-generators)
例如,如果您的项目相对简单,我会推荐您 AntInstaller。
顺便说一句,如果您担心您的客户可能没有在他的机器上安装 JRE,您可以使用 Launch4J 打包您的代码(或者更好的加载程序),该 Launch4J 从您的 java 代码生成可执行文件。
Guys already gave you a lot of options so I do not want to mention them again. The only option that is missing here is a case when you really need to install your program, meaning execute some logic, modify (or at least read) system configuration, create desktop shortcuts, copy many files, configure third party products (that are probably already installed) etc.
In this case you can use InstallAnywere, EzPack or similar solutions (see http://java-source.net/open-source/installer-generators)
For example if your project is relatively simple I'd recommend you AntInstaller.
BTW if you afraid that your customer probably does not have JRE installed on his machine you can package your code (or better a loader) using Launch4J that generates executable from your java code.
您可以使用Java WebStart,或将程序打包为可执行jar文件。
You can use Java WebStart, or package the program as an executable jar file.