Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create jre from OpenJDK Windows

Tags:

java

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.

Is there a way to create a JRE package from the OpenJDK for Windows X64?

like image 997
JimmyD Avatar asked Jul 18 '18 13:07

JimmyD


People also ask

Is there a JRE for OpenJDK?

The openjdk-6-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-6-jdk package.

How do I create a custom JRE?

You can use jdep command on your custom module to know module dependency . 5. Now use jlink command line tool to create your custom JRE. Command will create new JRE and now you can use your own JRE to run your program.

Does OpenJDK 11 have JRE?

@PeterLawrey JDK 11 does not include a JRE sub-directory.

Can I use JDK as JRE?

The JDK includes the JRE, so you do not have to download both separately. To understand the version-string scheme that is used to distinguish various JDK and JRE releases, see Version-String Format.


4 Answers

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

like image 159
SteinarH Avatar answered Oct 18 '22 19:10

SteinarH


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/

like image 38
Justin Avatar answered Oct 18 '22 21:10

Justin


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

like image 6
Dmitri Ciornii Avatar answered Oct 18 '22 20:10

Dmitri Ciornii


So I'm going to post 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).

This is PowerShell:

jlink --no-header-files --no-man-pages --compress=2 --add-modules $($(java --list-modules) -join "," -replace "@[0-9]*") --output jre-11

like image 6
Maxs728 Avatar answered Oct 18 '22 21:10

Maxs728