Java 从 OpenJDK Windows 创建 jre
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51403071/
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
Create jre from OpenJDK Windows
提问by JimmyD
We are switching from Oracle JDK/JRE to OpenJDK. Now I found only the JDK but I want to have a JRE as well from OpenJDK. This is for installing our application on the clients without the need of having the full JDK.
我们正在从 Oracle JDK/JRE 切换到 OpenJDK。现在我只找到了 JDK,但我还想从 OpenJDK 中获得 JRE。这是为了在不需要完整 JDK 的情况下在客户端上安装我们的应用程序。
Is there a way to create a JRE package from the OpenJDK for Windows X64?
有没有办法从适用于 Windows X64 的 OpenJDK 创建 JRE 包?
采纳答案by SteinarH
Inspired by the article Using jlink to Build Java Runtimes for non-Modular ApplicationsI used the commands:
受到文章Using jlink to Build Java Runtimes for non-Modular Applications 的启发,我使用了以下命令:
java --list-modules
to get a list of all openjdk modules availablejlink --no-header-files --no-man-pages --compress=2 --add-modules <module-list from step 1> --output java-runtime
to create a compact jre.
java --list-modules
获取所有可用 openjdk 模块的列表jlink --no-header-files --no-man-pages --compress=2 --add-modules <module-list from step 1> --output java-runtime
创建一个紧凑的jre。
For OpendJDK 12 this is the command I ended up with:
对于 OpendJDK 12,这是我最终得到的命令:
jlink --no-header-files --no-man-pages --compress=2 --add-modules java.base,java.compiler,java.datatransfer,java.desktop,java.instrument,java.logging,java.management,java.management.rmi,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.se,java.security.jgss,java.security.sasl,java.smartcardio,java.sql,java.sql.rowset,java.transaction.xa,java.xml,java.xml.crypto,jdk.accessibility,jdk.aot,jdk.attach,jdk.charsets,jdk.compiler,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.crypto.mscapi,jdk.dynalink,jdk.editpad,jdk.hotspot.agent,jdk.httpserver,jdk.internal.ed,jdk.internal.jvmstat,jdk.internal.le,jdk.internal.opt,jdk.internal.vm.ci,jdk.internal.vm.compiler,jdk.internal.vm.compiler.management,jdk.jartool,jdk.javadoc,jdk.jcmd,jdk.jconsole,jdk.jdeps,jdk.jdi,jdk.jdwp.agent,jdk.jfr,jdk.jlink,jdk.jshell,jdk.jsobject,jdk.jstatd,jdk.localedata,jdk.management,jdk.management.agent,jdk.management.jfr,jdk.naming.dns,jdk.naming.rmi,jdk.net,jdk.pack,jdk.rmic,jdk.scripting.nashorn,jdk.scripting.nashorn.shell,jdk.sctp,jdk.security.auth,jdk.security.jgss,jdk.unsupported,jdk.unsupported.desktop,jdk.xml.dom,jdk.zipfs --output java-runtime
jlink --no-header-files --no-man-pages --compress=2 --add-modules java.base,java.compiler,java.datatransfer,java.desktop,java.instrument,java.logging,java.management,java.management.rmi,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.se,java.security.jgss,java.security.sasl,java.smartcardio,java.sql,java.sql.rowset,java.transaction.xa,java.xml,java.xml.crypto,jdk.accessibility,jdk.aot,jdk.attach,jdk.charsets,jdk.compiler,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.crypto.mscapi,jdk.dynalink,jdk.editpad,jdk.hotspot.agent,jdk.httpserver,jdk.internal.ed,jdk.internal.jvmstat,jdk.internal.le,jdk.internal.opt,jdk.internal.vm.ci,jdk.internal.vm.compiler,jdk.internal.vm.compiler.management,jdk.jartool,jdk.javadoc,jdk.jcmd,jdk.jconsole,jdk.jdeps,jdk.jdi,jdk.jdwp.agent,jdk.jfr,jdk.jlink,jdk.jshell,jdk.jsobject,jdk.jstatd,jdk.localedata,jdk.management,jdk.management.agent,jdk.management.jfr,jdk.naming.dns,jdk.naming.rmi,jdk.net,jdk.pack,jdk.rmic,jdk.scripting.nashorn,jdk.scripting.nashorn.shell,jdk.sctp,jdk.security.auth,jdk.security.jgss,jdk.unsupported,jdk.unsupported.desktop,jdk.xml.dom,jdk.zipfs --output java-runtime
回答by Stephen C
According to the Building OpenJDKdocument1:
根据构建 OpenJDK文档1:
Windows XP is not a supported platform, but all newer Windows should be able to build OpenJDK.
Windows XP 不是受支持的平台,但所有较新的 Windows 都应该能够构建 OpenJDK。
It then goes on to explain that Cygwin is required to do the build, the requirements for native compilers and libraries, and the issue of the "bootstrap" JDK that is required to compile the Java classes in the source tree.
然后继续解释需要 Cygwin 进行构建、对本机编译器和库的要求,以及编译源树中的 Java 类所需的“引导”JDK 问题。
But the clear implication is that you can build OpenJDK onWindows and forWindows ... even though the end result is not supportedby Oracle or the OpenJDK project.
但明确的含义是,你可以建立的OpenJDK在Windows和对窗口...即使最终的结果是不支持通过Oracle或OpenJDK项目。
Note that the build document describes the make targets for creating JRE and JDK "images". I think it is saying that these are binary trees that can be copied to a target system and used. You could create ZIPs from them ...
请注意,构建文档描述了用于创建 JRE 和 JDK“映像”的 make 目标。我认为这是说这些是可以复制到目标系统并使用的二叉树。您可以从它们创建 ZIP ...
1 - That link is for the Java 9 version of the document. For others, you should be able to find a corresponding "building.html" document at the same place in the source tree.
1 - 该链接适用于文档的 Java 9 版本。对于其他人,您应该能够在源代码树的同一位置找到相应的“building.html”文档。
回答by Konrad Botor
As far as I know the only place you can download OpenJDK for Windows is Azul website. However, they only seem to provide full JDK, so if you want just the JRE you need to build it yourself as Stephen C suggested.
据我所知,唯一可以下载适用于 Windows 的 OpenJDK 的地方是Azul 网站。但是,它们似乎只提供完整的 JDK,因此如果您只需要 JRE,则需要按照 Stephen C 的建议自行构建。
回答by Alexander Wessel
回答by Stuart
I'm using openjdk 11 in place of jre8 since oracle announced the license change. My customers were unhappy about them changing the agreement.
自从 oracle 宣布更改许可证以来,我使用 openjdk 11 代替 jre8。我的客户对他们更改协议感到不满。
To get it to work, all I had to do was rename the sdk folder to jre.
为了让它工作,我所要做的就是将 sdk 文件夹重命名为 jre。
One problem I did have was an external library dll. where open jdk complained it could no longer find in the class path. To fix that I just copied the dlls to the system32 folder.
我确实遇到的一个问题是外部库 dll。open jdk 抱怨它在类路径中找不到的地方。为了解决这个问题,我只是将 dll 复制到 system32 文件夹。
Hope this helps
希望这可以帮助
Stuart
斯图尔特
回答by Dmitri Ciornii
Amazon Corretto OpenJDK https://aws.amazon.com/corretto/has the builds for JDK and JRE
Amazon Corretto OpenJDK https://aws.amazon.com/corretto/具有 JDK 和 JRE 的构建
回答by Justin
As others have mentioned, there's no longer a separate JRE distributed with the JDK since Java 9. You will need to use jlink
and specify the modules your code depends on to generate a custom jre.
正如其他人所提到的,自 Java 9 以来不再有单独的 JRE 与 JDK 一起分发。您将需要使用jlink
并指定代码所依赖的模块来生成自定义 jre。
Because this can be a hassle, I've created a web-based tool to make it easier to create a custom JRE from an OpenJDK implementation (such as Oracle HotSpot, Eclipse OpenJ9, or Amazon Corretto) using jlink
. The tool will give you the correct jlink
command to run depending on your needs.
因为这可能很麻烦,所以我创建了一个基于 Web 的工具,以便使用jlink
. 该工具将为您提供正确的jlink
命令以根据您的需要运行。
I've also included a way to make a standard Java SE JRE for those who just want a basic lightweight (~40-60 MB) JRE. If you know how to use a terminal, it'll take you less than 2 minutes to create a general-use JRE for JDK 9 and up.
我还提供了一种为那些只需要基本轻量级(~40-60 MB)JRE 的人制作标准 Java SE JRE 的方法。如果您知道如何使用终端,则只需不到 2 分钟即可为 JDK 9 及更高版本创建通用 JRE。
Give it a try here - EasyJRE: https://justinmahar.github.io/easyjre/
在这里尝试一下 - EasyJRE:https://justinmahar.github.io/easyjre/
回答by Maxs728
So I'm going to post an something a little bit easier than what was posted by SteinarH. I didn't want to have to compile that list myself so.... this does it for you. Also for the sense of being a bit more concise I wouldn't label it java-runtime
but instead jre-11
(or whatever version you are using).
所以我将发布一个比 SteinarH 发布的内容更容易的内容。我不想自己编译那个列表,所以......这对你来说是这样的。同样为了更简洁的感觉,我不会标记它java-runtime
,而是jre-11
(或您使用的任何版本)。
jlink --no-header-files --no-man-pages --compress=2 --add-modules $($(java --list-modules) -join "," -replace "@[0-9]*") --output jre-11
jlink --no-header-files --no-man-pages --compress=2 --add-modules $($(java --list-modules) -join "," -replace "@[0-9]*") --output jre-11
回答by Edgardo Genini
On this site you can get jdk and jre (the jdk contains jre) https://adoptopenjdk.net/upstream.html.
在这个站点上你可以获得 jdk 和 jre(jdk 包含 jre) https://adoptopenjdk.net/upstream.html。
But if you need to build a jre you can use the following code in python (I have taken the answer from @SteinarH), the code assumes that you are in the jdk bin and that there is no directory called jre at the previous level.
但是如果你需要构建一个jre,你可以在python中使用下面的代码(我从@SteinarH那里得到了答案),代码假设你在jdk bin中,并且在上一级没有名为jre的目录。
import os
jmod_str = os.popen('java --list-modules').read()
init = jmod_str.index('@')
end = jmod_str.index('\n')
version = jmod_str[init:end]
jmod_list = jmod_str.replace(version, '').replace('\n', ',')
jmod_list = jmod_list[:-1] if jmod_list[-1] == ',' else jmod_list
cmd = 'jlink --no-header-files --no-man-pages --compress=2 --module-path ..\jmods --add-modules '+ jmod_list + ' --output ..\jre'