# rt.jar file questions (import, size, redundancy)

You Gin
Ranch Hand
Posts: 52
Hi guys,

What I've noticed is that rt.jar is located in both JDK and JRE:
"c:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar"
"c:\Program Files\Java\jre6\lib\rt.jar"

Several questions arise at the same time. Do you mind I'll list them all?

Here are they:

1. Which of them is using when I do import something in my code?
2. Why the size of these two is different?
3. Does it mean I can simply remove the jre6 folder and still be able to run java applications (as long as JRE is included in JDK)?

Jeff Friesen
author
Ranch Hand
Posts: 41
Hi You,

On my Windows XP platform, I have JDK 6 Update 16 installed in my C:\Program Files\Java\jdk1.6.0_16 directory, and JRE 6 Update 21 installed in my C:\Program Files\Java\jre6 directory. The size of the rt.jar file in my C:\Program Files\Java\jdk1.6.0_16\jre\lib directory is 49,396,545 bytes, and the size of the rt.jar file in my C:\Program Files\Java\jre6\lib directory is 44,655,521 bytes. The difference in rt.jar file sizes is due to two different versions of Java, and I suspect this is what you have as well.

At your command line, execute java -version and javac -version. Do the version numbers agree or are they different? They probably are different.

When I compile a Java source file at the command line, I'm using JDK 6 Update 16. When I run an application via java at the command line, I'm using JRE 6.

I could remove my JRE 6 folder (which got installed when I ran a JavaFX application that needed a more recent update) and then my java command would indicate JDK 6 Update 16.

Hope this helps.

Jeff

Rob Spoor
Sheriff
Posts: 20661
65
Jeff Friesen wrote:On my Windows XP platform, I have JDK 6 Update 16 installed in my C:\Program Files\Java\jdk1.6.0_16 directory, and JRE 6 Update 21 installed in my C:\Program Files\Java\jre6 directory. The size of the rt.jar file in my C:\Program Files\Java\jdk1.6.0_16\jre\lib directory is 49,396,545 bytes, and the size of the rt.jar file in my C:\Program Files\Java\jre6\lib directory is 44,655,521 bytes. The difference in rt.jar file sizes is due to two different versions of Java, and I suspect this is what you have as well.

Actually, even with the same version this issue occurs.

I have not installed any JRE separately, only as part of the JDK. That means that my JRE and JDK are both the same version, 1.6.0u21. My JDK's rt.jar has a size of 49,785,005 bytes, the JRE's rt.jar has a size of 44,655,521 bytes.

I just did a file comparison on the contents of both JAR files (them being ZIP files), and the class files are different (except 24 of them...). The present class files are the same in both files. It just seems like the API classes have been compiled twice, once for the JDK and once for the JRE. Perhaps the debugging settings are different; if I call "".substring(0, 25); with my JDK's java.exe I see the file name and line number where the exception occurs, with my JRE's java.exe I see "Unknown Source".