无法找到javac编译器com.sun.tools.javac.Main不在类路径错误上 [英] Unable to find a javac compiler com.sun.tools.javac.Main is not on the classpath error

查看:1382
本文介绍了无法找到javac编译器com.sun.tools.javac.Main不在类路径错误上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行java应用程序并且出现以下错误,

I am trying to run java application and I am getting following error,


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

Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK

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

I have gone through many SO questions and found solution is JAVA_HOME should be point to JDK, not JRE.

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

Then I have tried to print JAVA_HOME in command prompt,

我已设置此JAVA_HOME从我的电脑 - > properties-> env变量 - >系统变量如下,

I had set this JAVA_HOME from my computer->properties->env variables -> system vars as below,

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

I had also added new variable in eclipse using preferences as,

最后我仍然得到同样的错误。 JAVA_HOME怎么了?

And finally I am still getting the same error. Whats wrong with JAVA_HOME ?


更新:

Update :

eclipse-preferences-installed jres 中只有一个条目存在且是jdk并被选中,

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

并在<$下c $ c>项目属性 java构建路径 - 使用JRE System Liberary [jdk1.8.0_31]


更新1:

Update 1 :

C:\Program Files\Java\jdk1.8.0_31 包含名为 JRE 。那个 jre 文件夹导致了这个问题吗?我可以删除这个文件夹吗?有没有办法在项目中只添加jdk liberary?

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 ?

推荐答案

Eclipse是一个IDE,因此它有(在至少)两个Java版本:它使用自己运行的版本( JAVA_HOME )和用于运行应用程序的JVM。两者不需要相同。

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.

因此,为了解决您的问题,您需要查看Eclipse的首选项,特别是已安装的JRE 它为您提供了Eclipse将用于从项目运行Java代码的Java VM列表。我的猜测是那里会有几个条目,默认是JRE而不是JDK。

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.

确保列表中有JDK,然后转到你的项目。在项目中,您可以在 Java构建路径 - > 下选择要使用的Java VM。

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.


仔细查看最后一个屏幕截图:您已将Eclipse配置为使用 C:\Program Files\Java\jdk1.8.0_31\jre 这意味着您已将其指向JDK内部的JRE。使用 C:\Program Files\Java \ _jdk1.8.0_31 代替(不包含 \ jre at at结束)。

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).

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

If you delete the jre folder, Java will stop working. Any JDK also contains a JRE. The JRE contains rt.jar with String.class and the like. The Java compiler is in tools.jar which is in the JDK.

如果在Eclipse中重新创建JRE条目没关系,你必须手动将它添加到类路径中。

If recreating the JRE entry in Eclipse doesn't help, you'll have to add it manually to the classpath.

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

You can use a variable ("Add Variable...") to make sure Eclipse updates the path when you switch to a new/different JRE. Try JAVA_HOME with the extension lib/tools.jar

这篇关于无法找到javac编译器com.sun.tools.javac.Main不在类路径错误上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆