warning: [options] bootstrap class path not set in conjunction with -source 1.5

I get the warning message at Build time!

warning: [options] bootstrap class path not set in conjunction with -source 1.5

How can I fix it?


From a blog post:

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

  • Use the older -source setting.
  • Set the bootclasspath to compile against the rt.jar (or equivalent) for the older platform.

If the second step is not taken, javac will dutifully use the old language rules combined with new libraries, which can result in class files that do not work on the older platform since references to non-existent methods can get included.


bootclasspath usage

javac -bootclasspath /usr/lib/jvm/java-7-oracle/jre/lib/rt.jar \
      -source 1.7 Main.java

On UNIX systems, locate rt.jar using:

locate -r '/rt.jar$'

Set JAVA_HOME so that rt.jar is located at $JAVA_HOME/jre/lib/rt.jar, then:

javac -source 1.7 -bootclasspath "$JAVA_HOME/jre/lib/rt.jar" Main.java

Tested on Ubuntu 14.04 for Oracle Java 7 and 8.