Using Netbeans 18 and JDK 20, I've built a project that includes a Java runtime. But I notice the resulting JRE includes Java's src.zip file. Is this really needed? The application seems to run fine without it, and I'd love to shrink the distribution by src.zip's 53MB.
-
2Not needed. Useful for development. Odd that it's getting included. Worth checking other cruft not present – g00se Aug 12 '23 at 13:24
-
1You may want to consider [using jlink](https://stackoverflow.com/a/53453519/1831987) to build your application with a Java runtime. jlink will not include src.zip in the application image. – VGR Aug 12 '23 at 13:53
-
How did you create that project? – Queeg Aug 12 '23 at 15:33
-
Read tag descriptors prior to using a tag. `Distribution` is not what you assumed. – pjs Aug 12 '23 at 18:39
-
Queeg the project was originally created using Netbeans 12 and JDK 11. I used the IDE's New Project wizard - selecting Java with Ant | Java Application. Since then I've upgraded IDE and JDK multiple times. In the Project options I chose Sources | Profile: Full JRE. In Libraries I have checked Build Dependencies. And under packaging I have checked Copy Dependent Libraries. – mstoreysmith Aug 12 '23 at 21:24
1 Answers
DISCLAIMER: Understand, this is a risky step, because taking away ANY files from the installation/shipping package might lead to runtime errors.
In your case, for example, someone could, during runtime, try to load source files from the src.zip file, manipulate the file, then try to compile it during runtime, and then load it via Reflection.
So there is always edge cases, ESPECIALLY when using Reflection and (custom) Class Loaders.
But as long as you stick to the basics, chances are near zero of running into those problems.
Now, to your question:
Necessary files for Java Runtime:
Actually, Java under Windows run with far less files:
Java 8u231 and before (still runs on WinXP):
bin/
client/
jvm.dll
Xusage.txt
java.dll
java.exe
msvcr100.dll
verify.dll
zip.dll
lib/
i386/
jvm.cfg
rt.jar
From there on, all subsequent versions
- run with the server files (no matter if the JVM is put in server or client mode).
- from Java 9+ on, the
lib/modules
file replaces thelib/rt.jar
So these are the needed files from there on out (JDK 20.0.2 runtime files):
bin/
server/
jvm.dll
java.dll
java.exe
jimage.dll
jli.dll
lib/
jvm.cfg
modules
BUT, this is without class file verification, so you have to run your app with bin\java.exe -Xverify:none HelloWorld
and get a warning, because it's deprecated.
To include file verification, all files you need are (JDK 20.0.2 runtime):
bin/
server/
jvm.dll
java.dll
java.exe
jimage.dll
jli.dll
verify.dll
lib/
jvm.cfg
modules
Further optimization
Okay, so far, so good.
BUT: we can further cut down on the rt.jar
(resp modules
file), by running the app with java <app_name> --verbose:class
. This goes even deeper than the java modules approach, because it is not module/package focused, but class focused.
(Make sure you run and re-run to cover all branches of your code)
JRE8u231 32bit
I have written a 'compiler' that takes the resulting list of classes, packages them into the rt.jar, and when compressed (7zip self-extracting, ultra compressed), my whole JRE8u231 package is 6 MB in size.
Why JRE8u231 32bit? Because it's the last Oracle Java release that runs on Windows XP without further magic. I'm using it as a beachhead to autmatically identify, download, and set up custom Java RT 'installations' and jvm configs from my server.
Later Java versions (9+)
Not sure if Your Netbeans packaging already considers the modules (using jlink), but it already might be doing that, reducing the size of the modules file from 131 MB to something smaller.
The modules file is the spiritual successor of rt.jar, but with the java modules system included. It can by analyzed by using the jimage tool: bin/jimage.exe list lib/modules
.
I have not yet cracked the modules file format for the later Java versions, but once I get to that, I'll reduce the size of the modules file even more.
Until then, the current RT size (modules file is untouched) is 28 MB, but only including a HellWorld app.

- 2,418
- 2
- 17
- 31
-
-
Yea, but you can always download the JDK compiler parts from a server during runtime, then compile the code and ClassLoaded it. Did so myself some 13 or 14 years ago, when Java 6 was around, and the application needed to support creating/editing and executing Java files during runtime. Not the HotPlug/HowSwap stuff, just really dynamic support for every possible scenario. – JayC667 Aug 13 '23 at 10:21