No com.sun.tools.javac in JDK7
It looks like you are using Eclipse. By default Eclipse only imports JRE jars, not the ones from the JDK.
Solution 1:
- Go to Eclipse preferences (on Windows: Window-->Preferences)
- Open the preference Java-->Installed JREs
- Select your JRE and press edit
- Use "Add external jars" to include the tools.jar (found in JDK_HOME/lib)
Solution 2:
Edit your project build path and add an external library: tools.jar found in JDK_HOME/lib
javac is in the JDK bin directory, but not the JRE bin.
I had a similar problem and it turned out that by mistake I had set my JAVA_HOME variable to the JRE instead of the JDK, i.e.,
C:\Program Files\Java\jre1.8.0_60 instead of
C:\Program Files\Java\jdk1.8.0_60
Because I "knew" that I had copied the correct directory name, it took me ages to see those two different characters and fix the problem.
You are better off using the JavaCompiler API, rather than attemtping to call javac directly which is in tools.jar The API will add this for you if you use it.