Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse doesn't compile the project

I had running project opened in eclipse. After an accidental restart of windows, now when I open the eclipse I see my project is marked with a little red cross. Now when I run the main method I get a java.lang.NoClassDefFoundError.

I have tried restarting eclipse, Project -> Clean but it doesn't solve the problem.

When I checked the project directory, inside 'target' folder there are no compiled .class files. I tried building the project but I can't get the compiled class files, which is the reason for the error.

How do I solve this?

like image 558
samsamara Avatar asked Aug 09 '12 07:08

samsamara


People also ask

How do I compile a project in Eclipse?

Step 1: Open Eclipse and click File > New > Java Project. Step 2: Provide the Project Name and click on the Finish button. Step 3: In the Package Explorer (left-hand side of the window) select the project which you have created. Step 4: Right-click on the src folder, select New > Class from the submenu.

How do I force Eclipse to recompile?

For Eclipse you can find the rebuild option under Project > Clean and then select the project you want to clean up... that's all.

Why is Eclipse not running my code?

If you've installed Eclipse but are having trouble getting it to run, the most likely cause is that you have not correctly specified the JVM for it to run under. Eclipse startup is controlled by the options in $ECLIPSE_HOME/eclipse. ini. If $ECLIPSE_HOME is not defined, the default eclipse.

Does Eclipse auto compile?

By default, you are in auto-build mode and Eclipse takes care of compiling source files automatically. Builds occur automatically in the background every time you change files in the workspace (for example saving an editor).


6 Answers

I tried all the solutions here, but here's what worked for me.

  1. First, remove the project from eclipse.

  2. Then, in your project folder, delete the 2 files that eclipse creates. They're hidden, but they're called .project and .classpath.

  3. Finally, add the project back into eclipse and eclipse will recreate those 2 files and a new configuration for your project.

My specific issue was that it a project that was missing a Java Builder because it thought it was a scala project. The only way for me to reset this was by removing the project, deleting the 2 files, and adding it back in.

like image 85
kane Avatar answered Oct 20 '22 09:10

kane


Maybe Eclipse's workspace files have become corrupted. Restart Eclipse and choose a new workspace folder (or choose Switch workspace from the menu). Then import the project files into a new project.

like image 23
Danny Lagrouw Avatar answered Oct 20 '22 10:10

Danny Lagrouw


Try deleting the run configuration and remaking.

If that doesn't work, open the class, ctrl+f11 to run. That will force Eclipse to update its classpaths & rebuild its main indexes.

To delete the configuration: - Menu -> Run -> Run Configurations. - Select your configuration - Press delete or use the delete icon

like image 23
Michael Avatar answered Oct 20 '22 09:10

Michael


If you are using maven, this will likely fix it: Right click your project -> Maven -> Update project.. (or alt + F5), select your project, make sure "Refresh workspace resources from local filesystem" is checked and click ok.

like image 29
Pieter12345 Avatar answered Oct 20 '22 09:10

Pieter12345


My eclipse project has similar issue though the error appeared slightly different. I imported a third party java project into Eclipse, with Project > Build Automatically checked, do a Project > Clean..., no classes were generated in the output bin folder. Tried different options, no luck.

I noticed a red exclamation mark at the top left corner of the project name.

enter image description here

Right click on project name, Properties > Java Build path, I saw "Build path entry is missing: cci/src". Manually created src folder, the red exclamation mark gone. Do a Project > clean..., project compilation successful

P.S. The eclipse project is not properly organized, there are no code under src folder. I suspected src folder went missing while checked in by original author since there are no code there.

like image 1
Jonathan L Avatar answered Oct 20 '22 09:10

Jonathan L


Was having the same problem and finally found the glorious hint here. In my project there is one *.scala File and Eclipse Neon is incompatible with the Scala IDE, thus there is no builder for scala and the whole project is not built.

Project Properties -- > Builders

After removing the Scala file and the Scala Package from the linked Libraries )Project Properties --> Build Path --> Libraries) and afterward re-adding the Java Builder (no idea why this one went missing, but here's a useful help on how to add the Java builder when missing), the project could be built and run again.

like image 1
nhaggen Avatar answered Oct 20 '22 11:10

nhaggen