December 11, 2013 Leave a comment
This article explains how to configure the Netbeans IDE to recognize java code the uses compiler internal classes. These classes are not part of the standard JDK and are not recognized by IDEs such as Netbeans, which will refuse to compile the correct code.
The compiler internal classes are used mainly as a hack to define annotations that automatically generate code. The most significant example is the Project Lombok, which transparently generates getters, setters and other code bload. Under the hood, the “Pluggable Annotation Processing API” (JSR 269) provides a mechanism that exposes internal classes from the java compiler. These classes provide methods that allow us change the abstract syntax tree.
In order to configure Netbeans IDE to recognize the java compiler internal classes, one needs to add the them to the compiler class path. These classes are found within the lib/tools.jar library within the JDK 6 or 7. In order to add this library to the class path, the following procedure may work:
- Open the Netbeans IDE, open the Java Platform Manager (menu Tools->Java Platforms). The dialog will list, one the left side, one or more JDKs, one of them marked as default. On the right side, all jar from the compiler bootstrap classpath are listed. We need to add the lib/tools.jar into the list, which is not possible from the dialog.
- Click on “Add Platform” and follow the wizard to add the same default platform again, but using another name, for exemple, “JDK 1.7 – javac”.
- Close the dialog and the Netbeans IDE.
- Open the xml file: C:\Users\name\AppData\Roaming\NetBeans\7.4\config\Services\Platforms\org-netbeans-api-java-Platform\JDK_1.7_-_javac.xml. The path may vary according to your operating system, user name and Netbeans IDE version.
- Scan through the xml file for the “sun.boot.class.path” property.
- Add the full absolute path of the JDK lib/tools.jar file, don’t forget the “:” separator.
- Open the Netbeans IDE again, open the Java Platform Manager.
- Make sure that the right side lists the lib/tools.jar file.
- Close the dialog.
- Open your project properties, go to the libraries tab.
- Change the Java Platform field to “JDK 1.7 – javac”.