如何为 Java 应用程序创建安装程序?
这对我来说还有一段时间,但对于我的项目实施课程,我们必须创建一个程序然后分发它。我已经用 Java 编写了一个应用程序,根据我在上一课(项目设计)中制定的规范,我的应用程序需要独立于平台。
对于 Mac 和 Linux,用户只需从终端运行 jar 文件,但对于 Windows,我希望将应用程序安装到用户选择的路径(默认:C:\Program Files(x86)\NameOfApplication),创建桌面快捷方式(如果用户希望有一个),安装在开始菜单下(如果用户想要),然后也显示在添加\删除程序列表中。
有什么简单的方法可以做到这一点吗?
如果我决定为 mac 和 linux 创建安装程序会更困难吗?
提前致谢。
This is still awhile down the road for me but for my Project Implementation class we have to create a program and then distribute it. I have written an application in Java and from the specification I have made in the previous class (Project Design) my application will need to be platform-independent.
For mac and linux the user can just run the jar file from the terminal, but for windows I would like to have the Application installed to the path user chooses (default: C:\Program Files(x86)\NameOfApplication), Create a desktop shortcut (if the user wishes to have one), install under the start menu (if the user wants it to) and then also show up in the add\remove programs list.
Is there any easy way to do this?
Is it any harder if I did decided to create an installer for mac and linux?
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用 NSIS 创建安装程序,甚至对于 Java 应用程序也是如此。
您还可以考虑通过 Java Web Start 分发您的应用程序。
You can create an installer with NSIS, even for a Java application.
You might also consider distributing your application via Java Web Start.
有用于 java 的开源安装程序生成器。我以前从未使用过。 的一个很好的资源 链接
这是我推荐 使用Java Web Start。
它有几个优点。
它有一个主要缺点。
系统上不存在软件包
请查看此处和此处
There are opensource installer generators for java. I have never used one before. Here is a good resource of links
I recommend using Java Web Start.
It has several advantages.
It has one major disadvantage.
Package is not present on the system
Have a look here and here
Install4j 可以满足您的需求,但您必须为此付费。就我个人而言,我不知道有任何免费的替代品。您还可以为 Linux 和 Mac OS 制作安装程序。
Install4j does what you want, although you have to pay for it. Personally, I am not aware of any free alternatives. You can make installers for Linux and Mac OS as well.
您可以使用
Exe4J
,请参阅http://www.Exe4J. ej-technologies.com/products/exe4j/overview.htmlyou can use
Exe4J
, see http://www.ej-technologies.com/products/exe4j/overview.html您可以使用标准 JNLP 完成大部分工作:
http ://docs.oracle.com/javase/1.4.2/docs/guide/jws/developersguide/syntax.html
您创建一个 JNLP 文件,该文件从某个本地(或远程)位置并为其(您选择的)创建一个桌面图标。唯一的区别是实际的 JAR 将放置在 JDK 的 jar 缓存目录中(而不是您选择的目录中 - 我认为用户不会太在意)。
这样做的巨大优势是,如果您制作一个从远程位置安装 jar 的 JNLP,您可以将 jar 的新版本远程上传到该位置,并且当用户下次在本地访问该 jar 时,您的最新版本将是下载并放入本地缓存。
另外,我建议您使用智能“fat JAR”构建器,它将所有依赖项 jar 打包到可执行 jar 中。 Eclipse IDE 有一种方法以这种格式导出项目(并且还添加了必要的类加载器,以便在 fat jar 上一切正常)。
You can do most of that using standard JNLP:
http://docs.oracle.com/javase/1.4.2/docs/guide/jws/developersguide/syntax.html
You make a JNLP file that takes the executable JAR from some local (or remote) location and creates a Desktop icon for it (of your chosing). Only difference is that the actual JAR will be placed in the JDK's jar cache directory (not in a directory of your choice - I don't think the user would care much).
The huge advantage with this is that if you make a JNLP that installs the jar from a remote location, you can remotely upload a new version of the jar to that location, and when the user next accesses the jar locally, your latest version will be downloaded and placed into local cache.
Also I recommend you use a smart "fat JAR" builder, which packages all dependency jars inside the executable jar. Eclipse IDE has a way to export a project in this format (and also adds the necessary class-loader so that all works ok from on fat jar).
如果您的目标操作系统是 Windows,我强烈推荐高级安装程序。它非常非常容易使用,让您可以使用特定的目标 Java VM 和一堆有用的 Windows 功能创建自己的本机 Microsoft 安装程序 (.msi),即使是免费版本也是如此。请注意,您还可以将私有 jre 包含到包中。
http://www.advancedinstaller.com/top-freeware-features.html
如果您想要一个“一包部署到各处”的解决方案,那么 IzPack 就是您的最佳选择,它独立于平台、免费且开源。
http://izpack.org/
根据项目的复杂性,Java Web Start 可能是一个非常好的选择,它配置和维护非常简单,但它依赖于浏览器的 java 插件,相信我...大多数用户不喜欢在每次启动应用程序时收到有关证书和风险的警告。
If your target OS is windows I highly recommend Advanced Installer. It's very very easy to use and will let you create your own native microsoft installer (.msi) with specific target Java VM and a bunch of useful windows features, even in the free version. Note you can also include a private jre into the package.
http://www.advancedinstaller.com/top-freeware-features.html
If you want a "package one deploy everywhere" solution then IzPack is the way to go, platform independant, free and open source.
http://izpack.org/
Depending on the complexity of your project Java Web Start could be a very good option, it's very simple configure and maintain but it relies on the browser's java plugin and believe me... most users DON'T like being warned about certificates and risks everytime they launch an application.