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

8

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?

Mcdermott answered 19/10, 2011 at 4:6 Comment(3)
NetBeans Forums: forums.netbeans.org/topic43819.htmlRutile
see #9165125 for a solution in case you are using mavenOdoriferous
This caused me a headache using String.join from Java 8 in a Maven build with source & target set to 7. I used the maven-enforcer-plugin's requireJavaVersion rule to enforce range <version>[1.7.0,1.7.0-79]</version> which at least breaks the build with a clear message rather than a test with obscure message.Benoni
T
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.

Thrips answered 21/8, 2012 at 7:26 Comment(2)
Great, though it seems easier just to use an older JDK to compile.Kalikalian
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.Ardis
S
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.

Saviour answered 1/4, 2015 at 6:54 Comment(0)
A
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. :-)

Ashelyashen answered 1/1, 2015 at 12:17 Comment(2)
"myProject>Properties>Source/Binary Format: JDK 7" worked for meCarbonization
Windows + Netbeans 12 by (code from jdk 8 to openjdk 11): solution from @DoctorParameter works for me.Darlleen
R
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.

Restrictive answered 31/5, 2013 at 13:41 Comment(4)
Please note, that's not a good idea to just shut up warnings like thisLemnos
agreed, but sometimes it is better to disable some warnings vs outputting hundreds of them so that your true warnings are hidden.Restrictive
Can someone give a minimal example of something that goes wrong by ignoring this warning?Saviour
See comment aboveWyn
T
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>
Tubing answered 30/10, 2019 at 6:56 Comment(2)
This fixed a problem I was struggling with for about an hour, I just couldn't see it.Somite
That doesn't fix the problem if what you want is to compile as version 8!Ardis
C
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
Caresa answered 7/3, 2021 at 22:26 Comment(0)
X
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

Xeniaxeno answered 17/9, 2023 at 4:58 Comment(1)
Please post descriptive answer with more details.Shiite
C
-2
  1. Download JDK (on warning written version) -> install

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

Cence answered 24/1, 2018 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.