分发 Java 应用程序的最佳方式是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/80105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:02:10  来源:igfitidea点击:

What's the best way to distribute Java applications?

javainstallerjarsoftware-distribution

提问by Laplie Anderson

Java is one of my programming languages of choice. I always run into the problem though of distributing my application to end-users.

Java 是我选择的编程语言之一。尽管将我的应用程序分发给最终用户,但我总是遇到问题。

Giving a user a JAR is not always as user friendly as I would like and using Java WebStart requires that I maintain a web server.

给用户一个 JAR 并不总是像我希望的那样用户友好,使用 Java WebStart 需要我维护一个 Web 服务器。

What's the best way to distribute a Java application? What if the Java application needs to install artifacts to the user's computer? Are there any good Java installation/packaging systems out there?

分发 Java 应用程序的最佳方式是什么?如果 Java 应用程序需要将工件安装到用户的计算机上怎么办?有没有好的 Java 安装/打包系统?

采纳答案by Noel Grandin

There are a variety of solutions, depending on your distribution requirements.

根据您的分发要求,有多种解决方案。

  1. Just use a jar. This assumes that the user has the the correct java version installed, otherwise the user will get "class-file format version" exceptions. This is fine for internal distribution inside a company.

  2. Use launch4j and an installer like NSIS. This gives you a lot more control, although the user can still do stupid stuff like un-installing the java runtime. This is probably the most popular approach, and what I currently use.

  3. Use Webstart. This also assumes that the user has the correct java version installed, but it's a lot easier to get going. My experience is that this is fine for tightly controlled intranet environments, but becomes a pain with larger deployments because it has some many weird failures. It may get better with the new plug-in technology in Java 1.7.

  4. Use a native-code compiler like Excelsior JET and distribute as a executable, or wrap it up in an installer. Expensive, and it generally ties you to a slightly older version of java, and there is some pain with dynamic class-loading, but its very effective for large-scale deployment where you need to minimise your support hassles.

  1. 只需使用一个罐子。这假设用户安装了正确的 java 版本,否则用户将获得“类文件格式版本”异常。这适用于公司内部的内部分发。

  2. 使用 launch4j 和 NSIS 之类的安装程序。这给了你更多的控制,尽管用户仍然可以做一些愚蠢的事情,比如卸载 java 运行时。这可能是最流行的方法,也是我目前使用的方法。

  3. 使用网络启动。这也假设用户安装了正确的 java 版本,但它更容易上手。我的经验是,这对于严格控制的 Intranet 环境来说很好,但在较大的部署中会变得很痛苦,因为它有很多奇怪的故障。使用 Java 1.7 中的新插件技术可能会变得更好。

  4. 使用 Excelsior JET 等本机代码编译器并作为可执行文件分发,或将其打包在安装程序中。价格昂贵,并且通常会将您绑定到稍旧版本的 java,并且动态类加载会带来一些痛苦,但是对于需要最大程度减少支持麻烦的大规模部署而言,它非常有效。

回答by jjnguy

For simple Java apps I like to use Jar's. It is very simple to distribute one file that a user can just click on (Windows), or

对于简单的 Java 应用程序,我喜欢使用 Jar 的。分发一个用户只需单击的文件(Windows)非常简单,或者

java -jar jarname.jar

IMHO, jar is the way to go when simplicity is a main requirement.

恕我直言,当简单是主要要求时,jar 是要走的路。

回答by zurk

executable files are best but they are platform limited i.e. use gcj : http://gcc.gnu.org/java/for linux to produce executables and use launch4j : http://launch4j.sourceforge.net/to produce windows executables. To package on linux you can use any rpm or deb packager. For win32 try http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System

可执行文件是最好的,但它们受平台限制,即使用 gcj : http://gcc.gnu.org/java/for linux 生成可执行文件并使用 launch4j : http://launch4j.sourceforge.net/生成 Windows 可执行文件。要在 linux 上打包,您可以使用任何 rpm 或 deb 打包程序。对于 win32,请尝试http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System

回答by qualidafial

The best answer depends on the platform. For deployment on Windows, I have had good results using a combination of one-jarand launch4j. It did take a little while to set up my build environment properly (ant scripts, mostly) but now it's fairly painless.

最佳答案取决于平台。对于在 Windows 上的部署,我使用one-jarlaunch4j的组合取得了不错的结果。正确设置我的构建环境确实需要一些时间(主要是 ant 脚本),但现在它相当轻松。

回答by Ry4an Brase

If it's a real GUI-having end user application you should ignore the lanaguage in which you wrote the program (Java) and use a native installer for each of your chosen platforms. Mac folks want a .dmg and on windows a .msi or a .exe installer is the way to go. On Windows I prefer NSIS from NullSoft only because it's less objectionable than InstallShield or InstallAnywhere. On OSX you can count on the JVM already being there. On Windows you'll need to check and install it for them if necessary. Linux people won't run Java GUI applications, and the few that will, know what to do with an executable .jar.

如果它是真正具有 GUI 的最终用户应用程序,您应该忽略您编写程序所用的语言 (Java),并为您选择的每个平台使用本机安装程序。Mac 用户需要 .dmg,而在 Windows 上则需要 .msi 或 .exe 安装程序。在 Windows 上,我更喜欢 NullSoft 的 NSIS,因为它不像 InstallShield 或 InstallAnywhere 那样令人反感。在 OSX 上,您可以指望 JVM 已经存在。在 Windows 上,如有必要,您需要为他们检查和安装它。Linux 人不会运行 Java GUI 应用程序,少数人会知道如何处理可执行文件 .jar。

回答by Petr Macek

Well from my point of view the superior distribution mechanism is to use something like ClickOnce, or WebStarttechnology. You just deploy the version to the server and it gets automatically to the clients when the version is released. Also the Eclipse RCP platform contains UpdateManager that does what WebStart do, but also much more.

在我看来,高级分发机制是使用ClickOnceWebStart技术之类的东西。您只需将版本部署到服务器,当版本发布时它会自动发送到客户端。此外,Eclipse RCP 平台包含 UpdateManager,它可以执行 WebStart 的功能,但还有更多功能。

Since I am using Maven2 for building, the deployment is just a piece of cake: copy the built jar to the location on the server, update the jnlp file if needed and you are done.

由于我使用 Maven2 进行构建,因此部署只是小菜一碟:将构建的 jar 复制到服务器上的位置,如果需要,更新 jnlp 文件即可完成。

回答by rustyshelf

advanced installermakes it easy to package java apps as windows executables, and it's quite flexible in the way you can set it up. I've found that for distributing java applications to windows clients, this is the easiest way to go.

高级安装程序可以轻松地将 Java 应用程序打包为 Windows 可执行文件,并且在设置方式上非常灵活。我发现将 Java 应用程序分发给 Windows 客户端,这是最简单的方法。

回答by Mario Ortegón

I develop eclipse RCP applications. Normally to start an eclipse application an executable launcher is included. I include the java virtual machine inside the application folder in a /jre sub directory to ensure that the right java version will be used.

我开发 Eclipse RCP 应用程序。通常要启动一个 eclipse 应用程序,一个可执行的启动器是包括在内的。我将 java 虚拟机包含在 /jre 子目录中的应用程序文件夹中,以确保将使用正确的 java 版本。

Then we package with Inno Setup for installation on the user's machine.

然后我们用 Inno Setup 打包安装在用户的机器上。

回答by Rejeev Divakaran

I would zip the jar file along with other dependent jars, configuration files and documentation along with a run.bat/run.sh. End user should be able unzip it to any location and edit the run.bat if required (It should run without editing in most of the cases). An installer may be useful if you want to create entries in start menu, desktop, system tray etc.

我会将 jar 文件与其他依赖 jar、配置文件和文档以及 run.bat/run.sh 一起压缩。最终用户应该能够将其解压缩到任何位置并在需要时编辑 run.bat(在大多数情况下它应该在不编辑的情况下运行)。如果您想在开始菜单、桌面、系统托盘等中创建条目,安装程序可能会很有用。

As a user I prefer unzip and run kind of installation (no start menu entries please). However People outside IT industry may have different preferences. So if the application is largely targeted for developers zip-run.bat route and applications for general public may be installed using a installer.

作为用户,我更喜欢解压缩并运行某种安装(请不要进入开始菜单)。然而,IT 行业以外的人可能有不同的偏好。因此,如果应用程序主要针对开发人员 zip-run.bat 路由,则可以使用安装程序安装面向大众的应用程序。

回答by coobird

Although I haven't used NSIS(Nullsoft Scriptable Installer System) myself, there are install scripts that will check whether or not the required JRE is installed on the target system.

虽然我自己没有使用过NSIS(Nullsoft Scriptable Installer System),但有安装脚本会检查目标系统上是否安装了所需的 JRE。

Many sample scripts are available from the Code Examplesand Real World Installerspages, such as:

许多示例脚本可从代码示例真实世界安装程序页面获得,例如:

(Please note that I haven't actually used any of the scripts, so please don't take it as an endorsement.)

(请注意,我实际上并没有使用任何脚本,因此请不要将其视为认可。)