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

Java

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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.

Solution 3 - Java

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. :-)

Solution 4 - Java

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.

Solution 5 - Java

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>

Solution 6 - Java

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

Solution 7 - Java

  1. Download JDK (on warning written version) -> install

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamView Question on Stackoverflow
Solution 1 - JavaEduard WirchView Answer on Stackoverflow
Solution 2 - JavaCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow
Solution 3 - Javan9dyfiView Answer on Stackoverflow
Solution 4 - JavaNeonView Answer on Stackoverflow
Solution 5 - JavaSandeep TView Answer on Stackoverflow
Solution 6 - JavaJozielView Answer on Stackoverflow
Solution 7 - JavaErasyl AbenovView Answer on Stackoverflow