147

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?

3

8 Answers 8

105

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.

2
  • 11
    Great, though it seems easier just to use an older JDK to compile.
    – dhardy
    Jul 16, 2014 at 13:34
  • I am using a Java 11 compiler to compile a Java 8 project. It is not clear what I should use for rt.jar because Java 11 doesn't seem to have this file at all. Jul 27, 2023 at 19:57
42

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.

5

I'm currently running Netbeans IDE 8.0.2 with JDK 1.8 on Linux Mint 17.1 which has java -version = 1.7.0_65. So to be able to run JAR files I had to set myProject>Properties>Source/Binary Format: JDK 7. However when building (myProject>Clean and Build) I got a similar warning: warning: [options] bootstrap class path not set in conjunction with -source 1.7.

The solution was to add the Linux Mint JDK1.7 platform to the Netbeans platform list.

This can be done by going to myProject>Properties>Libraries and clicking the Manage Platforms... button. Then in the Java Platform Manager window click Add Platform... and select: Java Standard Edition, click Next and browse to /usr/lib/jvm/java-7-openjdk-amd64 (or whatever is the location of the JDK 1.7 version). The Platform name will be set to JDK1.7. Just click Finish and you're done.

You can now select the Java platform in the project properties. By selecting JDK1.7 and running Clean and Build: no more warnings. :-)

2
  • 2
    "myProject>Properties>Source/Binary Format: JDK 7" worked for me Mar 18, 2016 at 12:34
  • Windows + Netbeans 12 by (code from jdk 8 to openjdk 11): solution from @DoctorParameter works for me.
    – Jaja
    Feb 15, 2021 at 15:30
3

The warning can be disabled with a new JDK 7 suboption within the -Xlint family, -Xlint:-options. e.g.

$ javac -source 1.5 -Xlint:-options example.java

sources: https://blogs.oracle.com/darcy/entry/bootclasspath_older_source

and

http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html#xlintwarnings

Warnings That Can Be Enabled or Disabled with -Xlint Option

Enable warning name with the option -Xlint:name, where name is one of the following warning names. Similarly, you can disable warning name with the option -Xlint:-name: ...

options Warn about issues relating to the use of command line options. See Cross-Compilation Example for an example of this kind of warning.

4
  • 41
    Please note, that's not a good idea to just shut up warnings like this Aug 2, 2013 at 4:57
  • 9
    agreed, but sometimes it is better to disable some warnings vs outputting hundreds of them so that your true warnings are hidden.
    – Neon
    Sep 17, 2013 at 17:00
  • 3
    Can someone give a minimal example of something that goes wrong by ignoring this warning? Mar 18, 2015 at 8:10
  • 1
    See comment above
    – real_paul
    Jan 12, 2016 at 10:29
2

Ensure your jdk version and the java compiler source version are the same. For example if you are using maven, and have setup the project using JDK 9, then following pom snippet would through above warning

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    ...
                </configuration>
            </plugin>

Correcting the source/target version to 9 fixes the warning as below

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                    ...
                </configuration>
            </plugin>
2
  • 1
    This fixed a problem I was struggling with for about an hour, I just couldn't see it. Nov 14, 2019 at 2:01
  • That doesn't fix the problem if what you want is to compile as version 8! Jul 27, 2023 at 20:01
1

If you are on Windows using the Apache NetBeans IDE:

1 - Check which Java version is selected at:

Menu Bar -> Tools -> Options -> Java -> Java Platform

2 - Select the same Java version at:

Menu Bar -> Run -> Set Project Configuration -> Customize... -> Sources -> Source/Binary Format
0

I managed to change the source (in Netbeans), by right-clicking the libraries folder, selecting properties, and then source, change the source to the recommended option enter image description here

1
  • 1
    Please post descriptive answer with more details. Sep 19, 2023 at 3:45
-2
  1. Download JDK (on warning written version) -> install

  2. Right click your project -> Properties -> Libraries -> Java platform (add your installed JDK) -> OK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.