Eclipse Build Error “A class file was not written.

2020-08-10 07:02发布

I have been struggling with a very weird issue that has suddenly popped up on the latest version of Eclipse Classic (4.2.2).

Everytime I try creating or refactoring a class or subclass in any of my projects (all Java) in my Eclipse workspace I get an error at the very top of my class that says

A class file was not written. The project may be inconsistent, if so try refreshing this project and building it

Again, this happens when I create new classes. And even when I rename current classes, then undo the renaming, its totally fine, but changing a single character in the name causes this error to happen for that specific class.

I have Auto Build on, and I tried multiple times to clean and refresh every project as well as restart Eclipse entirely.

I have literally no idea how to even start figuring out how to fix this. The solutions i've found through search didn't help, so i'm hoping I might find any clues here.

2楼-- · 2020-08-10 07:46

I solved it changed the owner of the project files. I changed from root(old owner) to user my current(user that i use with eclipse).

3楼-- · 2020-08-10 07:48

Try to launch Eclipse as Administrator.

4楼-- · 2020-08-10 07:49

We are using Eclipse here too and have to handle a workspace with more than 200 plug-ins. Every now and then people have similar problems with their workspace and inconsistencies reported in a weird way by Eclipse. What people here usually do is (next step only in case previous step didn't help): - trying to ContextMenu->Team->Clean/Refresh the whole workspace - creating a new workspace and check out all necessary files from the repository - reinstalling Eclipse to a new directory

From my experience after using the Eclipse IDE on a daily basis for many years, it doesn't make very much sense to waste too much time with these issues, unless they aren't solved by one of the steps above. It takes too much time to struggle with these things, while starting from scratch is done in an hour or less (and usually fixes the issue). If your Eclipse still behaves strangely it might make sense to go through your installed plug-ins. Not all external plug-ins follow the Eclipse guidelines and can seriously harm the performance and operational consistency of your Eclipse installation (E.g. Sonar Plug-in, Toad Plug-in, ...)

5楼-- · 2020-08-10 07:50

I had the same issues, the following worked for me:

  1. Right click eclipse then running "as an Administrator"
  2. Click Project > Clean.
Deceive 欺骗
6楼-- · 2020-08-10 07:52

For linux (Debia) and working on Spring boot project (maven):

$ sudo mvn clean

Then open Eclipse and File -> Refresh.

7楼-- · 2020-08-10 07:53

I've been throught that error once when I used wsdl2java to extract java classes from a wsdl, it turns out that all classes were created in the same "class", causing end classes with long names (error - File name too long). When I organized and rename some classes the error disappeared.

登录 后发表回答