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

时间:2022-09-06 00:25:32

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安装/打包系统吗?

16 个解决方案

#1


84  

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.

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

  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.

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

  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.

    使用Webstart。这也假定用户已经安装了正确的java版本,但是更容易实现。我的经验是,这对于严格控制的内部网环境来说是可以的,但是对于更大的部署来说,这是一种痛苦,因为它有许多奇怪的失败。使用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.

    使用类似Excelsior JET的原生代码编译器并将其作为可执行文件分发,或者将其打包到安装程序中。代价高昂,并且它通常将您与稍微旧一点的java版本联系在一起,并且动态类加载会带来一些痛苦,但是对于需要将支持问题最小化的大规模部署来说,它非常有效。

#2


9  

Convert Java to EXE - Why, When, When Not and How

将Java转换为EXE——为什么、何时、何时和如何

#3


5  

advanced installer makes 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客户机,这是最简单的方法。

#4


4  

JSmooth is a simple program that takes your jar and wraps it up in a standard windows executable file. It comes with a simple GUI that allows you to configure the required JVM, bundle it with the application or provide an option to download it if it's not already installed. You can send the exe file as is or zip it with possible dependencies (or let the program download the extra dependencies from the net on startup). It's also free, as in beer and speech, which may (or may not) be a good thing.

JSmooth是一个简单的程序,它接收你的jar并将它封装在一个标准的windows可执行文件中。它附带了一个简单的GUI,允许您配置所需的JVM,将其与应用程序捆绑在一起,或者提供一个在尚未安装时下载的选项。您可以按原样发送exe文件,或者使用可能的依赖项对其进行压缩(或者让程序在启动时从网络上下载额外的依赖项)。它也是免费的,就像啤酒和演讲一样,这可能(也可能不是)是件好事。

#5


4  

It depends on how sophisticated your target users are. In most cases you want to isolate them from the fact that you are running a Java-based app. Give them with a native installer that does the right thing (create start menu entries, launchers, register with add/remove programs, etc.) and already bundles a Java runtime (so the user does not need to know or care about it). I would like to suggest our cross platform installation tool, BitRock InstallBuilder. Although it is not Java-based, it is commonly used to package Java applications. It can be easily integrated with Ant and you can build Windows installers from Unix/Linux/Mac and the other way around. Because the generated installers are native, they do not require a self-extraction step or a JRE to be already present in the target system, which means smaller installers and saves you some headaches. I also would like to mention we have free licenses for open source projects

这取决于你的目标用户有多复杂。在大多数情况下,你想要把它们与您正在运行一个基于Java的应用程序。这一事实给他们的本地安装程序做正确的事(创建开始菜单条目,发射器,注册添加/删除程序,等等),已经捆绑了一个Java运行时(所以用户不需要知道或关心它)。我想推荐我们的跨平台安装工具BitRock InstallBuilder。虽然它不是基于Java的,但通常用于打包Java应用程序。它可以很容易地与Ant集成,您可以从Unix/Linux/Mac以及其他方式构建Windows安装程序。因为生成的安装程序是本地的,所以它们不需要在目标系统中已经存在一个自提取步骤或JRE,这意味着更小的安装程序,并为您省去了一些麻烦。我还想提一下,我们有开放源码项目的免费许可证。

#6


3  

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/用于linux来生成可执行文件,并使用launch4j: http://launch4j.sourceforge.net/来生成windows可执行文件。要在linux上打包,可以使用任何rpm或deb打包程序。win32试试http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System

#7


3  

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)的lanaguage,并为每个选择的平台使用本地安装程序。Mac用户想要的是.dmg,而在windows a .msi或.exe安装程序上则需要。在Windows上,我更喜欢NSIS而不是NullSoft,因为它比InstallShield或InstallAnywhere更不令人讨厌。在OSX上,您可以依赖已经存在的JVM。在Windows上,如果需要,您需要检查并安装它。Linux用户不会运行Java GUI应用程序,少数人知道如何使用可执行的.jar。

#8


3  

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可脚本安装程序系统),但是有一些安装脚本将检查所需的JRE是否安装在目标系统上。

Many sample scripts are available from the Code Examples and Real World Installers pages, such as:

许多示例脚本可以从代码示例和实际安装程序页面获得,例如:

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

(请注意,我实际上没有使用任何脚本,所以请不要把它当作背书。)

#9


2  

I needed a way to package my project and its dependencies into a single jar file.

我需要一种方法将我的项目和它的依赖项打包到一个jar文件中。

I found what I needed using the Maven2 Assembly plugin: Maven2 Assembly plugin

我使用Maven2程序集插件找到了我需要的东西:Maven2程序集插件

This appears to duplicate the functionality of one-jar, but requires no additional configuration to get it going.

这似乎复制了one-jar的功能,但是不需要额外的配置就可以运行它。

#10


1  

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就是最好的选择。

#11


1  

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设置。

#12


1  

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安装/打包系统吗?

In my experience (from evaluating a number of options), install4j is a good solution. It creates native installers for any platform, and is specifically geared towards installing Java apps. For details, see "Features" on its website.

根据我的经验(从评估多个选项),install4j是一个很好的解决方案。它为任何平台创建本地安装程序,并专门用于安装Java应用程序。有关详细信息,请参阅其网站上的“特性”。

install4j is a commercial tool, though. Especially if your needs are relatively simple (just distribute an application and install some artifacts), many other good options exist, including free ones (like izPack or the already mentioned Lauch4j). But you asked for the best way, and to my current knowledge install4j is the one, especially for distributing larger or more complicated Java (EE) apps.

不过,install4j是一个商业工具。特别是如果您的需求相对简单(只需分发应用程序并安装一些构件),则存在许多其他的好选项,包括免费的选项(如izPack或前面提到的Lauch4j)。但是你问的是最好的方法,我目前的知识是安装4j,特别是用于分发更大或更复杂的Java (EE)应用程序。

#13


0  

The best answer depends on the platform. For deployment on Windows, I have had good results using a combination of one-jar and 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-jar和launch4j的组合,取得了很好的效果。正确地设置我的构建环境(大部分是ant脚本)确实需要一些时间,但现在它相当轻松。

#14


0  

Well from my point of view the superior distribution mechanism is to use something like ClickOnce, or WebStart technology. 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.

在我看来,更好的分配机制是使用点击一次,或WebStart技术。您只需将版本部署到服务器,它将在版本发布时自动地到达客户端。此外,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文件,这样就完成了。

#15


0  

installanywhere is good but expensive one - i have not found (as) good free one

安装任何地方是好的,但昂贵的一个-我没有找到(作为)好的免费一个

#16


-2  

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。最终用户应该能够解压缩到任何位置并编辑运行。如果需要,可以使用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路由和普通公众应用程序。

#1


84  

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.

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

  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.

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

  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.

    使用Webstart。这也假定用户已经安装了正确的java版本,但是更容易实现。我的经验是,这对于严格控制的内部网环境来说是可以的,但是对于更大的部署来说,这是一种痛苦,因为它有许多奇怪的失败。使用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.

    使用类似Excelsior JET的原生代码编译器并将其作为可执行文件分发,或者将其打包到安装程序中。代价高昂,并且它通常将您与稍微旧一点的java版本联系在一起,并且动态类加载会带来一些痛苦,但是对于需要将支持问题最小化的大规模部署来说,它非常有效。

#2


9  

Convert Java to EXE - Why, When, When Not and How

将Java转换为EXE——为什么、何时、何时和如何

#3


5  

advanced installer makes 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客户机,这是最简单的方法。

#4


4  

JSmooth is a simple program that takes your jar and wraps it up in a standard windows executable file. It comes with a simple GUI that allows you to configure the required JVM, bundle it with the application or provide an option to download it if it's not already installed. You can send the exe file as is or zip it with possible dependencies (or let the program download the extra dependencies from the net on startup). It's also free, as in beer and speech, which may (or may not) be a good thing.

JSmooth是一个简单的程序,它接收你的jar并将它封装在一个标准的windows可执行文件中。它附带了一个简单的GUI,允许您配置所需的JVM,将其与应用程序捆绑在一起,或者提供一个在尚未安装时下载的选项。您可以按原样发送exe文件,或者使用可能的依赖项对其进行压缩(或者让程序在启动时从网络上下载额外的依赖项)。它也是免费的,就像啤酒和演讲一样,这可能(也可能不是)是件好事。

#5


4  

It depends on how sophisticated your target users are. In most cases you want to isolate them from the fact that you are running a Java-based app. Give them with a native installer that does the right thing (create start menu entries, launchers, register with add/remove programs, etc.) and already bundles a Java runtime (so the user does not need to know or care about it). I would like to suggest our cross platform installation tool, BitRock InstallBuilder. Although it is not Java-based, it is commonly used to package Java applications. It can be easily integrated with Ant and you can build Windows installers from Unix/Linux/Mac and the other way around. Because the generated installers are native, they do not require a self-extraction step or a JRE to be already present in the target system, which means smaller installers and saves you some headaches. I also would like to mention we have free licenses for open source projects

这取决于你的目标用户有多复杂。在大多数情况下,你想要把它们与您正在运行一个基于Java的应用程序。这一事实给他们的本地安装程序做正确的事(创建开始菜单条目,发射器,注册添加/删除程序,等等),已经捆绑了一个Java运行时(所以用户不需要知道或关心它)。我想推荐我们的跨平台安装工具BitRock InstallBuilder。虽然它不是基于Java的,但通常用于打包Java应用程序。它可以很容易地与Ant集成,您可以从Unix/Linux/Mac以及其他方式构建Windows安装程序。因为生成的安装程序是本地的,所以它们不需要在目标系统中已经存在一个自提取步骤或JRE,这意味着更小的安装程序,并为您省去了一些麻烦。我还想提一下,我们有开放源码项目的免费许可证。

#6


3  

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/用于linux来生成可执行文件,并使用launch4j: http://launch4j.sourceforge.net/来生成windows可执行文件。要在linux上打包,可以使用任何rpm或deb打包程序。win32试试http://en.wikipedia.org/wiki/Nullsoft_Scriptable_Install_System

#7


3  

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)的lanaguage,并为每个选择的平台使用本地安装程序。Mac用户想要的是.dmg,而在windows a .msi或.exe安装程序上则需要。在Windows上,我更喜欢NSIS而不是NullSoft,因为它比InstallShield或InstallAnywhere更不令人讨厌。在OSX上,您可以依赖已经存在的JVM。在Windows上,如果需要,您需要检查并安装它。Linux用户不会运行Java GUI应用程序,少数人知道如何使用可执行的.jar。

#8


3  

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可脚本安装程序系统),但是有一些安装脚本将检查所需的JRE是否安装在目标系统上。

Many sample scripts are available from the Code Examples and Real World Installers pages, such as:

许多示例脚本可以从代码示例和实际安装程序页面获得,例如:

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

(请注意,我实际上没有使用任何脚本,所以请不要把它当作背书。)

#9


2  

I needed a way to package my project and its dependencies into a single jar file.

我需要一种方法将我的项目和它的依赖项打包到一个jar文件中。

I found what I needed using the Maven2 Assembly plugin: Maven2 Assembly plugin

我使用Maven2程序集插件找到了我需要的东西:Maven2程序集插件

This appears to duplicate the functionality of one-jar, but requires no additional configuration to get it going.

这似乎复制了one-jar的功能,但是不需要额外的配置就可以运行它。

#10


1  

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就是最好的选择。

#11


1  

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设置。

#12


1  

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安装/打包系统吗?

In my experience (from evaluating a number of options), install4j is a good solution. It creates native installers for any platform, and is specifically geared towards installing Java apps. For details, see "Features" on its website.

根据我的经验(从评估多个选项),install4j是一个很好的解决方案。它为任何平台创建本地安装程序,并专门用于安装Java应用程序。有关详细信息,请参阅其网站上的“特性”。

install4j is a commercial tool, though. Especially if your needs are relatively simple (just distribute an application and install some artifacts), many other good options exist, including free ones (like izPack or the already mentioned Lauch4j). But you asked for the best way, and to my current knowledge install4j is the one, especially for distributing larger or more complicated Java (EE) apps.

不过,install4j是一个商业工具。特别是如果您的需求相对简单(只需分发应用程序并安装一些构件),则存在许多其他的好选项,包括免费的选项(如izPack或前面提到的Lauch4j)。但是你问的是最好的方法,我目前的知识是安装4j,特别是用于分发更大或更复杂的Java (EE)应用程序。

#13


0  

The best answer depends on the platform. For deployment on Windows, I have had good results using a combination of one-jar and 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-jar和launch4j的组合,取得了很好的效果。正确地设置我的构建环境(大部分是ant脚本)确实需要一些时间,但现在它相当轻松。

#14


0  

Well from my point of view the superior distribution mechanism is to use something like ClickOnce, or WebStart technology. 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.

在我看来,更好的分配机制是使用点击一次,或WebStart技术。您只需将版本部署到服务器,它将在版本发布时自动地到达客户端。此外,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文件,这样就完成了。

#15


0  

installanywhere is good but expensive one - i have not found (as) good free one

安装任何地方是好的,但昂贵的一个-我没有找到(作为)好的免费一个

#16


-2  

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。最终用户应该能够解压缩到任何位置并编辑运行。如果需要,可以使用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路由和普通公众应用程序。