为 Windows/Linux 桌面打包 Java 应用程序
我正在用 Java 编写一个桌面应用程序,使用 Eclipse SWT 库进行 GUI 渲染。 我认为 SWT 帮助 Java 克服了桌面上接受的最大障碍:即为 Java 应用程序提供一致的、响应式的界面,该界面看起来像属于桌面上任何其他应用程序。 然而,我觉得打包应用程序仍然是一个问题。
OS X 本身提供了一种简单的机制,用于将 Java 应用程序包装在本机应用程序包中,但是为 Windows/Linux 生成不需要用户运行难看的批处理文件或单击 .jar 的应用程序仍然很麻烦。 在 Linux 上这可能不是一个问题,因为用户可能更精通技术,但在 Windows 上我希望有一个常规的 .exe 供他/她运行。
有人使用过任何 Java .exe 生成工具吗? 我尝试过 JSmooth,但遇到了各种问题。 在我破解 Visual Studio 并推出自己的解决方案之前,是否有更好的解决方案?
编辑:我也许应该提到,我无法在商业解决方案上花费很多钱。
I am writing an application in Java for the desktop using the Eclipse SWT library for GUI rendering. I think SWT helps Java get over the biggest hurdle for acceptance on the desktop: namely providing a Java application with a consistent, responsive interface that looks like that belonging to any other app on your desktop. However, I feel that packaging an application is still an issue.
OS X natively provides an easy mechanism for wrapping Java apps in native application bundles, but producing an app for Windows/Linux that doesn't require the user to run an ugly batch file or click on a .jar is still a hassle. Possibly that's not such an issue on Linux, where the user is likely to be a little more tech-savvy, but on Windows I'd like to have a regular .exe for him/her to run.
Has anyone had any experience with any of the .exe generation tools for Java that are out there? I've tried JSmooth but had various issues with it. Is there a better solution before I crack out Visual Studio and roll my own?
Edit: I should perhaps mention that I am unable to spend a lot of money on a commercial solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(18)
我也经历过同样的事情,发现所有的免费选项都不是很好。 看来你要自己写了。 我有兴趣看看是否有人有有效的免费/廉价选项
I went through the same and found that all of the free options weren't very good. Looks like you'll be writing your own. I'd be interested to see if someone has a free/cheap option that works
我正在考虑的另一个选择是:Eclipse 附带了自己的启动器的源代码,而不是从头开始编写本机启动器,这也许可以重新用于我的应用程序。
遗憾的是 Sun 从未在 JDK 中包含类似的内容。
Another option I was considering: rather than writing a native launcher from scratch, Eclipse comes with the source code for its own launcher, and this could perhaps be repurposed for my app.
It's a shame that Sun never included anything similar in the JDK.
又投了Launch4J一票,今天早上刚刚写了一个ant任务来与我的一个项目集成。 看起来效果真的很好
Another vote for Launch4J, just wrote an ant task this morning to integrate with one of my projects. Seems to work really well
我过去使用过 JSmooth,并且仍然很幸运。 UI 非常有问题,但我只用它来构建配置文件一次,然后我从 Ant 构建。
您在使用 JSmooth 时遇到什么问题?
I have used JSmooth in the past, and still have luck with it. The UI is pretty buggy, but I only use that for building the config file once, and then I build from Ant after that.
What issues are you having with JSmooth?
JSMooth 在生产环境中非常适合我们,我首先使用 one-jar(eclipse 的 fat jar 插件)生成一个 jar,然后用 JSmooth 包装它。
(请注意,我想要单个文件的免安装分发,如果需要,它可以提示安装 JRE)。
它运行得非常好,我以为没有人使用它:)
JSMooth has worked very well for us in a production environment, where I first generated a single jar using one-jar (fat jar plugin to eclipse) and then wrapped it with JSmooth.
(Please note that I wanted a no-install distribution of a single file, which could promt for installing the JRE if needed).
It has worked so well that I thought nobody was using it :)
您可能想尝试我们的工具,BitRock InstallBuilder。 虽然它是一个本机应用程序,但我们的许多客户使用它来打包桌面 Java 应用程序。 如果您捆绑 JRE 并创建启动器等,用户甚至不需要知道他们正在安装 Java 应用程序。 它是跨平台的,因此您可以为 Windows 和 Mac(以及 Linux、Solaris 等)生成安装程序。就像另一篇文章中提到的 install4j 工具一样,它是一个商业工具,但是我们有免费许可证对于开源项目以及微型独立软件开发商/小型企业等的特别折扣,请给我们发送电子邮件。 还要强调的是,这是一个安装程序工具,因此如果您只寻找单个文件可执行文件,它无法满足您的需求。
You may want to try our tool, BitRock InstallBuilder. Although it is a native application, a lot of our customers use it to package desktop Java applications. If you bundle the JRE and create launcher, etc. the user does not even need to know they are installing a Java application. It is cross platform, so you can generate installers for both Windows and Mac (and Linux, Solaris, etc.) Like install4j tool mentioned in another post, it is a commercial tool, but we have free licenses for open source projects and special discounts for microISVs / small business, etc. just drop us an email. Also wanted to emphasize that this is an installer tool, so it will not address your needs if you are looking only for a single file executable.
在我的公司,我们在 Windows 发行版中使用 launch4J 和 NSIS,在 Debian 发行版中使用 jdeb,在通用操作系统中使用 Java Web Start。 这工作得很好。
In my company we use launch4J and NSIS for the windows distribution, and jdeb for the Debian distribution, and Java Web Start for the general operating system. This works quite fine.
请尝试 InstallJammer。这是我用过的最好的一个。 免费且功能强大。足以满足个人和商业用途。
Please try InstallJammer.The best one I have used ever. Free and powerful.And sufficient for personal and commercial use.
您考虑过高级安装程序吗?
我已经多次使用过它,特别是在 Windows 和 Mac 上。 无需脚本或 Ant。 所有图形用户界面。 非常简单易懂。 不是免费的,但值得每一分钱。
- 以管理员身份启动
- 文件关联
- 自定义安装主题+内置主题
- 包含 JRE 的软件包
- 安装位置
- 本机启动画面实施
- 您可以事件创建服务和安装事件
- 先决条件
- JRE 最低版本和最高版本
还有更多。 别误解了,我和这些家伙没有任何联系……他们的应用程序非常棒。
Have you considered Advanced Installer?
I have used it severally especially for Windows and Mac. No scripting or Ant required. All GUI. Very simple and understandable. Ain't free but worth every penny.
- Lauch as Administrator
- File Association
- Custom Install Themes + In built Themes
- Package with JRE
- Install location
- Native Splash screen implementation
- You can event create services and installation events
- Prerequisites
- JRE minimum version and maximum version
And a lot more. And don't get it twisted, i have no connections with the dudes...their App is just awesome.
考虑将您的应用程序转换为 Eclipse RCP。 它是用 SWT 编写的,Eclipse IDE 包含为所有主要平台生成可执行文件的打包工具。 对于 Windows,它可以生成包含代码的 zip 或文件夹。 对于常见的安装体验,我使用 NSIS。 Eclipse 上实际上有一个 包生成器 项目,用于为 Eclipse 支持的所有平台创建通用安装程序。
Consider converting your application to Eclipse RCP. It is written in SWT, and the Eclipse IDE contains packaging tools that generate executables for all major platforms. For windows, it can generate a zip or a folder containing your code. For a common installation experience, I'd using NSIS. There is actually a packages generator project at eclipse to create common installers for all platforms eclipse supports.
您是否考虑过 Java Web Start? 这里是专门用于使用 Java Web 部署 SWT 应用程序的教程开始。
Have you thought about Java Web Start? Here is a tutorial specifically for deploying an SWT application with Java Web Start.
安装4J。 不是免费的,但值得。 尝试一下审判
Install4J. Not free, but worth it. Give the trial a shot
您现在可以通过 Netbeans 执行此操作! 这真的很简单并且运行完美。 请查看 Netbeans 网站上的此教程。
You can now do this through Netbeans! It's really easy and works perfectly. Check out this tutorial on the Netbeans website.
我使用免费的 Launch4J 为 Windows 上的 Java 程序创建自定义启动器。 结合免费的 NSIS 安装程序,您可以为 Windows 用户构建一个不错的软件包。
编辑: 没有看到您使用 SWT。 不知道它是否也适用于 SWT,因为我在我的应用程序中只使用了 Swing。
I've used the free Launch4J to create a custom launcher for my Java programs on Windows. Combined with the free NSIS Installer you can build a nice package for your Windows users.
Edit: Did not see that you use SWT. Don't know if it works with SWT as well, because I used only Swing in my apps.
您是否考虑过用 C/C++ 编写一个仅调用
CreateProcess 的小程序
使用 jar(或类)文件启动 java VM?您可以获取 Visual C++ Express 并轻松地将启动程序组合在一起。 这也使得添加友好的图标变得容易。
Have you considered writing a small program in C/C++ that just calls
CreateProcess
to start up the java VM with the jar (or class) file?You could get Visual C++ Express and put together the startup program pretty easily. This would make it easy to add a friendly icon as well.
在我的公司,我们使用 Launch4J 创建 exe 文件,并使用 NSIS 使用 SWT 应用程序创建安装程序。
我们已在多个商业应用中使用它多年,并且两者运行良好。
In my company we use Launch4J to create the exe file, and NSIS to create the installer, with SWT applications.
We have used it for years in several commercial applications and the pair works fine.
也许您应该看看 IzPack。 几年前我创建了一个非常好的安装程序,我敢打赌他们仍在改进它。 它允许安装文档、二进制文件和可单击的链接来启动应用程序IIRC。
Maybe you should take a look at IzPack. I created a very nice installer some years ago and I'd bet that they are still improving it. It allows the installation of docs, binaries and a clickable link to start the application IIRC.
为了跟进 pauxu 的答案,我在我的一个项目中使用 launch4j 和 NSIS,并认为展示我如何使用它们会很有帮助。 这就是我为 Windows 所做的事情。 顺便说一句,我正在为 Mac 创建 .app 和 .dmg,但还没有弄清楚要为 Linux 做什么。
launch4j 和 NSIS 的项目副本
在我的项目中,我有一个“vendor”目录,在它下面有一个“launch4j”和“nsis”目录。 每个内都有每个应用程序的安装副本。 我发现在项目本地拥有一个副本比强迫其他人安装这两个产品并设置某种环境变量来指向每个产品更容易。
脚本文件
我的项目中还有一个“脚本”目录,其中包含项目的各种配置/脚本文件。 首先是 launch4j.xml 文件:
然后是 NSIS 脚本 rpgam-setup.nsis。 它可以使用 VERSION 参数来帮助命名文件。
Ant 集成
我的 Ant 构建文件 (build.xml) 中有一些目标来处理上述问题。 首先,我告诉 Ant 导入 launch4j 的 Ant 任务:
然后,我有一个用于创建包装器可执行文件的简单目标:
以及用于制作安装程序的另一个目标:
顶部部分仅将安装程序所需的文件复制到临时位置,第二部分half 执行使用其全部来制作安装程序的脚本。
To follow up on pauxu's answer, I'm using launch4j and NSIS on a project of mine and thought it would be helpful to show just how I'm using them. Here's what I'm doing for Windows. BTW, I'm creating .app and .dmg for Mac, but haven't figured out what to do for Linux yet.
Project Copies of launch4j and NSIS
In my project I have a "vendor" directory and underneath it I have a directory for "launch4j" and "nsis". Within each is a copy of the install for each application. I find it easier to have a copy local to the project rather than forcing others to install both products and set up some kind of environment variable to point to each.
Script Files
I also have a "scripts" directory in my project that holds various configuration/script files for my project. First there is the launch4j.xml file:
And then there's the NSIS script rpgam-setup.nsis. It can take a VERSION argument to help name the file.
Ant Integration
I have some targets in my Ant buildfile (build.xml) to handle the above. First I tel Ant to import launch4j's Ant tasks:
I then have a simple target for creating the wrapper executable:
And another target for making the installer:
The top portion of that just copies the necessary files for the installer to a temporary location and the second half executes the script that uses all of it to make the installer.