Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-building a deleted class file in Eclipse

I accidentally deleted a .class (Java bytecode) file in my project (on the filesystem, not using Eclipse itself). Easy to fix, right? Just re-build it. But that doesn't work! Even if I select "Build Project" or "Build All" or "Build Automatically" from the "Project" menu, nothing actually happens on the file system, and I still get:

Exception in thread "main" java.lang.NoClassDefFoundError

I just want to re-compile this from the source code I already have!

By the way, when I choose "Clean..." from the "Project" menu, Eclipse doesn't delete any files either. I have also tried re-importing the project into a different folder, but Eclipse just copies all the .class files and the problem persists.

like image 987
user690075 Avatar asked Sep 07 '11 00:09

user690075


People also ask

How do I Regen a class file?

Make sure that in the Project up-menu, the option "Build Automatically" is checked then just clean your project. It should regenerate the . class file(s).

How do I restore a file in Eclipse?

Select the file you want to restore, then click Restore. That's it, the file is restored to the same package where it resided before the deletion.

Can we decompile class file in Eclipse?

The decompiler plugin can decompile the class file outside of the Eclipse IDE as well. Drag and drop the class file to the Eclipse editor area, the decompiled source code will display.


1 Answers

The OP answered his own question in the comments (2 and a half years ago):

Found the solution: another project on which that project depended could not be compiled, because it could not be cleaned, because Eclipse wanted to delete the .svn directories throughout that project (I have no idea why), and it could not because some of the files didn't have write permission. I was happy to wipe out all the .svn data just to get this working! Thanks for the hint. – user690075 Sep 7 '11 at 1:25


In regards to the bounty

This question has not received enough attention.

This problem keeps wasting hours of my time.

IF the OP's answer didn't resolve your issue, you should ask a more specific question on a new post, describing what you've attempted and how the OP's solution didn't resolve your specific issue.

That being said, assuming you did try the solution the OP posted, it is possible a different issue (that wasn't caused by deleting a class file) is causing the same error. Because you started a bounty on someone else's question and you can't get your prestige back I thought it would be appropriate to mention it might be worth your time to make sure your JDK version(s) are compatible between old or external source code used in your project. You'll get the same error NoClassDefFoundError when the compiler reaches a point in your code that references an object/class that's defined in a library that was developed on an incompatible JDK, it's missing key internal dependencies that are not found within your JDK version.

I would go into more detail, but since this question is specifically about an error that came about from deleting a class file I don't feel it's right to do so.

like image 165
Arthur Weborg Avatar answered Oct 13 '22 01:10

Arthur Weborg