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

When compiling with Java, you may get a warning message similar (or identical to):

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

This warning is emitted if you are using JDK 7 Build 121 or later (earlier versions of the compiler would not issue a warning).

It is warning you that your Java compiler version and the version of Java you are compiling for are different. For example, you may have version 7 of the compiler installed, but are choosing to compile for Java version 5.0. While the compiler is capable of emitting code for different versions, it needs to use the correct startup libraries (bootstrap) in order to guarantee it will function correctly.

In any other language, this would be called “linking against the correct startup libraries”, but in Java, it is called “compiling against bootstrap and extension classes”.

For Users of NetBeans IDE

These instructions are for NetBeans IDE 7.3.

I suspect the instructions are the same for other versions of NetBeans IDE, but I make no guarantee.

You can correct the warning by ensuring the compiler version and binary version are the same:

1) Right-click on the project:

2) Select Properties:

3) Ensure that the Source/Binary Format: under the Sources category, matches the Java Platform under the Libraries category (click for full sized image):

For Command Line Users

If you are compiling using the command line, then you need to ensure that the -source and -target options refer to the same version and the -bootclasspath option refers to the correct Java runtime.

For example, if you have JDK 7 installed and want to compile for Java 5.0, then the command line would be:

javac -source 1.5 -target 1.5 -bootclasspath path-to-java-5.0-runtime code.java

Where path-to-java-5.0-runtime is the path to the rt.jar file of Java 5.0 (note: you have to include rt.jar as part of the path.

Where code.java is Java code compatible with version 5.0.

Note: The mapping from Java version to command line attributes are:

  • Java 1.2 => 1.3 (unless there is a typo in the JDK 7 warning, it is 1.3 not 1.2)
  • Java 1.3 => 1.3
  • Java 1.4 => 1.4
  • Java 5.0 => 1.5
  • Java 6 => 1.6

Normally, you do not have to specify the -target option because by default it is set the same as the -source option.

For Other IDE Users

You will have to read (or explore) your IDE to determine where the compiler and target settings are located. It is probably a safe bet that they are part of the project options (try right-clicking on the project name and see if a menu pops up, or see if there is something like a Project Options setting somewhere.

More Information

These are external links and where deemed to be safe and relevant at the time of publication.

If there are problems with them, please let me know.

javac – Java programming language compiler – search for bootclasspath on the page

Java SE 7 and JDK 7 Compatibility – a discussion about Java 7 compatibility with previous versions