[英]No com.sun.tools.javac in JDK7
I'm using JDK7 and Eclipse Indiago in Windows 7 64-bit. 我在Windows 7 64位中使用JDK7和Eclipse Indiago。 I set environment variable JAVA_HOME to F:\\JDK7 and add %JAVA_HOME%\\bin in path. 我将环境变量JAVA_HOME设置为F:\\ JDK7并在路径中添加%JAVA_HOME%\\ bin。 It's my sample code: 这是我的示例代码:
com.sun.tools.javac.Main m1 = new com.sun.tools.javac.Main();
m1.compile(source);
Error I get: 我得到的错误:
Type com.sun.tools cannot be resolved to a type 键入com.sun.tools无法解析为类型
Why there is no com.sun.tools ? 为什么没有com.sun.tools? What's the problem ? 有什么问题 ?
It looks like you are using Eclipse. 看起来你正在使用Eclipse。 By default Eclipse only imports JRE jars, not the ones from the JDK. 默认情况下,Eclipse只导入JRE jar,而不是JDK中的JAR jar。
Solution 1: 解决方案1:
Solution 2: 解决方案2:
Edit your project build path and add an external library: tools.jar found in JDK_HOME/lib 编辑项目构建路径并添加外部库:JDK_HOME / lib中的tools.jar
你最好使用JavaCompiler API ,而不是直接调用tools.jar中的javac。如果你使用它,API会为你添加它。
javac is in the JDK bin directory, but not the JRE bin. javac位于JDK bin目录中,但不在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, ie, 我有一个类似的问题,事实证明我错误地将我的JAVA_HOME变量设置为JRE而不是JDK,即,
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. 因为我“知道”我复制了正确的目录名,所以我花了很长时间才能看到这两个不同的字符并解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.