42

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?

5
  • You are aware that OpenJDK is the name of the project? Not referring to JDK/JRE distribution. Commented Jul 18, 2018 at 13:21
  • Actually, it is also used as the label for the distribution (actually the Linux package manager packages) on many Linux distros. Commented Jul 18, 2018 at 13:33
  • @titou10 there's no separate JRE as none is needed. It's all part of the JDK distribution. Commented Oct 3, 2018 at 9:59
  • 2
    @jwenting I will definitively not bundle the full JDK with my Eclipse RCP app and add about 300MB in the distribution... Commented Oct 3, 2018 at 12:16
  • 1
    @titou10 you shouldn't bundle the runtime anyway as the license no longer allows for it. I've done some comparisons, for 1.8 the full JDK minus the docs and the included JRE was almost the same size as just that JRE. Expect things to be the same for 11. So you'd be saving peanuts, a few hundred K at most Commented Oct 3, 2018 at 13:02

12 Answers 12

31

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

Sign up to request clarification or add additional context in comments.

1 Comment

This worked quite well on OSX too! I skipped all the lines beginning with 'jdk.' and my (admittedly very small and independent) application ran just fine using the produced runtime.
17

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/

1 Comment

Thanks a lot. This is really amazing tool.
7

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

1 Comment

You can also find JRE builds here: adoptopenjdk.net/releases.html
6

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

3 Comments

you are copying all the modules from JDK to jre? Then what's the profit?
I would probably say (though this worked at the time I needed it), this answer is now a little irrelevant. However, it was stripping the jdk documentation and header files. That is essentially what the JRE has. If you didn't need or want all the modules to be usable then you don't need to do it this way. This is outdated because you can also use Chocolatey on Windows which has the adoptopenjdk11jre 11.0.11.900 [Approved] available. No need to do the work yourself.
Should just state for those interested in that approach the command would look like choco install -y adoptopenjdk11jre and it also handles the environment variables for you.
2

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.

8 Comments

Given the effort needed to "roll your own" Windows JRE from OpenJDK (and the continuing need to rebuild it every time a security vulnerability is discovered and an update delivered...), were I in management over this group, there had better be a really strong technical reason to spend a lot of time, money and computing resources for no apparent functional benefit. And then, depending on what the JRE were to be used for, I might have to run it by some lawyers to make sure rolling our own wouldn't open up the company to any liability.
The issue isn't legal use of the product - it's the fact that rolling your own likely makes you much, much, much more responsible for the security of the product. Using the latest pre-built widely-used out-of-the-box JRE is different from compiling your own from source. "Oh, you were pwned via software you compiled yourself? Please show us how you made sure your build process produced a secure product. What? You don't even know how to test Java security?" Rolling your own JRE because "We hateses Oracle, precious!" is going to make corporate counsel poop a brick.
I'm not assuming - I just pointed out the use of the home-built JRE might need legal inspection "depending on what the JRE were to be used for". For example, if the app in question is used by customers to to online payments over the open internet (a recent question about how to update Java 6u45 to TLS 1.2 so it could do PayPal payments comes to mind... :-o )
will get the corporate bean counters to talk to the corporate lawyers and tell them to stop being obstructionist Not if the bean counters appropriately account for the fact that maintaining an up-to-date, secure JRE from source code is likely at least a full-time job for one person, thus costing the company well over $100,000 per year. I'd be damned if I'd pay a developer to uselessly reinvent the wheel in that manner over a petulant child's dislike of Oracle. And to revisit a point I made above: does the developer even know how to test JRE security? How much $$$ does that cost?
As little as $100,000 per year? You sure about that? At $25 per server core per month + $2.50 per PC user per month? And you don't need a full-time developer to rebuild JREs and apply the security patches from the OpenJDK upstream maintainers ... who Oracle has agreed to cooperate with.
|
1

Since Java 9, you can use jlink to create a custom runtime environment for your application, using only the modules you actually need to run, which is typically even smaller than the traditional JRE was.

Comments

1

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

1 Comment

that does really not solve the question, it adds lots of confusion, and in most professional scenarios, from a security POV it is a desaster
1

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' 

2 Comments

AdoptOpenJDK seems to be the only OpenJDK vendor that provides a separate JRE build.
When I looked, Azul does too.
1

Azul Systems provides up-to date Windows JREs.

Here the link to Java 18 Windows JRE:
https://www.azul.com/downloads/?os=windows&architecture=x86-64-bit&package=jre

Amazon Corretto nor AdoptOpenJDK provide Windows JREs.

We are using the Azul distribution since Oracle decided to change its licensing and made very good experience.

Also previous versions can be found: enter image description here

Comments

0

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.

5 Comments

There is an official build for Windows build by Oracle available on the official openjdk page.
@JimmyD There is an official build for Windows build by Oracle available on the official openjdk page. You need to post that as the answer. With a link.
It's only for the jdk. I need a way to get the jre.
@jwenting - As of now, you can't get a JRE from jdk.java.net. Only full JDK builds, as far as I can see.
@StephenC there is no standalone JRE for Java11, period. And do remember that every JDK IS a JRE as well. The JRE is just a JDK minus some of the tools (compilers, decompilers, and things like that).
0

For a more straightforward approach i wrote this little tool, which you can use under Windows: https://github.com/g3t00ls/OpenJDKtoOpenJRE

I personally use OpenJDK from: https://jdk.java.net/

It basicly does exactly what SteinarH wrote.

Currently it includes all java modules and exludes all jdk modules! A GUI to select required modules / an auto detect function for required modules for even smaller JRE's will probably be added soon! Currently it still needs jlink, so only >=v9 JDK's will work! This could change in the future!

Comments

0

Reasons for making another answer:

  1. I needed a single line to make a standard JRE to put in my Windows installer
  2. I didn't want to have to update it when I upgrade java

Method:

  1. I back engineered the output from the page that Justin made: https://stackoverflow.com/a/54997476/1280293 (Excellent utility)
  2. I took the output of java --list-modules
  3. selected only lines that start with java
  4. removed the @versionnumber from the end of each line
  5. joined the array into a comma separated string
  6. appended it to jlink --output jre --compress=2 --no-header-files --no-man-pages --module-path ../jmods --add-modules

Notes:

  • This command assumes you have added your java bin to your path
  • This creates it's output directory in the folder you run the command from

PowerShell:

jlink --output jre --compress=2 --no-header-files --no-man-pages --module-path ../jmods --add-modules "$((java --list-modules | Select-String -Pattern '^(java[^@]+?)@' | % {"$($_.Matches.Groups[1].value)"}) -join ',')" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.