简体   繁体   中英

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. 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; it only accepted .ant files.

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

"Build path entry is missing: 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.

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. However, I extracted all the .zip files in the Juno folder and the Eclipse application did appear.

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.

Your project in the Package Explorer should show the JRE System Library after your source folder if you have one.

  • Right click on your project and choose properties.
  • Click on the Java Build Path option in the left side tree of options.
  • On the Java Build Path window, click on the Libraries Tab.
  • Make sure JRE System Library is listed, if it is not, then click Add Library button.
  • Then Choose JRE System Library, Then you can point to one or use the one Eclipse uses.
  • 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. 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. You have to know that eclipse has its own structure when it comes to Java projects. Follow this tutorial which I think may help you a lot.

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.

Using Eclipse JUNO set the java environment to configure the FX project.

  • Go to Window --> Preferences
  • Select the Installed JREs
  • Add missing JRR (7)

Then after create the JavaFx project.

Ashok Parmar

For Java 1.7 or 1.8 on Mac OSX you can follow these steps:

  1. Use /usr/libexec/java_home -v 1.8 command on a terminal shell to find your java 1.8 home directory.
  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

This error is due to JRE System Library. Maybe you didn't give appropriate JRE for eclipse project to run. 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.
  3. From the Java Build Path window, click on the Libraries Tab.
  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.
  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 .
  6. Then it will open another window called JRE System Library . So in that window choose Alternate JRE . From that drop down choose your JRE.

In my case, it is java-8-openjdk-amd64 , as I am using ubuntu 16.04. Like that you can also choose your JRE System library .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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