
代码
import com.sun.tools.javac.util.Abort; // 来自 tools.jar 中的类 public class Test { public static void main(String[] args) { System.out.println("hello world"); } } 使用 javac 来编译, 报如下错误
程序包 com.sun.tools.javac.util 不存在
使用的是 jdk1.8
有铁子知道原因么?
1 yzmm 2021 年 6 月 22 日 Linux: javac -cp $JAVA_HOME/lib/tools.jar Test.java Windows: javac -classpath %JAVA_HOME%/lib/tools.jar Test.java |
2 ThreeBody 2021 年 6 月 22 日 如果你的是 maven 项目的话,可以直接引入依赖 <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.8</version> <scope>system</scope> <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath> </dependency> |
3 zm8m93Q1e5otOC69 2021 年 6 月 22 日 This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk. * This code and its internal interfaces are subject to change or * deletion without notic |