Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 591
spade4acer Avatar asked Nov 27 '22 04:11

spade4acer


2 Answers

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.

like image 125
Logan Avatar answered Dec 05 '22 18:12

Logan


I solved it by going to Eclipse ->preferences-->java-->installed jre --> select a standard Vm in my case (Mac OSX) /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home.Finish

like image 21
madhu prasad Avatar answered Dec 05 '22 18:12

madhu prasad