且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Java 11 中使用没有 JRE 的 JDK

更新时间:2022-06-25 00:47:21

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

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.

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

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

这一直让我感到困惑,因为维护人员这样做完全是浪费精力,而且完全浪费了安装它的计算机上的磁盘空间,因为 JRE 只是复制了一些东西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.

最后,在 Java 11 中,Oracle 和 OpenJDK 团队决定结束这种愚蠢的做法,只发布一个东西,即 JDK.安装时,这个 JDK 在您的硬盘上实际上比以前单独的旧 JRE 小,甚至删除了一些有效的论点,即您希望为磁盘空间有限的设备使用单独的 JRE,这个论点从未解释为什么 2 个 JRE 会最初使用单个 JDK 安装,但这样做是为了证明需要 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.

因此,不需要单独的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.只需在客户端计算机上安装 OpenJDK 并确保将 $JAVA_HOME/bin 添加到系统路径中,就像您必须对旧的 JRE 做的一样.

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 安装程序不会放置在那里的任何 java*.exe 文件的 Windows 目录树,以及一些 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.