javac.main.java,无法找到javac编译器com.sun.tools.javac.Main不在类路径错误上

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

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

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

Then I have tried to print JAVA_HOME in command prompt,

5aZG7.png

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

ECm0W.png

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

0SG9E.png

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

Update :

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

hlun4.png

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

zyWhC.png

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 ?

解决方案

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

[EDIT 2] 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.

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值