tools.jar not on classpath anymore?
I recently reformatted my system from Fedora 15 32 to Fedora 15 64-bit. I installed the 64-bit version of Java, started up a fresh Netbeans instance, tried to build my project which uses Project Lombok, and got this:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/parser/Scanner$Factory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at lombok.delombok.DelombokApp$1.loadStreamAsClass(DelombokApp.java:102)
at lombok.delombok.DelombokApp$1.loadClass(DelombokApp.java:117)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at lombok.delombok.Delombok.delombok(Delombok.java:358)
at lombok.delombok.Delombok.main(Delombok.java:190)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at lombok.delombok.DelombokApp.runApp(DelombokApp.java:55)
at lombok.core.Main.go(Main.java:127)
at lombok.core.Main.main(Main.java:41)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.parser.Scanner$Factory
at java.lang.ClassLoader.findClass(ClassLoader.java:522)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at lombok.delombok.DelombokApp$1.loadClass(DelombokApp.java:118)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 15 more
I have never gotten this error before. This particular error came from the Maven exec plugin trying to execute lombok to delombok some source code. On the old system this worked all the time without problems. Now its not.
What's puzzling is that on the old system it worked even though I used both Java 6 and later Java 7 without having to do anything special. I also frequently deleted Netbeans and its files, either upgrading to a new version or just wanting to speed it up again. So there isn't any special settings or checkboxes I might of changed in either program. Even then, I don't remember doing anything special to get it working.
Why 开发者_开发知识库am I all of a sudden getting this error? Why is tools.jar not automatically being added to the classpath? And if that's normal behavior, then how did it work before?
Today I finally figured out what the issue was: Java 6 was installed originally and I jumped straight to Java 7.
Essentially I was running Netbeans and Maven on Java 7 which was in a folder in my home folder. I had Java 6 actually installed in the OS and it was on my path. Apparently Java 6 (at least the Linux versions) includes tools.jar by default, which allows Lombok to execute correctly. Java 7 does not.
When the Maven Exec Plugin ran, it actually used Java 6 even though I had started Maven under Java 7. When Java 6 was replaced with 7, it no longer worked, causing this error.
does java link to the right version ?
java -version
type java
Regards, Stéphane
精彩评论