我正在尝试运行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 ?
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.jar
with String.class
等。Java编译器tools.jar
位于JDK中。
如果在Eclipse中重新创建JRE条目无济于事,则必须手动将其添加到类路径中。
您可以使用变量(“添加变量...”)来确保当您切换到新的/不同的JRE时Eclipse更新了路径。尝试JAVA_HOME
扩展lib/tools.jar
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句