Marco Micheli
Marco Micheli

Reputation: 717

Eclipse doesn't compile java files into classes

I have no idea why, but from today Eclipse doesn't compile .java files into .class. I press the "Run" button and Eclipse only tries to run the program rather then compiles it first, so i get this error all the time:

Exception in thread "main" java.lang.NoClassDefFoundError

Upvotes: 23

Views: 124345

Answers (24)

alphcoder
alphcoder

Reputation: 130

First of all are seeing a cross sign near your application in project explorer? If yes then export your project as a war, and check if your class is present in the classes directory ( "path_to_war\NoteTaking.war\WEB-INF\classes). If you don't have the class file there then we need to clean the project. One the top menu of eclipse go to project and clean. After that cross sign should disappear from application and you should be able to see in classes directory also.

enter image description here

Upvotes: 0

Fuchun Hsieh
Fuchun Hsieh

Reputation: 89

I opened one of the file in Intellij and this problem happened to me as well. Eclipse couldn't identify new files and lost the properties of the file that is opened by other IDEs. (I don't know why) Here's the steps I fixed it, hope it works for you.

  1. remove build path of the project
  2. close eclipse
  3. build path again

Upvotes: 0

Priyabrata Nayak
Priyabrata Nayak

Reputation: 50

Try deleting the missing jar files from build path. It may resolve the issue.

I got the same error, but later solved it just by deleting the missing jar files from the build path.

Upvotes: 0

Tom Rutchik
Tom Rutchik

Reputation: 1692

I'll explain my solution to this problem: "eclipse not compiling java files into class files". I'm using Eclipse version '2020-03 (4.15.0)'. I have a project that is dependent on a java project. For the dependent project, I was not able to export a jar file containing the compiles classes and resources. To be more precise, the exported jar file did not contain any class files. The output bin folder for the project is empty after doing a project build. In examining the console output when I tried to build all projects indicated that the build failed because the dependent project was missing. In looking at one of the log outputs, I saw something indicating that the build failed because some eclipse class was missing.

One of the things I tried was to do an eclipse update. Eclipse offered up the list of changes and I tried to apply them, but the update failed. I tried to update several times but they all failed. Looking more carefully at the offered up list of updates I noticed that one of the suggested update involved "deleting" Java Development Tools. That line had an warning indicating that the entire feature could not be deleted due to other dependencies and that only the non dependent features would be deleted. Doesn't that sound suspicious. Why was the update trying to delete Java Development Tools? My speculation is that something got deleted from the Java Development tool that was causing the build process to fail. The missing class I saw earlier also suspiciously sounds like it might be part of the Java Development Tools feature.

So what I did to solve the problem was to reinstall eclipse. I used the eclipse loader application to do the reinstall. (Note, I did not uninstall it first). After the reinstall, the dependent project was able to produce classes, and things once again worked as they should.

I certainly don't know how the eclipse release got into this compromised state, but in my situation the re-install of eclipse was the only way I could find to resolve the problem.

Upvotes: 0

Axel Osorio
Axel Osorio

Reputation: 11

I had this problem, I tried the clean, the build manually, open, closing the project, deleting, and open, etc., nothing works, and after 4 hours I get a workaround what works for me.

  1. Please, Make a RAR, ZIP, or copy from your entire project folder as a backup if it doesn't work and you mess around, OK, now:

  2. Clean the Project. It cleaned all my class files from the output folder, but doesn't generate the class files after the clean with the building (but we already know that)

  3. Delete the project (warning, make sure the Delete contents is not selected or your project will dissapear). For me it says something about that desynchronysation with code mix, and hibernate, blabla)

  4. Close myEclipse

  5. Restart your computer.

  6. Open myEclipse

  7. Import the project with the option "Projects from folder or Archive", not with the "existing projects into workspace" option.

  8. Myeclipse start to build the class files, I don't know why, but works for me, I hope this helps somebody else.

Upvotes: 1

Marek Podyma
Marek Podyma

Reputation: 1073

I tried many different potential solutions: cleaning, rebuilding, removing, re importing, Update Maven Project and nothing. I still couldn't run my app from Eclipse. In my case the reason was that I was running Eclipse using openjdk-11 while my project was in Java 8. After I've reconfigured Eclipse to be ran from Java 8 everything started to work (in eclipse.ini).

-vm
/usr/lib/jvm/jdk1.8.0_202/bin

Upvotes: 0

Moebius Rex
Moebius Rex

Reputation: 107

When I have had this exact same problem, its cause has always been the same and the solution has worked 100% of the time for me. It's caused by a missing jar file in the project's Java build path and it's indicated by a red exclamation point decoration on the project icon. To fix the problem, go to Project|Properties|Java Build Path, click on the Libraries tab and either remove or fix the path for all missing jar files. If your project is configured to rebuild automatically, it should start a build as soon as you apply your changes.

enter image description here

Upvotes: 7

Arunangshu Pal
Arunangshu Pal

Reputation: 21

Please check if all the jars are there in your build path settings. If any jar is missing this issue might come.

Upvotes: 1

Muhammad Mohinuddin
Muhammad Mohinuddin

Reputation: 41

Yes I was facing this issue. Coz Eclipse cannot build the project for Build Path error. Check that your external jar files is not showing any error. Delete the Jar file which one is missing or which one is showing re color. delete that one. add a fresh one from the correct path or location. if all the error are gone. then in the project bin folder one class file will be created and then could not load main class error will be removed too.

Upvotes: 4

JesseBoyd
JesseBoyd

Reputation: 1096

This is probably a rare event but I declared a servlet with annotations and left off the "/" before the servlet mapping name. I spent over an hour chasing my tail, installing new servers, thinking I might even need to re-install my IDE and it was this simple error! Every time I tried to load any page from my Dynamic Web Project I got a 404 error. I could not even load a plain vanilla html page. There really needs to be better error logging with the IDE and Server interaction as there was zero indication of the error and my servlet was never called at the start of my web app. Hope this helps save someone else some frustration. Always name your servlet with a / slash like /myServlet never just myServlet.

Upvotes: 0

Hasnain Ali Bohra
Hasnain Ali Bohra

Reputation: 2180

Just Remove Your all Jars (Libraries) from the Build Path and refresh and add all jars and clean and build the project

Upvotes: 0

fish_drowned
fish_drowned

Reputation: 11

I encountered a similar problem: previously compiled and running java files couldn't run anymore. Eclipse showed "couldn't find class xxxx". When I checked bin folder, the previous .class files were gone. That's why Eclipse couldn't run the files, NOT because of errors in files. I don't know why it can't just re-compile the file, and why the .class file gone missing in the first place.
But I found a solution:
Simply create a dummy java file in the same package (without doing anything just create), then run it. Then magically all previous .class files came back. And I can run those files as before.

Upvotes: 0

santosh
santosh

Reputation: 11

I had problem in eclipse for load module not found and no class file was getting created. Solution: Go to Create New Project > Under JRE section Choose Use project Specific JRE. Now Class files are created.

Upvotes: 1

LazerBanana
LazerBanana

Reputation: 7211

Just restart your machine. Its weird but it helps we had loads of problems this type in our company for unknown yet reason. Always restarting the machine helped. It was normally encountered while trying to run Junit tests and it could not find a class even when the Run configuration was pointed to /bin.

Upvotes: 0

Harpal
Harpal

Reputation: 135

  1. there can be errors in your project, or other reasons like mentioned in above answers.
  2. or you may be a fool like me

who moved the source code to other folder and not updated source path in project build properties. in this case it was not giving any error or class files too. check that too.

goto Project Properties -> Java Build Path -> Source

Add or Link new source folder location.

Upvotes: 3

Aarish Ramesh
Aarish Ramesh

Reputation: 7023

Also ensure that there are no projects with fatal errors (projects with ! symbol over it) in the build path of the project which is not generating classes under the bin directory

Upvotes: 0

Johnny2012
Johnny2012

Reputation: 1532

Close Project -> Open Project -> Clean -> Refresh

Hope it helps for someone else

Upvotes: 16

StrangeLoop
StrangeLoop

Reputation: 531

I ran into this problem with Eclipse Luna, for some reason the Java builder was missing from the project. Verify that in your .project file you have something like

<buildSpec>
    <buildCommand>
        <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>     
</buildSpec>

You can also configure builders from Project Properties -> Builders

Upvotes: 10

jan.supol
jan.supol

Reputation: 2805

The eclipse needs to erase the output folder when building classes.

The folder is found on Project Properties -> Java Build Path -> Default Output Folder. It can differ from general output folder name found under Eclipse Preferences. If this output folder cannot be erased for some reason (for instance, on Windows, when a shell is opened on this location), the project is marked as corrupted (as Marco Micheli describes) and the classes then are not built.

You just need to make sure the output folder can be erased.

Upvotes: 4

nimesh makwana
nimesh makwana

Reputation: 141

There would be the case : if you have opened project explorer in eclipse then it may not show you classes generated under /**/build/classes, in such case open Navigator view of that project and check build directory under the same project.

Upvotes: -1

Vasanth Raj
Vasanth Raj

Reputation: 11

Some times jars in the build path might be missing even though we are not using it. Since error is there, java files wont compile into classes. Can check errors from problems view.

Either remove jars from build path or place the missing jars in the build path.

Upvotes: 1

Septem
Septem

Reputation: 3622

open problems view from window -> show view -> problems, if there's any error, fix it

eclipse will reject to compile if there is any problems in your project

Upvotes: 42

Marco Micheli
Marco Micheli

Reputation: 717

This problem happens when "for some reasons" your project is corrupted and has a red icon near the project's name in Eclipse. The solution is to save the project's folder, delete the project in Eclipse, than create the project again in Eclipse coping all the previous files saved.

Upvotes: 13

Stimpson Cat
Stimpson Cat

Reputation: 1498

Do clean all projects ! This will erase all old class files, so eclipse is forced to generate them again.

Upvotes: 1

Related Questions