37

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?

Santosh b
  • 534
  • 4
  • 17
JimmyD
  • 2,089
  • 3
  • 23
  • 47
  • You are aware that OpenJDK is the name of the project? Not referring to JDK/JRE distribution. – Thorbjørn Ravn Andersen Jul 18 '18 at 13:21
  • Actually, it *is also* used as the label for the distribution (actually the Linux package manager packages) on many Linux distros. – Stephen C Jul 18 '18 at 13:33
  • @titou10 there's no separate JRE as none is needed. It's all part of the JDK distribution. – jwenting Oct 03 '18 at 09:59
  • 1
    @jwenting I will definitively not bundle the full JDK with my Eclipse RCP app and add about 300MB in the distribution... – titou10 Oct 03 '18 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 – jwenting Oct 03 '18 at 13:02

10 Answers10

25

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

SteinarH
  • 276
  • 3
  • 3
  • 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. – emllnd Apr 21 '20 at 09:47
11

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/

Justin
  • 181
  • 2
  • 2
5

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

5

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

dsh
  • 11,380
  • 3
  • 27
  • 48
Maxs728
  • 473
  • 2
  • 7
  • 17
  • you are copying all the modules from JDK to jre? Then what's the profit? – P Satish Patro Apr 29 '21 at 14:54
  • 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. – Maxs728 May 03 '21 at 08:59
  • 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. – Maxs728 May 03 '21 at 09:01
  • Okay. Understood. Thanks for the update – P Satish Patro May 05 '21 at 12:33
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.

Stephen C
  • 632,615
  • 86
  • 730
  • 1,096
  • 1
    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. – Andrew Henle Jul 18 '18 at 14:54
  • Well, yes for the first part. For the second part, if you are using OpenJDK, then the legal requirements are clearly set out in http://openjdk.java.net/legal/. While IANAL, it should not take a lawyer to understand how these apply to a company. Especially since the licenses are all based GPL version 2 + Classpath exception ... which is well researched and well understood. – Stephen C Jul 19 '18 at 03:09
  • 1
    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. – Andrew Henle Jul 19 '18 at 11:13
  • You are assuming that JimmyD is intending to make his JRE available to people outside of his organization. That's not how I read this question. *"This is for installing our application on the clients without the need of having the full JDK."* - read "the clients" as meaning machines that talk to his servers ... not his organization's customers. However, you are correct that this whole exercise appears to be pointless. – Stephen C Jul 19 '18 at 11:24
  • 1
    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 ) – Andrew Henle Jul 19 '18 at 11:34
  • @AndrewHenle - But the flipside is that rolling your own JRE so that you don't have to pay Oracle license fees to use Oracle Java 11 in production will get the corporate bean counters to talk to the corporate lawyers and tell them to stop being obstructionist. Bear in mind that (as of right now) Oracle still haven't made an Oracle Java 11 JRE available for public download .... anywhere that I can find! – Stephen C Nov 02 '18 at 02:45
  • 1
    *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? – Andrew Henle Nov 02 '18 at 09:39
  • 1
    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. – Stephen C Nov 02 '18 at 10:40
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.

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

Stuart
  • 37
  • 5
  • 1
    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 – Martin Meeser Feb 21 '20 at 14:33
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'
Edgardo Genini
  • 510
  • 4
  • 9
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.

Konrad Botor
  • 3,904
  • 1
  • 10
  • 21
  • 1
    There is an official build for Windows build by Oracle available on the official openjdk page. – JimmyD Jul 18 '18 at 14:54
  • 2
    @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. – Andrew Henle Jul 18 '18 at 14:59
  • It's only for the jdk. I need a way to get the jre. – JimmyD Jul 18 '18 at 15:00
  • @jwenting - As of now, you can't get a JRE from jdk.java.net. Only full JDK builds, as far as I can see. – Stephen C Nov 02 '18 at 10:44
  • 2
    @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). – jwenting Nov 05 '18 at 04:58
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!