java JDK7 中没有 com.sun.tools.javac
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10314904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No com.sun.tools.javac in JDK7
提问by linker
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:
我在 Windows 7 64 位中使用 JDK7 和 Eclipse Indiago。我将环境变量 JAVA_HOME 设置为 F:\JDK7 并在路径中添加 %JAVA_HOME%\bin 。这是我的示例代码:
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 ? What's the problem ?
为什么没有 com.sun.tools ?有什么问题 ?
回答by Guillaume Polet
It looks like you are using Eclipse. By default Eclipse only imports JRE jars, not the ones from the JDK.
看起来您正在使用 Eclipse。默认情况下,Eclipse 只导入 JRE jar,而不是来自 JDK 的那些。
Solution 1:
解决方案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)
- 转到 Eclipse 首选项(在 Windows 上:窗口-->首选项)
- 打开首选项 Java-->Installed JREs
- 选择您的 JRE 并按编辑
- 使用“添加外部 jars”来包含 tools.jar(在 JDK_HOME/lib 中找到)
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
回答by Peter Lawrey
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.
您最好使用JavaCompiler API,而不是尝试直接调用 tools.jar 中的 javac 如果您使用它,API 将为您添加它。
回答by cowang
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, i.e.,
我有一个类似的问题,结果我错误地将我的 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.
因为我“知道”我复制了正确的目录名称,所以我花了很长时间才能看到这两个不同的字符并解决问题。