Create jre from OpenJDK Windows

前端 未结 10 2014
太阳男子
太阳男子 2020-12-08 09:54

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 client

相关标签:
10条回答
  • 2020-12-08 10:03

    On this site you can get jdk and jre (the jdk contains 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.

    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'
    
    0 讨论(0)
  • 2020-12-08 10:05

    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.

    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.

    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.

    Give it a try here - EasyJRE: https://justinmahar.github.io/easyjre/

    0 讨论(0)
  • 2020-12-08 10:05

    I'm using openjdk 11 in place of jre8 since oracle announced the license change. My customers were unhappy about them changing the agreement.

    To get it to work, all I had to do was rename the sdk folder to 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.

    Hope this helps

    Stuart

    0 讨论(0)
  • 2020-12-08 10:12

    Inspired by the article Using jlink to Build Java Runtimes for non-Modular Applications I used the commands:

    1. java --list-modules to get a list of all openjdk modules available
    2. jlink --no-header-files --no-man-pages --compress=2 --add-modules <module-list from step 1> --output java-runtime to create a compact jre.

    For OpendJDK 12 this is the command I ended up with:

    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

    0 讨论(0)
  • 2020-12-08 10:16

    According to the Building OpenJDK document1:

    Windows XP is not a supported platform, but all newer Windows should be able to build 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.

    But the clear implication is that you can build OpenJDK on Windows and for Windows ... even though the end result is not supported by Oracle or the OpenJDK project.

    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 ...

    But a simpler approach is to use "jlink" to generate a JRE-like executable; see the accepted answer.


    @Andrew Henle points out that there are costs and (if you put yourself in the mindset of a corporate lawyer) risks in rolling your own JRE. Whether you just use it internally or you provide it to customers. If this is a concern, you are in a bit of a bind:

    • From Java 9 onwards, Oracle does not ship JRE distributions at all. Not for Oracle Java. Not for OpenJDK Java. As far as Oracle is concerned, JREs end after Java 8.

    • Anything that you build for yourself is a cost and a (erm) risk.

    Fortunately, there are 3rd-party vendors who ship JRE distributions for Java on Windows. (Both AdoptOpenJDK and Azul do at the time of writing).

    Alternatively, just use an Oracle JDK distro. Disk space is cheap, networks are fast.


    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.

    0 讨论(0)
  • 2020-12-08 10:17

    Amazon Corretto OpenJDK https://aws.amazon.com/corretto/ has the builds for JDK and JRE

    0 讨论(0)
提交回复
热议问题