bootstrap class path not set

好久不见. 提交于 2019-12-03 22:12:32
toomasr

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.

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!