简体   繁体   English

Eclipse项目无法识别Java项目; 类路径问题

[英]Java projects not being recognized by Eclipse; classpath problems

I am a very inexperienced programmer. 我是一个非常缺乏经验的程序员。 I have just taken a weeklong class on Java programming in Eclipse. 我刚刚在Eclipse中学习了一周的Java编程课程。 When I got home and installed Eclipse on my home computer, I was able to bring up the program I made in the editor but Eclipse would not run it; 当我回到家并在家用计算机上安装Eclipse时,我能够调出我在编辑器中创建的程序,但Eclipse不会运行它; it only accepted .ant files. 它只接受.ant文件。

I was able to get projects to show up in the Project Explorer (by importing them) and change the classpath to recognize those projects, but nothing shows up as an option to select a main class in run>run configurations>Java application. 我能够在Project Explorer中显示项目(通过导入它们)并更改类路径以识别这些项目,但没有任何内容显示为在运行>运行配置> Java应用程序中选择主类的选项。 I am very confused as I have not been taught to use these features of Eclipse in the one week of Java experience I have. 我很困惑,因为我没有被教过在一周的Java经验中使用Eclipse的这些功能。 Any help would be very much appreciated. 任何帮助将非常感谢。

Update : When I try to configure the build path/classpath, I still have no options for selecting a main class in run>run configurations>Java application, even after following Logan's advice. 更新 :当我尝试配置构建路径/类路径时,即使按照Logan的建议,我仍然没有选择运行>运行配置> Java应用程序中的主类的选项。 The JRE system library is still on the build path, but there's a red X on its icon in my project's properties.Plus, this is also at the top of my project's Properties window: JRE系统库仍然在构建路径上,但是在我的项目的properties.Plus中,它的图标上有一个红色X,这也是我项目的Properties窗口的顶部:

"Build path entry is missing: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7 “缺少构建路径条目:org.eclipse.jdt.launching.JRE_CONTAINER / org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType / JavaSE-1.7

To make matters worse, when I click the Run button, the options for the type of file to run the script depend on what I have selected. 更糟糕的是,当我单击“运行”按钮时,运行脚本的文件类型选项取决于我选择的内容。 If I've selected the project in the Project Explorer, the options are Java Applet and Java Application, but if I've selected the code in the display, the .ant file options come up. 如果我在Project Explorer中选择了项目,则选项是Java Applet和Java Application,但如果我在显示中选择了代码,则会出现.ant文件选项。

Plus, there is no # in front of the name of the source folder. 另外,源文件夹名称前面没有#。

One more important piece of info: The Eclipse SDK folder never downloaded, for some reason. 另一个重要信息:由于某些原因,Eclipse SDK文件夹从未下载过。 However, I extracted all the .zip files in the Juno folder and the Eclipse application did appear. 但是,我解压缩了Juno文件夹中的所有.zip文件,并且Eclipse应用程序确实出现了。

Help would be appreciated, especially as literal, straightforward directions on what to do. 我们将非常感谢您的帮助,特别是关于如何做的直接指示。 Thank you. 谢谢。

I think I have run into this before. 我想我以前遇到过这种情况。 You need to add the JRE System Library to your project build path libraries. 您需要将JRE系统库添加到项目构建路径库中。

Your project in the Package Explorer should show the JRE System Library after your source folder if you have one. Package Explorer中的项目应该在源文件夹后显示JRE系统库(如果有)。

  • Right click on your project and choose properties. 右键单击您的项目并选择属性。
  • Click on the Java Build Path option in the left side tree of options. 单击选项左侧树中的Java Build Path选项。
  • On the Java Build Path window, click on the Libraries Tab. 在Java Build Path窗口中,单击Libraries选项卡。
  • Make sure JRE System Library is listed, if it is not, then click Add Library button. 确保列出了JRE System Library,如果不是,则单击Add Library按钮。
  • Then Choose JRE System Library, Then you can point to one or use the one Eclipse uses. 然后选择JRE System Library,然后你可以指向一个或使用Eclipse使用的那个。
  • Click finish and then go back to your project. 单击完成,然后返回到您的项目。

Also check that your source code folder is on the build path of the project. 还要检查源代码文件夹是否在项目的构建路径中。 Your source folder should have the # in front of the name like #src if that folder is on the build path. 如果该文件夹位于构建路径上,则源文件夹应在#src之类的名称前面加上#。 If it does not have the # sign, you may need to right click on that folder with your code and add it to the build path. 如果它没有#符号,您可能需要用您的代码右键单击该文件夹并将其添加到构建路径。

我通过转到Eclipse - >首选项 - > java - >安装jre解决了这个问题 - >在我的案例中选择标准Vm(Mac OSX)/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/ Home.Finish

First of all you have to make sure you have Eclipse for JAVA installed. 首先,您必须确保安装了Eclipse for JAVA。 You have to know that eclipse has its own structure when it comes to Java projects. 你必须知道eclipse在Java项目中有自己的结构。 Follow this tutorial which I think may help you a lot. 按照本教程,我认为可能会对您有所帮助。

http://eclipsetutorial.sourceforge.net/totalbegginer01/lesson01.html http://eclipsetutorial.sourceforge.net/totalbegginer01/lesson01.html

Most IDEs, including eclipse, do not run files (at least not in a straightforward way), so you must create a project and import your existing (.java) files to it. 大多数IDE(包括eclipse)都不运行文件(至少不是以直接的方式),因此您必须创建一个项目并将现有(.java)文件导入其中。

Using Eclipse JUNO set the java environment to configure the FX project. 使用Eclipse JUNO设置java环境来配置FX项目。

  • Go to Window --> Preferences 转到窗口 - >首选项
  • Select the Installed JREs 选择已安装的JRE
  • Add missing JRR (7) 添加缺少的JRR(7)

Then after create the JavaFx project. 然后创建JavaFx项目。

Ashok Parmar Ashok Parmar

For Java 1.7 or 1.8 on Mac OSX you can follow these steps: 对于Mac OSX上的Java 1.71.8 ,您可以按照以下步骤操作:

  1. Use /usr/libexec/java_home -v 1.8 command on a terminal shell to find your java 1.8 home directory. 在终端shell上使用/usr/libexec/java_home -v 1.8命令查找java 1.8主目录。
  2. Go to Eclipse ->Preferences->Java->Installed JREs and press Add button and then select Standard VM and as in my case add /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home 转到Eclipse ->Preferences->Java->Installed JREs ,然后按Add按钮,然后选择Standard VM ,在我的例子中添加/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home

This error is due to JRE System Library. 此错误是由JRE系统库引起的。 Maybe you didn't give appropriate JRE for eclipse project to run. 也许你没有为eclipse项目提供适当的JRE来运行。 So follow below steps. 请按照以下步骤操作。

  1. Right-click on the project and choose properties. 右键单击项目并选择属性。
  2. Click on the Java Build Path option in the left side menu. 单击左侧菜单中的Java Build Path选项。
  3. From the Java Build Path window, click on the Libraries Tab. 在Java Build Path窗口中,单击Libraries选项卡。
  4. Make sure JRE System library is listed, if it is not listed then you can add, by clicking "Add Library" from the right side menu. 确保列出了JRE系统库,如果未列出,则可以通过单击右侧菜单中的“添加库”添加。
  5. So if JRE System Library is already listed then double click on JRE System Library which was showing error on Java Build Path window Libraries tab previously . 因此,如果已经列出了JRE系统库,则双击 JRE系统库,该库在之前的Java Build Path窗口Libraries选项卡上显示错误。
  6. Then it will open another window called JRE System Library . 然后它将打开另一个名为JRE System Library的窗口。 So in that window choose Alternate JRE . 所以在那个窗口中选择Alternate JRE From that drop down choose your JRE. 从下拉菜单中选择您的JRE。

In my case, it is java-8-openjdk-amd64 , as I am using ubuntu 16.04. 就我而言,它是java-8-openjdk-amd64,因为我使用的是ubuntu 16.04。 Like that you can also choose your JRE System library . 像这样你也可以选择你的JRE系统库。

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

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