Where can I find cross-compilation bootstrap classes for older versions of Java?

We have a Java project that we want to distribute to users. It does not use any Java features outside of Java 1.5, so we want it to work on Java 1.5 and higher.

At this point, you can rightfully point out that Java 1.6 is the oldest available currently, so why target Java 1.5? However, this does not change the general nature of the cross-compilation issue for older versions.

So, the way that cross-compilation attempts usually start is to specify the -source 1.5 and -source 1.5 options on javac , after which the well-known warning about -bootclasspath cannot be set:

 $ javac -source 1.5 -target 1.5 Test.java warning: [options] bootstrap class path not set in conjunction with -source 1.5 1 warning 

Now, according to the Oracle blog post , as well as the official documentation , the good practice of cross-compiling is this:

To use javac from JDK N to cross-compiler to an older version of the platform, good practice is this:

  • Use the old-source parameter.
  • Install bootclasspath to compile with rt.jar (or equivalent) for the old platform.

If the second step is not performed, javac will dutifully use the old language rules in combination with the new libraries, which may lead to the fact that class files that do not work on the old platform may be included in the list.

For example, citing official documentation:

 % javac -source 1.6 -target 1.6 -bootclasspath jdk1.6.0/lib/rt.jar \ -extdirs "" OldCode.java 

This is wonderful and has been answered many times, both on the stack overflow and the rest of the Internet.

However, none of the resources we found indicate where rt.jar can be found for older versions of Java. For example, JDK 1.7 does not send rt.jar except for its own:

 $ find jdk-1.7.0_45 -name rt.jar jdk-1.7.0_45/jre/lib/rt.jar 

This makes you think that to get rt.jar for Java 1.6, for example, you need to download JDK 1.6. But then two questions arise:

  • If we download JDK 1.6, we could also use this to compile instead of JDK 1.7;
  • if we want to cross-compile for Java 1.5, then JDK 1.5 is no longer available for download.

So, how do we actually specify the -bootclasspath option to use this cross compilation function?

+8
java javac cross-compiling
source share
2 answers

This type of compilation is primarily motivated by the need to target a JRE that is already in production or an existing IME installation otherwise. In this case, transfer the bootclasspath JRE files from the existing installation and make them accessible from the assembly system (s). The bootclasspath value you specify will depend on where you put the bootclasspath JRE files during this step.

FYI, you may need some more files besides rt.jar. For example, when targeting IBM Java 6.

0
source share

Rt.jar is included in the JRE. You can cross-compile if you have, say, JDK 1.6 and JRE 1.5.

Using JDK 1.6:

 $ javac -source 1.5 -target 1.5 -bootclasspath jre1.5.0/lib/rt.jar Test.java 

The advantage is that a JRE can be as little as 1/3 of the size of a full JDK. You can often remove old versions of the JDK without removing old versions of the JRE.

If you need to get the old JRE, you can find them at the links on the Java archive page http://www.oracle.com/technetwork/java/javase/archive-139210.html

+3
source share

All Articles