简体   繁体   English

如何使用特定的JRE交付我的Java应用程序?

[英]How to deliver my Java application with a particular JRE?

Does somebody know how to pack a particular JRE together with a compiled Java application? 有人知道如何将特定的JRE与已编译的Java应用程序一起打包吗? I currently have an executable jar file and wish to put JRE 6 Update 31 in it. 我目前有一个可执行jar文件,并希望将JRE 6 Update 31放入其中。 So that the application uses the shipped JRE regardless of which JRE version the client has installed. 因此,无论客户端安装了哪个JRE版本,应用程序都会使用随附的JRE。 The solution should work platform independent. 解决方案应该独立于平台。

Any ideas? 有任何想法吗? Many thanks in advance! 提前谢谢了!

If you have the jre installed on a target platform, say Windows 64 bit, simply copy everything under the jre folder in your Java install and place it in your distro. 如果您在目标平台上安装了jre,比如说Windows 64位,只需复制Java安装中jre文件夹下的所有内容并将其放在发行版中。 Then create a batch file to point to your local jre instead of the system one. 然后创建一个批处理文件以指向您的本地jre而不是系统jre。

Here is what I do: 这是我做的:

  • my jar file is in a dist folder 我的jar文件在dist文件夹中
  • copy the system jre folder to dist\\jre-win-1.7.0_04 将系统jre文件夹复制到dist\\jre-win-1.7.0_04
  • create a .bat file with the following line in it jre-win-1.7.0_04\\bin\\java.exe -jar MyProgram.jar 创建一个.bat文件,其中包含以下行: jre-win-1.7.0_04\\bin\\java.exe -jar MyProgram.jar

..boom, done! ..boom,完成了! Double click the batch file and it runs your jar file with the local jre. 双击批处理文件,它使用本地jre运行您的jar文件。 To prove it to yourself, uninstall your system jre and double click the batch file. 要自己证明,请卸载系统jre并双击批处理文件。 Still works. 仍然有效。

You can do this on Linux or OS X in an analogous way. 您可以在Linux或OS X上以类似的方式执行此操作。

I would also like to point out that this is a fairly common practice and many Java distributions are done like this. 我还想指出,这是一种相当普遍的做法,许多Java发行版都是这样完成的。 So, don't say you can't or shouldn't. 所以,不要说你不能或不应该。

There are some caveats, however. 但是,有一些警告。 This does make your distro larger and platform dependent, in my example Windows x64. 在我的Windows x64示例中,这确实使您的发行版更大并且依赖于平台。 However, it's doable and manageable. 但是,它可行且易于管理。 There are a finite number of platforms supported for the jre and guess what... they're platform dependent too. jre支持有限数量的平台并猜测它们是什么......它们也依赖于平台。

On OSX, they are moving away from Apple providing Java to Oracle providing Java, this also means that Java will not be installed on a fresh install of OSX. 在OSX上,他们正在从提供Java的Apple转向提供Java的Oracle,这也意味着Java不会安装在全新的OSX上。 Oracle have provided a tool for packing up Java installations and they strongly recommend providing a jre as part of your installation. Oracle提供了一个用于打包Java安装的工具,他们强烈建议在安装过程中提供jre。 The advantage of this is that the customer will not have to install an additional package in order to run your application, and you can test your application against the correct Java runtime for you and ensure there are no incomptabilities before shipping. 这样做的好处是客户不必安装额外的软件包来运行您的应用程序,您可以针对正确的Java运行时测试您的应用程序,并确保在发货之前没有不兼容性。 The disavantage is that building the installer is slighty more complex and your download size is larger. 令人遗憾的是,构建安装程序会稍微复杂一些,而且下载量会更大。

Of course building installers get more complex if you want to provide your applications for Windows, Linux ectera and it would be alot simpler to just provide an executable jar but this is not the experience customers want. 当然,如果你想为Windows,Linux ectera提供你的应用程序,那么构建安装程序会变得更加复杂,只提供一个可执行的jar会更简单,但这不是客户想要的体验。 Customers do not expect to be able to download one application and run the same exe on windows, osx and linux. 客户不希望能够下载一个应用程序并在Windows,osx和linux上运行相同的exe。 They are happy 他们很高兴
to have different installers for each platform and also expect the installers to work in a different way. 为每个平台安装不同的安装程序,并期望安装程序以不同的方式工作。

This is how I do it: 我是这样做的:

OSX:Use AppBundler with bundled jre, put onto a Dmg with DMGCanvas. OSX:将AppBundler与捆绑的jre一起使用,放入带有DMGCanvas的Dmg。 The user simply drags the application to their /Application folder. 用户只需将应用程序拖动到其/ Application文件夹即可。

Windows:Use Izpack with bundled jre wrapped with launch4j so installer can be run as an exe. Windows:使用带有launch4j包装的捆绑jre的Izpack,因此安装程序可以作为exe运行。

Linux:Use Izpack without bundled jre, as user linux users like to be in control of exactly what on their machine, but specify minimum version of Java allowed. Linux:使用没有捆绑jre的Izpack,因为用户linux用户喜欢控制他们机器上的确切内容,但是指定允许的最小Java版本。 Ideally I should create packages for the main Linux Package Managers such as rpm but Ive decided this is not worth the effort at the moment as Linux users are a small percentage of my client base. 理想情况下,我应该为主要的Linux软件包管理器创建软件包,例如rpm,但我认为目前这不值得,因为Linux用户只占我的客户群的一小部分。

Most of the installation is automated using Maven and Ant, so its not a big effort to build these different installers. 大多数安装都是使用Maven和Ant自动完成的,因此构建这些不同的安装程序并不是一件大事。

We have the same situation with a commercial product in production. 我们对生产中的商业产品具有相同的情况。 We've downloaded both windows and linux JREs of a specific version, and packed it with the application using IzPack . 我们已经下载了特定版本的windows和linux JRE,并使用IzPack将其打包到应用程序中。

"Our" JRE must be installed if one wants to install the app, and the app is being run by that JRE regardless of the system installed JREs or JDKs. 如果想要安装应用程序,则必须安装“我们的”JRE,并且无论系统安装了JRE还是JDK,该应用程序都由该JRE运行。

The downside is: installer is to be made for Windows or Linux and it is ~ 50 MB in size. 缺点是:安装程序适用于Windows或Linux,大小约为50 MB。 The sizes of modules when unpacked are: 解压缩时模块的大小为:

  • app itself ~ 5MB app本身~5MB
  • libs ~10 MB libs~10 MB
  • JRE ~90 MB JRE~90 MB

If I'd want to make it more "platform independent" I'd have to pack both JREs which would be ~100 MB for the installer. 如果我想让它更“独立于平台”,我必须打包两个JRE,安装程序大约为100 MB。 And it would still be valid for only two types of platforms (see Cthulhu' answer). 它只对两种类型的平台有效(见Cthulhu的回答)。

Note that we make the mostly remote installation's via SSH and that using compression options increases the package time by a factor of ~10 at least (from minutes to dozens of minutes). 请注意,我们通过SSH进行大多数远程安装,并且使用压缩选项至少会将打包时间增加约10倍(从几分钟到几十分钟)。

A rather new solution, provided by Oracle, is here: Oracle提供的一个相当新的解决方案是:

Self contained packaging 独立包装

It reads: 它写道:

Self-contained application packages provide the following benefits: 独立的应用程序包提供以下好处:

  • Users install the application with an installer that is familiar to them and launch it in the usual way. 用户使用他们熟悉的安装程序安装应用程序,并以通常的方式启动它。

  • You control the version of the JRE used by the application. 您可以控制应用程序使用的JRE版本。

  • Applications can be deployed on fresh systems with no requirement for the JRE to be installed. 应用程序可以部署在新系统上,无需安装JRE。

But a drawback of this approach is: 但这种方法的缺点是:

Self-contained application packages can only be built using JDK 7 Update 6 or later. 只能使用JDK 7 Update 6或更高版本构建自包含的应用程序包。

看看您是否计划分发此捆绑包(您的应用程序+ JRE),然后有一个实用程序install4J ,它是一个功能强大的多平台Java安装程序构建器,可为Java应用程序生成本机安装程序和应用程序启动程序。

You can deploy it with java webstart which enables you to download a certain version of the jre if not present. 您可以使用java webstart部署它,这使您可以下载某个版本的jre(如果不存在)。 I don't know if downgrading is possible, however. 但是,我不知道是否可以降级。 Java must be installed already, too. Java也必须已经安装。

You need platform-specific launchers that use a JRE that is placed next to the JAR file. 您需要特定于平台的启动程序,这些启动程序使用放置在JAR文件旁边的JRE。 Of course you can do this with batch files and shell scripts, but there are more professional solutions that create native launchers, such as install4j . 当然,您可以使用批处理文件和shell脚本执行此操作,但是有更多专业解决方案可以创建本机启动程序,例如install4j (Disclaimer: my company develops install4j). (免责声明:我的公司开发install4j)。 A free solution is izpack . 免费的解决方案是izpack

This is not directly possible. 这不是直接可能的。 To make it possible, you have to download VM's for every platform. 为了实现这一点,您必须为每个平台下载VM。 For windows, copy the JRE to a directory and the jar and call distributed JVM by shell scripts. 对于Windows,将JRE复制到目录和jar,并通过shell脚本调用分布式JVM。 But this is so hard and the solution described by Cthulhu is best ie, check the version and point to the webpage. 但这很难,而且Cthulhu描述的解决方案是最好的,即检查版本并指向网页。

However there are some you might check out. 但是有一些你可能会检查出来。

JSmooth - http://jsmooth.sourceforge.net/ JSmooth - http://jsmooth.sourceforge.net/

Jar2Exe - http://transfer2pc.weebly.com/1/post/2011/10/jar2exe-converter-11-gui.html Jar2Exe - http://transfer2pc.weebly.com/1/post/2011/10/jar2exe-converter-11-gui.html

If it is a NetBeans platform application, NetBeans itself has the option to bundle additional resources and JRE . 如果它是NetBeans平台应用程序,NetBeans本身可以选择捆绑其他资源和JRE。

Source: https://platform.netbeans.org/tutorials/nbm-nbi.html#bundling-jre 资料来源: https//platform.netbeans.org/tutorials/nbm-nbi.html#bundling-jre

You can have a look at jrecreate provided by oracle and that may just do what you need / want . 你可以看看oracle提供的jrecreate,它可能只是做你需要/想要的东西。

https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/jrecreate.htm https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/jrecreate.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将特定的JRE版本设置为在JBoss上运行的Java应用程序的默认版本 - How to set a particular JRE version as default for my Java application running on JBoss 如何确定Java应用程序的最低JRE版本和系统要求 - How to determine the minimum JRE version and system requirements for my Java application BKM向最终用户交付基于Web的Java应用程序+ Jetty + JRE - BKM to deliver a web-based java application + Jetty + JRE to end-user 如何从 Java 应用程序更新 JRE(或运行时映像)? - How do I update my JRE (or Runtime Image) from my Java application? 如何使用java应用程序检查jre版本 - how to check jre version using java application 如何将 Java 相关应用程序与 MSI 中的 JRE 捆绑在一起 - How to bundle a Java dependent application with a JRE in an MSI 我有一个Java应用程序在JRE 6中运行,但不在JRE 7中运行。如何在JRE7中运行该应用程序 - I have a Java App running in JRE 6 but not in JRE 7. How do i run the application in JRE7 将JRE与Java应用程序捆绑在一起 - Bundling the JRE with a Java application 用于Java应用程序的JRE包 - Package JRE for Java application 如何检查我的Java应用程序将在具有JRE 1.6 / 1.7的计算机上运行? - How do I check that my Java application will run on a machine with JRE 1.6/1.7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM