Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap class path not set

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.

like image 757
Stephopolis Avatar asked Apr 08 '13 15:04

Stephopolis


3 Answers

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.
like image 160
toomasr Avatar answered Nov 18 '22 09:11

toomasr


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
like image 30
MT0 Avatar answered Nov 18 '22 09:11

MT0


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

like image 2
nhaggen Avatar answered Nov 18 '22 07:11

nhaggen