简体   繁体   English

Eclipse在Mac OS X上找不到默认的Java类

[英]Eclipse Can't find default Java Classes on Mac OS X

I have done Android and C development in my copy of Eclipse, but have never actually done Java strictly. 我已经在我的Eclipse副本中完成了Android和C开发,但实际上从未严格执行Java。 When I add code that compiles using "javac codename.java" to an eclipse project, eclipse gives me errors and can't recognize statements like import java.io.* . 当我在eclipse项目中添加使用“ javac codename.java”进行编译的代码时,eclipse会给我带来错误,并且无法识别import java.io. *之类的语句。 I believe this is due to a problem with my class path and I have tried adding some paths like library/system/java but have not had any success. 我相信这是由于我的类路径存在问题,并且我尝试添加一些路径,例如库/系统/ java,但没有成功。 Any ideas for a solution? 有解决方案的想法吗?

If Eclipse is having troubles with classes delivered by JDK, I would suggest checking out if it (thus - JDK) is properly installed. 如果Eclipse在JDK提供的类方面遇到麻烦,我建议您检查一下它(因此-JDK)是否已正确安装。 You may do that by going to menu Window > Preferences and started typing "jdk" in search input. 您可以执行以下操作:转到菜单窗口>首选项,然后开始在搜索输入中输入“ jdk”。 It should point You to Java > Installed JREs . 它应该将您指向Java>已安装的JRE Check if there is proper JDK installed (if not - You may add it there). 检查是否安装了正确的JDK(如果没有,则可以其中添加 )。 After that try to clean Your project - menu Project > Clean... . 之后,尝试清理您的项目-菜单项目>清理...。

Hope this helps, regards. 希望这会有所帮助,问候。

如果进入首选项对话框并转到Java / Installed JRE,请确保这些路径正确。

In order for Eclipse to recognize source files as Java and compile them, your project has to be a Java project. 为了使Eclipse将源文件识别为Java并将其编译,您的项目必须是Java项目。 Putting a .java file in a project that wasn't created via New / Java Project won't work. .java文件放入未通过New / Java Project创建的项目中将无法正常工作。

Please try creating a Java project and put your .java file in it. 请尝试创建一个Java项目,然后将您的.java文件放入其中。

On os x the default location (right now anyway) is /System/Library/Java/JavaVirtualMachines/[VERSION].jdk/Contents/Home 在os x上,默认位置(无论如何现在)是/System/Library/Java/JavaVirtualMachines/[VERSION].jdk/Contents/Home
The default location is available from /usr/libexec/java_home . 可从/usr/libexec/java_home获得缺省位置。
That said, I've never had any problems with eclipse not finding the jdk, usually it's all automatic. 就是说,我从来没有遇到过Eclipse找不到jdk的任何问题,通常这都是自动的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM