Java 由于 .lock 无法打开 Eclipse 工作区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23924310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:05:34  来源:igfitidea点击:

Cannot open Eclipse workspace because of .lock

javaeclipse

提问by TK Tang

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?

每次打开 Eclipse 都说我的工作区目录无法加载,删除我的工作区目录中元数据文件夹中的“.lock”文件可以让我访问它。但是 .lock 文件不断出现,每次尝试打开 Eclipse 并加载该工作区时,我都必须将其删除。任何想法可能导致此问题或可能的解决方法?

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)

我正在使用 Ubuntu 14.04。由于愚蠢的原因,我的 eclipse 在桌面目录上(无法使 eclipse.exe 可执行,因为我的驱动器是 ntfs 或类似的东西)

回答by skytreader

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.

另一个想法。由于您正在运行 Ubuntu,因此您可以创建一个启动脚本,该脚本将在实际运行 Eclipse 之前删除 .lock 文件。我不知道你的设置的细节,所以这是一个粗略的草案。您可能必须修改它。

# 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.

唯一的缺点是您需要从命令行运行 Eclipse。虽然我相信您可以将脚本放在 Unity 的启动器中,或者在后台运行,以便关闭终端窗口不会杀死 Eclipse。

Some notes:

一些注意事项:

  • If the .lock file does not exist, the rmcommand 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.
  • 如果 .lock 文件不存在,该rm命令将打印出一条错误消息,否则什么也没有发生。
  • 如果您没有从 Ubuntu 软件中心(例如,手动下载)安装 Eclipse,您可能找不到 Eclipse 作为/usr/bin/eclipse.

回答by E-Riz

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

.lock文件是 Eclipse 检查工作区是否正在被另一个正在运行的实例使用的方式。算法基本上是这样的:在启动时,

  • if no .lockfile 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 .lockfile 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 notbe deleted, Eclipse assumes it's because it is locked ("held") by another instance process and reports that the workspace is in use.
  • 如果不.lock存在文件,则创建一个文件,Eclipse 继续加载工作区。如果由于某种原因无法创建,则加载工作区将失败。
  • 如果.lock文件存在,Eclipse 会尝试删除它。
    • 如果可以删除该文件,Eclipse 会这样做,重新创建它(以从当前运行的进程中对文件建立一个新的“保留”)并加载工作区。
    • 如果无法删除该文件,Eclipse 会认为这是因为它被另一个实例进程锁定(“持有”)并报告工作区正在使用中。

So, the .lockfile will always exist in a workspace directory once Eclipse has been run at least 1 time with that workspace. This is nota 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 bugthat suggest Samba can be the source of mysterious file locking issues like this.

因此,.lock一旦使用该工作区至少运行 1 次 Eclipse ,该文件将始终存在于该工作区目录中。这不是问题,事实上这是它的设计方式。在您的情况下,听起来 Eclipse 在启动时无法删除该文件,这表明存在 NFS 或其他文件系统问题。你在用桑巴吗?我在这个 bug中读到了一些评论,这些评论表明 Samba 可能是像这样的神秘文件锁定问题的根源。