28

So I am getting- warning: [options] bootstrap class path not set in conjunction with -source 1.6

And I am about to ask 3 questions about it. I understand that I need to set the bootstrap class path but I am not sure I understand how. A quick google just sent me to pages that quoted from the Oracle page, but I read the Oracle page and didn't feel that I understood it particularly well.

I am currently running this code on Netbeans, so all I have to do is hit the play button for it to compile and run. Is there a property that dictates how this will compile so that I may add in the bootstrap class path?

Also, for the coming eventuality that I will take it off running only on Netbeans and run it from the commandline, what is the correct way to compile with the bootstrap class path there? They say $ javac -source 6 HelloWorld.java but would just stating -source 1.6 really be the solution?

Perhaps an even greater question in, how do I avoid this type of warning in the future? If I understand even a little bit, I am referencing an old java source and therefore older methods. I am not sure how or when that happened.

Stephopolis
  • 1,765
  • 9
  • 36
  • 65

5 Answers5

44

You are doing cross compiling. You are using a JDK 7 compiler to compile classes for JDK 6. This is okay but to avoid problems the compiler wants to get its hands on JDK 6 rt.jar. The reasoning behind that is that you actually might generate classes that don't work with JDK 6 because you might be using the old language rules (in this case 1.6) but the brand new bootstrap classes. Some methods might not be present in the older JDK for example. So you get your compilation done but once you run the program it might blow up with a MethodNotFoundException.

Couple of solutions, you can just pick one

  • Specify rt.jar from JDK 6. Why not use the older compiler than even?
  • Use JDK 6 compiler (it has rt.jar included). Why even use 7 if no 7 features are needed.
  • Ignore the warning and have good test coverage to make sure you don't use Java 7 features
    • I don't know about NetBeans but in Eclipse you can also say that you are compiling against JDK 6 so it won't actually compile if you use Java 7 features.
  • Change business needs and compile for Java 7.
Michael Mior
  • 28,107
  • 9
  • 89
  • 113
toomasr
  • 4,731
  • 2
  • 33
  • 36
  • 10
    Downvoting because several solutions are given with no instruction at all how to do them. – seansand Jan 31 '14 at 17:17
  • @toomasr Please understand that going back to an older JDK is easy working on your local machine (MacOs being one exception btw). When working for (larger) companies, you all too often can't change your JDK. For example, you are bound to use 1.7 on your development machine while the server you target is still stuck with 1.6. Of course you can now wait until they (server admins) eventually move to 1.7 or you behave like a professional and get your job done. What would be your choice? – wh81752 Jul 02 '14 at 09:54
  • @whaefelinger if you are stuck on JDK7 on local machine and JDK6 in production then have to make sure that source level is set 1.6 everywhere and if you have a CI server make sure to use JDK1.6 there. There isn't much more you can do. – toomasr Jul 03 '14 at 10:55
  • 1
    +2 for good, helpful insight & some nice solutions, -1 for not providing the (quite useful IMO) details `seansand` mentioned... well, it's still +1 in total in my book. –  Apr 27 '15 at 22:44
  • 3
    Regarding how to do... During compilation add this option javac -bootclasspath C:\Java\jre\1.6.0\lib\rt.jar – Hemang Jan 28 '16 at 08:16
  • 2
    @Hemang see the cross compilation section at http://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html for commandline details. – toomasr Jan 29 '16 at 08:22
  • bootstrap class path not set in conjunction with -source 1.7 not resolved for me for Spring application. – Prasad Shinde Nov 15 '17 at 17:31
  • I was able to resolve this problem by going to Project --> Properties --> Sources change Source/Binary Format from JDK 6 to JDK 8. – Jim Fell Apr 12 '19 at 15:06
3

I understand that I need to set the bootstrap class path but I am not sure I understand how.

In Netbeans 8.0.2, go to:

Run > Set Project Configuration > Customise...

In the Categories window, go to:

Build > Compiling

The bottom field is "Additional Compiler Options" to which you can add:

-bootclasspath /your/path/to/lower/java/version/lib/rt.jar
MT0
  • 143,790
  • 11
  • 59
  • 117
2

Was having the same Warning compiling on console on macOS. Here the compiler-option to be added is

-bootclasspath /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar

Note that on macOS, for Java versions <= 1.6 (those released by Apple) the rt.jar is called classes.jar

nhaggen
  • 301
  • 2
  • 8
1

In my case maven was using the another java version and I fixed it by changing the required java version in maven.

vsharma
  • 299
  • 3
  • 3
0

Just go right click on the Project properties and then go to Binding and choose the JDK 1.7 provided you are using it's features in your NetBeans project and this is the reason why are you getting the problem. This will help solve the problem and worked for me.