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?
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.
rt.jar
because Java 11 doesn't seem to have this file at all. –
Ardis 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.
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. :-)
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.
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>
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
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
Download JDK (on warning written version) -> install
Right click your project -> Properties -> Libraries -> Java platform (add your installed JDK) -> OK
© 2022 - 2024 — McMap. All rights reserved.
<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