简体   繁体   English

JDK7中没有com.sun.tools.javac

[英]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:

  1. Go to Eclipse preferences (on Windows: Window-->Preferences) 转到Eclipse首选项(在Windows上:窗口 - >首选项)
  2. Open the preference Java-->Installed JREs 打开首选项Java - > Installed JREs
  3. Select your JRE and press edit 选择您的JRE并按编辑
  4. Use "Add external jars" to include the tools.jar (found in JDK_HOME/lib) 使用“添加外部jar”包含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

你最好使用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.

相关问题 Java 11 将 jdk.compiler/com.sun.tools.javac 类包含到项目中 - Java 11 include jdk.compiler/com.sun.tools.javac classes into project 模块 jdk.compiler 不会“打开 com.sun.tools.javac.processing” - module jdk.compiler does not "opens com.sun.tools.javac.processing" 环境(在模块 jdk.compiler 中),因为模块 jdk.compiler 不会将 com.sun.tools.javac.processing 导出到未命名的模块 - Environment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing to unnamed module com.sun.tools.javac.Main不在类路径中 - com.sun.tools.javac.Main is not on the classpath 模块 jdk.compiler 不会“打开 com.sun.tools.javac.processing”到未命名的模块 @4bae33a6 - module jdk.compiler does not “opens com.sun.tools.javac.processing” to unnamed module @4bae33a6 JDK6-> JDK7无法使用com.sun.xml.internal.stream.XMLInputFactoryImpl - JDK6 -> JDK7 cant use com.sun.xml.internal.stream.XMLInputFactoryImpl JDT编译器中的com.sun.tools.javac.jvm.ClassWriter等效项 - com.sun.tools.javac.jvm.ClassWriter equivalent in JDT compiler com.sun.tools.javac.util 在 openjdk 8 中可用吗? - Is com.sun.tools.javac.util available in openjdk 8? 错误:包 com.sun.tools.javac.util 不存在 - error: package com.sun.tools.javac.util does not exist java.lang.NoClassDefFoundError:com / sun / tools / javac / Main - java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM