简体   繁体   中英

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

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

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

Hope it helps for someone else

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.

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

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.

在此处输入图片说明

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.

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.

  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.

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

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.

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.

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

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.

还要确保在 bin 目录下未生成类的项目的构建路径中没有出现致命错误的项目(带有 ! 符号的项目)

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.

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.

只需从构建路径中删除所有罐子(库)并刷新并添加所有罐子并清理和构建项目

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.

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

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.

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.

会出现这种情况:如果您在 eclipse 中打开了项目资源管理器,那么它可能不会显示在 /**/build/classes 下生成的类,在这种情况下,打开该项目的导航器视图并检查同一项目下的构建目录。

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