简体   繁体   中英

How to create JRE to run jar programs?

I have an executable-jar that I can run with java -jar app.jar but the SDK is 326MB . This is a lot.

jlink can create a JRE , but I can't use jlink as I have a non-modular application .

Can you please tell me how to create a JRE?

You can try to this as source:

https://javaalmanac.io/

where you can find links to download only JRE instead of JDK.

jlink can be used to create a 'JRE'/runtime image for non-modular applications just fine. It just can't automatically derive the modules that should go in the runtime image in that case. They have to be specified manually instead.

For instance, if I have a simple app.jar :

$ java -jar app.jar
Hello World!

Then create a runtime image with jlink , with only the java.base module:

jlink --output runtime --add-modules java.base --strip-debug --no-header-files --no-man-pages

Then I can run the jar with the java executable in the runtime image:

$ ./runtime/bin/java -jar app.jar
Hello World!

And the runtime image is just ~35 MB (though this can vary per platform).


jdeps can be used to get an idea of which modules should be used to create the runtime image:

$ jdeps --print-module-deps add.jar
java.base

This will print a comma-separated list of modules that can be passed directly as an argument to the --add-modules option of jlink .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM