2

Every time I open Eclipse, it says that my workspace directory can't be loaded, deleting the ".lock" file in the metadata folder in my workspace directory lets me access it. But the .lock file keeps appearing and I have to delete it each time I try to open Eclipse and load that workspace. Any ideas what could be causing this or possible ways to fix it?

I am using Ubuntu 14.04. My eclipse is on the desktop directory because of dumb reasons (Cannot make eclipse.exe executable because my drive is ntfs or something like that)

TK Tang
  • 113
  • 2
  • 2
  • 9
  • this only happens when eclipse exits under exceptional conditions. I don't know that there is a work around besides deleting the file. – nsfyn55 May 29 '14 at 01:32
  • If it happens every time maybe you need to reinstall/redownload Eclipse? Could also be an issue with your installed plugins/dev environments. – skytreader May 29 '14 at 01:50

2 Answers2

3

The .lock file is how Eclipse checks if a workspace is in use by another running instance. The algorithm is basically this: on startup,

  • if no .lock file exists, one is created and Eclipse proceeds to load the workspace. If it can't be created for some reason, loading the workspace fails.
  • if a .lock file exists, Eclipse tries to delete it.
    • If the file can be deleted, Eclipse does so, re-creates it (to establish a new "hold" on the file from the current running process) and loads the workspace.
    • If the file can not be deleted, Eclipse assumes it's because it is locked ("held") by another instance process and reports that the workspace is in use.

So, the .lock file will always exist in a workspace directory once Eclipse has been run at least 1 time with that workspace. This is not a problem, in fact it's how it is designed. In your case it sounds like Eclipse can't delete the file when it starts up, which suggest an NFS or other file system problem. Are you using Samba? I've read some comments in this bug that suggest Samba can be the source of mysterious file locking issues like this.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
0

Another idea. Since you're running Ubuntu, you can just create a launch script that will delete the .lock file before actually running Eclipse. I don't know the specifics of your set-up so here's a rough draft. You probably have to modify this.

# Delete the lock file
rm /home/ch/workspace/.lock
# Start Eclipse
/usr/bin/eclipse

The only downside is that you need to run Eclipse from the command line. Though I believe you can put the script in Unity's launcher, or run in background so that closing the terminal window will not kill Eclipse.

Some notes:

  • If the .lock file does not exist, the rm command will print out an error message but otherwise nothing happened.
  • If you did not install Eclipse from the Ubuntu Software Center (e.g., manual download) you may not find Eclipse as /usr/bin/eclipse.
skytreader
  • 11,467
  • 7
  • 43
  • 61