如何在 Java 11 中使用没有 jre 的 jdk

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52584888/
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 00:31:41  来源:igfitidea点击:

How to use jdk without jre in Java 11

javajava-8migrationjava-11

提问by Maha Lak

We are planning to migrate our Java 8 project to use Java 11. But I noticed that Java 11 doesn't have a JRE folder.

我们计划迁移我们的 Java 8 项目以使用 Java 11。但我注意到 Java 11 没有 JRE 文件夹。

In Java 9 and Java 10, folder structures are changed i.e. java\jdk1.xor java\jre1.x, where xis java 9 or 10.

在 Java 9 和 Java 10 中,文件夹结构发生了变化,即java\jdk1.xjava\jre1.x,其中x是 java 9 或 10。

But in Java 11, I am getting only one folder, i.e. java\jdk-11. How will my client use my application without jre?

但是在 Java 11 中,我只得到一个文件夹,即java\jdk-11. 我的客户将如何在没有 jre 的情况下使用我的应用程序?

What I understood is that Java 11 is enforcing to modularize our application, and using jlink is needed to create our own jre to run the application in client.

我的理解是 Java 11 正在强制模块化我们的应用程序,并且需要使用 jlink 创建我们自己的 jre 以在客户端运行应用程序。

Is my understanding correct?

我的理解正确吗?

回答by jwenting

For 20 years, the JDK shipped with a JRE which was just a subset of its functionality installed in a different directory on your system.

20 年来,JDK 附带了一个 JRE,它只是安装在系统不同目录中的功能的一个子集。

In fact, it shipped with TWO identical JREs, one installed inside the JDK installation directory and one outside it.

事实上,它附带了两个相同的 JRE,一个安装在 JDK 安装目录中,一个安装在 JDK 安装目录之外。

This has always puzzled me as it's a complete waste of effort on the part of the maintainers to make this so, and a complete waste of disk space on the computer you install it on, as that JRE just duplicates some of the things the JDK can do already.

这一直让我感到困惑,因为维护人员这样做完全是在浪费精力,而且完全浪费了安装它的计算机上的磁盘空间,因为 JRE 只是复制了 JDK 可以做的一些事情做已经。

Finally, with Java 11, Oracle and the OpenJDK team decided to end this silliness and just distribute a single thing, the JDK. This JDK when installed is actually smaller on your hard disk than the old JRE alone used to be, removing even the somewhat valid argument that you'd want a separate JRE for devices with limited disk space, an argument that never explained why 2 JREs would be installed with a single JDK in the first place but was made to justify the need for a JRE as a stripped down runtime environment for the JDK.

最后,在 Java 11 中,Oracle 和 OpenJDK 团队决定结束这种愚蠢的做法,只发布一个东西,即 JDK。这个 JDK 安装在你的硬盘上实际上比以前单独的旧 JRE 更小,甚至删除了你想要一个单独的 JRE 用于磁盘空间有限的设备的有点有效的论点,这个论点从未解释为什么 2 个 JRE 会首先安装一个 JDK,但为了证明需要 JRE 作为 JDK 的精简运行时环境。

Ergo, there is no need for a separate JRE, and there hasn't been one for a long time, let alone for including and forcibly installing it as part of the JDK installation.

因此,不需要单独的JRE,并且已经很长时间没有了,更不用说将其包含并强制安装作为JDK安装的一部分。

And no, you don't need to create your own JRE. Just install the OpenJDK on the client machines and make sure you add the $JAVA_HOME/bin to the system path, just as you had to do with old JREs.

不,您不需要创建自己的 JRE。只需在客户端计算机上安装 OpenJDK 并确保将 $JAVA_HOME/bin 添加到系统路径,就像您必须对旧的 JRE 做的那样。

And oh, strip the Windows directory tree of any java*.exe files which some versions of the old JRE installer were wont to place there, as well as the system path which also had some weird entries added by some JRE installers.

哦,去掉某些版本的旧 JRE 安装程序不会放置在那里的任何 java*.exe 文件的 Windows 目录树,以及一些 JRE 安装程序添加的一些奇怪条目的系统路径。

回答by matson kepson

Look at AdoptOpenJDK project website to download the latest JRE and JDK https://github.com/AdoptOpenJDK/openjdk-jdk11

查看AdoptOpenJDK项目网站下载最新的JRE和JDK https://github.com/AdoptOpenJDK/openjdk-jdk11

I have used their night builds to workaround the problem of missing JRE in JDK package https://adoptopenjdk.net/releases.html?variant=openjdk11#x64_linux

我使用他们的夜间构建来解决 JDK 包中缺少 JRE 的问题https://adoptopenjdk.net/releases.html?variant=openjdk11#x64_linux

Just unpack JRE into JDK folder and this gonna be it.

只需将 JRE 解压到 JDK 文件夹中,就可以了。

enter image description here

在此处输入图片说明

回答by Basil Bourque

tl;dr

tl;博士

How will my client use my application without jre?

我的客户将如何在没有 jre 的情况下使用我的应用程序?

? Bundle a Java implementation within your Java-based app.

? 在基于 Java 的应用程序中捆绑 Java 实现。

Learn about:

学习关于:

Details

细节

What I understood is that Java 11 is enforcing to modularize our application

我的理解是 Java 11 正在强制模块化我们的应用程序

No, modularization is not required, strictly speaking. Most existing apps can run as-is in Java 11. You can continue to develop in Java 11 without modularizing your code. But in your case, for a GUI desktop or mobile app, then you need to package a JVM within your app. Modularizing and using jlinktooling is probably the best way to go about that. In contrast a server-side Servlet-based app or Microservices server need not yet modularize, though likely a good idea to do so eventually.

不,严格来说,不需要模块化。大多数现有应用程序都可以在 Java 11 中按原样运行。您可以继续在 Java 11 中进行开发,而无需模块化代码。但就您而言,对于 GUI 桌面或移动应用程序,则需要在您的应用程序中打包 JVM。模块化和使用jlink工具可能是最好的方法。相比之下,服务器端基于 Servlet 的应用程序或微服务服务器还不需要模块化,尽管最终这样做可能是个好主意。

I noticed that Java 11 doesn't have a JRE folder.

我注意到 Java 11 没有 JRE 文件夹。

Oracle no longer intends for end-users to be installing a JRE or a JDK. Java Appletsin a browser and Java Web Startapp delivery are both being phased out, leaving the end-user with no need for a JRE. Java-based apps are expected to bundle their own Java implementation. The only folks consciously installing a JDK will be developers & server-side sysadmins.

Oracle 不再打算让最终用户安装 JRE 或 JDK。浏览器中的Java AppletJava Web Start应用程序交付都将被逐步淘汰,最终用户无需 JRE。基于 Java 的应用程序应该捆绑自己的 Java 实现。唯一有意识地安装 JDK 的人将是开发人员和服务器端系统管理员。

Some folks are disappointed to see the passing of the Java Everywheredream. And they may be annoyed to have to make a build of their app for every host OS (macOS, Linux, Windows, etc.). On the other hand, some developers are happy to be bundling a Java implementation (now smaller than ever) with their app, as that eliminates the hassle for the end-user to download-install-update a system-wide Java implementation. Also eliminates wrestling with corporate IT departments to install Java on users' PCs. And bundling Java with app simplifies testing and support, as you know and control exactly what version and distribution of Java is involved. By the way, this bundling-Java-with-app is not exactly new: It has been supported by Apple for many years in the macOS & iOS app stores.

有些人对Java Everywhere梦想的破灭感到失望。他们可能会对必须为每个主机操作系统(macOS、Linux、Windows 等)构建应用程序而感到恼火。另一方面,一些开发人员很乐意将 Java 实现(现在比以往任何时候都小)与他们的应用程序捆绑在一起,因为这消除了最终用户下载-安装-更新系统范围的 Java 实现的麻烦。还消除了与企业 IT 部门在用户 PC 上安装 Java 的麻烦。将 Java 与应用程序捆绑在一起可以简化测试和支持,因为您知道并准确控制所涉及的 Java 版本和发行版。顺便说一句,这种捆绑 Java 的应用程序并不是全新的:Apple 多年来一直在 macOS 和 iOS 应用程序商店中支持它。

Important:

重要的:

Here is a flowchart diagram that may help you finding and deciding amongst the various vendors providing a Java 11 implementation.

这是一个流程图,可以帮助您在提供 Java 11 实现的各种供应商中查找和决定。

Flowchart guiding you in choosing a vendor for a Java 11 implementation

指导您为 Java 11 实现选择供应商的流程图



Motivations in choosing a vendor for Java

选择 Java 供应商的动机