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?