如何在我的JAR中捆绑JRE,以便它可以在没有Java的系统上运行? [英] How do I bundle a JRE in my JAR, so that it can run on systems without Java?

查看:245
本文介绍了如何在我的JAR中捆绑JRE,以便它可以在没有Java的系统上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在可执行文件JAR中捆绑一个JRE,以便该exe可以在任何系统上运行.

I want to bundle a JRE inside my executable JAR, so that the exe can run on any system.

我已经尝试过 Launch4j ,但是这种方法要求我同时交付JRE和exe.根据我的要求,我既不应该使用安装程序来运送产品,也不应该在客户端计算机上提取/安装JRE.

I have tried Launch4j, but that approach requires me to ship both the JRE and the exe. As per my requirements, I should not use an installer to ship, nor extract/install the JRE on the client machine.

如何将JRE放入JAR并加以利用?

How do I put a JRE inside a JAR and make use of it?

推荐答案

您不能将JRE放在JAR文件中. (好吧,但是...无济于事.)

You cannot put a JRE inside a JAR file. (Well you can ... but it won't help.)

您需要做的是构建并分发安装程序.创建安装程序的推荐方法是使用商业或开源安装程序生成器. (Google会帮助您找到一个.)

What you need to do is build and distribute an installer. The recommended way to create an installer is to use a commercial or open-source installer generator. (Google will help you find one.)

也可以将JRE嵌入ZIP文件中,如下所述:

It is also possible to do embed a JRE in a ZIP file, as described here:

  • How to bundle a JRE with Launch4j? (see the accepted answer)

ZIP文件包含JRE和应用程序JAR以及它需要的其他文件.用户必须解压缩ZIP文件才能安装该应用程序.

The ZIP file contains the JRE and the application JAR, and other files that it needs. The user has to unzip the ZIP file to install the application.

..,但是它在客户端系统中复制了将近100 MB的JRE.是否可以使JRE重量轻?

.. but it's copying total JRE in client system of almost 100 MB. Is it possible to make JRE light weight?

并非如此.分发JRE的最(合法)轻便的方法是分发Oracle Java安装程序.注意,Java Binary License禁止分发精简JRE.如果您想走这条路首先与律师交谈!

Not really. The most (legal) light-weight way to distribute a JRE is to distribute an Oracle Java installer. Beware that the Java Binary License forbids the distribution of a cut-down JRE. If you want to go down that path talk to a lawyer first!!

使用嵌入式JRE分发Java应用程序可以说是一件坏事:

Distributing Java apps with an embedded JRE is arguably a bad thing:

  • 它用多个JRE填充用户磁盘.
  • JRE往往被隐藏/对于正常的安全更新/补丁/审核不可见.因此,它们往往会成为安全责任.
  • 您需要定期更新您的可分发内容...避免将过时/不安全的JRE强加给毫无戒心的用户.

从Java 9开始,有比嵌入标准JRE更好的解决方案.使用新的jlink实用程序为您的应用程序创建量身定制的JRE.有关教程,请参见 https://www.baeldung.com/jlink 和Oracle Jlink手动输入.

From Java 9 onwards there is a better solution than embedding a standard JRE. Use the new jlink utility to create a tailored JRE for your application; see https://www.baeldung.com/jlink for a tutorial, and the Oracle Jlink manual entry.

请注意,这完全解决了嵌入式JRE的问题.但是,它将更新应用程序(带有JVM安全修补程序等)的责任明确地放在了应用程序开发人员/发行人的手中……可以说总是如此.每当发布相关的安全补丁程序时,您都需要创建一个新的可分发产品,使其可用并通知您的客户.

Note that this entirely address the concerns with embedded JREs. However it is placing the responsibility for updating the application (with JVM security patches, etc) clearly in the app developer / distributor's hands ... where arguably it always was. Whenever relevant security patches are released, you need to create a new distributable, make it available, and notify your customers.

这篇关于如何在我的JAR中捆绑JRE,以便它可以在没有Java的系统上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆