找不到javac编译器com.sun.tools.javac.Main不在classpath上

Nishant Nawarkhede:

我正在尝试运行Java应用程序,但出现以下错误,

找不到javac编译器;com.sun.tools.javac.Main不在类路径中。也许JAVA_HOME没有指向JDK

我经历了很多SO问题,发现解决方案是JAVA_HOME应该指向JDK,而不是JRE

然后我尝试在命令提示符下打印JAVA_HOME,

在此处输入图片说明

我已经从我的计算机->属性->环境变量->系统变量中设置了JAVA_HOME,如下所示,

在此处输入图片说明

我还使用首选项在eclipse中添加了新变量,

在此处输入图片说明

最后,我仍然遇到相同的错误。JAVA_HOME有什么问题?

更新:

In eclipse-preferences-installed jres there is only one entry is present and which is jdk and selected,

在此处输入图片说明

And under project properties java build path-libraries there is JRE System Liberary [jdk1.8.0_31] is used.

在此处输入图片说明

Update 1 :

C:\Program Files\Java\jdk1.8.0_31 have folder named jre. Is that jre folder causing this issue ? Can I remove this folder ? Is there is any way to add only jdk liberary in project ?

Aaron Digulla :

Eclipse is an IDE and as such, it has (at least) two Java versions: The one which it uses itself to run (JAVA_HOME) and a JVM which it uses to run your application. The two don't need to be the same.

So to fix your problem, you need to look into Eclipse's preferences, specifically Installed JREs which gives you a list of Java VMs which Eclipse will use to run Java code from projects. My guess is that there will be several entries there and the default will be a JRE instead of a JDK.

Make sure you have a JDK in the list and then go to your project. In the project, you can select which Java VM to use under Java Build Path -> Libraries.

[EDIT] Look closely at the last screenshot: You've configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre which means you've pointed it at the JRE inside of the JDK. Use C:\Program Files\Java\jdk1.8.0_31 instead (without the \jre at the end).

[编辑2]如果删除jre文件夹,Java将停止工作。任何JDK也包含一个JRE。JRE包含rt.jarwith String.class等。Java编译器tools.jar位于JDK中。

如果在Eclipse中重新创建JRE条目无济于事,则必须手动将其添加到类路径中。

您可以使用变量(“添加变量...”)来确保当您切换到新的/不同的JRE时Eclipse更新了路径。尝试JAVA_HOME扩展lib/tools.jar

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

编译器错误-“错误:找不到或加载主类com.sun.tools.javac.Main”

编译器错误:com.sun.tools.javac.code.Symbol $ CompletionFailure:找不到rx.Observable的类文件

编译器错误:com.sun.tools.javac.code.Symbol $ CompletionFailure:找不到akka.actor.SupervisorStrategy $ 1的类文件

Hadoop“无法找到或加载主类com.sun.tools.javac.Main”

从Java访问com.sun.tools.javac.util 9

找不到Javac编译器

java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: 找不到 org.bouncycastle.asn1.DERInteger 的类文件

compileReleaseKotlin失败,并出现java.lang.ClassNotFoundException:com.sun.tools.javac.util.Context

使用maven构建项目时出错[com / sun / tools / javac / tree / JCTree $ JCCompilationUnit]

JDK7中没有com.sun.tools.javac

错误:程序包com.sun.tools.javac.util不存在

为什么getSimpleName()在com.sun.tools.javac.tree.JCTree $ JCClassDecl中是两次

如何将com.sun.tools.javac.code.Attribute导入kotlin模块?

Sun JRE Javac和Eclipse Java编译器之间不一致?

java.lang.IllegalAccessError: 类 lombok.javac.apt.LombokProcessor 无法访问类 com.sun.tools.javac.processing.JavacProcessingEnvironment

由以下原因引起:java.lang.ClassNotFoundException:使用lombok时com.sun.tools.javac.code.TypeTags

找不到使用Javac Main Class编译的Ant

在Javac中使用内部Sun类

Java、Intellij IDEA 问题无法识别的选项:--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED

标准Sun javac可以进行增量编译吗?

Kivy Apk build with buildozer错误:#找不到Java编译器(javac),请安装

无法找到Javac编译器

Javac是Oracle Java编译器吗?

使用Javac的StanfordCoreNLP编译器错误

Java注释-Javac编译器错误?

Sun的javac产生的奇怪异常表条目

JLS如何与Sun javac对应/为什么不匹配

找不到javac

javac:找不到命令