bootstrap class path not set

Stephopolis picture Stephopolis · Apr 8, 2013 · Viewed 27.9k times · Source

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.

Answer

toomasr picture toomasr · Apr 8, 2013

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.