Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Could not find or load main class in Eclipse

Tags:

eclipse

I'm having trouble running a project in Eclipse 4.2. I have a Java program with one class titled Conversion. Eclipse builds the project fine. I'm able to run the program from the command line by navigating to /bin/ in the project's folder that's in the workspace and typing java Conversion.

However, when I try to run the program from Eclipse, I am shown Error: Could not find or load main class Conversion in the console.

The project name is 10.12.12: Project.

like image 249
Zach Latta Avatar asked Sep 16 '12 09:09

Zach Latta


3 Answers

It appears that the project is not part of the classpath.
Check in your Run Configuration->Classpath and if your project is not there, then add it under User Entries.

enter image description here

enter image description here

like image 66
Cratylus Avatar answered Nov 02 '22 06:11

Cratylus


I understand the ':' was likely the case here, but I had a tangential issue that might help someone else.

I inherited a project and was having a similar issue. Dev/Debugging is on Mac/Win, and the TST/UAT/PRD environment is RHEL. Someone literally copied the systemd command line and left a '\' in the Debug arguments. The reason this was hard to find is that the lines wrap right at the -D, so the \ is the last char on a line, which looks OK under Linux. I fixed it like this...

In my case it was...

-Dlog4j.configurationFile=file:<PATH>/log4j2.xml \
-DCONFIG_PATH=...

Right-Click Project -> Run-As/Debug-As, click the Arguments Tab.
In the VM Arguments, look for \.  

HTH.

like image 31
FederOnline Avatar answered Nov 02 '22 08:11

FederOnline


Eclipse does not support the use of a colon or hyphen in project names. Colons appear to break the way it handles compilation.

The issue can be fixed by not using a colon in the project's name.

As noted in the comments, this may be a fault of Java 6. It is fixed in Java 7.

like image 38
Zach Latta Avatar answered Nov 02 '22 07:11

Zach Latta