JDK7中没有com.sun.tools.javac [英] No com.sun.tools.javac in JDK7
问题描述
我正在Windows 7 64位中使用JDK7和Eclipse Indiago.我将环境变量JAVA_HOME设置为F:\ JDK7并在路径中添加%JAVA_HOME%\ bin.这是我的示例代码:
I'm using JDK7 and Eclipse Indiago in Windows 7 64-bit. I set environment variable JAVA_HOME to F:\JDK7 and add %JAVA_HOME%\bin in path. It's my sample code:
com.sun.tools.javac.Main m1 = new com.sun.tools.javac.Main();
m1.compile(source);
我得到的错误:
com.sun.tools类型无法解析为 键入
Type com.sun.tools cannot be resolved to a type
为什么没有com.sun.tools?有什么问题吗?
Why there is no com.sun.tools ? What's the problem ?
推荐答案
似乎您正在使用Eclipse.默认情况下,Eclipse仅导入JRE jar,而不从JDK中导入.
It looks like you are using Eclipse. By default Eclipse only imports JRE jars, not the ones from the JDK.
解决方案1:
- 转到Eclipse首选项(在Windows上:Window-> Preferences)
- 打开首选项Java->已安装的JRE
- 选择您的JRE,然后按Edit
- 使用添加外部jar"来包含tools.jar(位于JDK_HOME/lib中)
解决方案2:
编辑您的项目构建路径并添加一个外部库:在JDK_HOME/lib中找到的tools.jar
Edit your project build path and add an external library: tools.jar found in JDK_HOME/lib
这篇关于JDK7中没有com.sun.tools.javac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!