简体   繁体   English

Eclipse 项目中缺少 .classpath 文件

[英]Missing .classpath file in Eclipse project

I have recently returned to a project after not using it for a couple of weeks.我最近几周没有使用它后又回到了一个项目。 The project was not created in Eclipse it was imported, and there is no '.classpath' file in the project workspace.该项目不是在 Eclipse 中创建的,而是导入的,并且项目工作区中没有“.classpath”文件。

I am sure that previously I successfully added new .jar files by simply right clicking them and going to 'Add to build path', but thanks to an unrelated error I had to re-add the files to the build path, and now whenever I try to add a new .jar file I get the following error:我确信以前我通过简单地右键单击它们并转到“添加到构建路径”来成功添加了新的 .jar 文件,但是由于一个不相关的错误,我不得不将文件重新添加到构建路径中,现在每当我尝试添加一个新的 .jar 文件我收到以下错误:

Error while adding a library

Reason:
Could not write file C:\Users\Charles\workspace\hive\.classpath

Or, if I try to add a file using Configure build path, I get the following error:或者,如果我尝试使用配置构建路径添加文件,则会出现以下错误:

'Setting build path' has encountered a problem.

Could not write file:
C:\Users\Charles\workspace\hive\.classpath

I have earlier versions of this project prior to adding .jar files, and there is no .classpath file for any of them either, so I haven't accidentally deleted it at any point.在添加 .jar 文件之前,我有这个项目的早期版本,并且没有任何一个 .classpath 文件,所以我没有在任何时候意外删除它。

If anyone can help me out at all, I'd be ever so grateful (I desperately need to add these .jar files so I can do some actual work).如果有人能帮助我,我会非常感激(我迫切需要添加这些 .jar 文件,以便我可以做一些实际的工作)。

The thing that annoys me the most is I'm sure it worked before, but I have tried to do the same in earlier versions of the project and I am always getting the same error now.最让我烦恼的是我确定它以前有效,但我尝试在项目的早期版本中做同样的事情,现在我总是遇到同样的错误。

I had the same problem.我有同样的问题。 I had just setup a new PC, I transferred my projects to the new PC, clicked on the workspace directory, and changed the permission so that I (the 'me' on my new PC) owned all the files in all all sub-directories.我刚刚设置了一台新 PC,我将我的项目转移到了新 PC,单击了工作区目录,并更改了权限,以便我(新 PC 上的“我”)拥有所有子目录中的所有文件. However, even after doing this, eclipse couldn't write to the .classpath files.但是,即使这样做,eclipse 也无法写入 .classpath 文件。 I verified that I could write to them using notepad, and that worked fine.我确认我可以使用记事本给他们写信,而且效果很好。 I also verified that the O/S knew I was really the owner, but it didn't help.我还验证了 O/S 知道我真的是所有者,但这没有帮助。 I also tried running as admin, but that didn't help either.我也尝试以管理员身份运行,但这也无济于事。

Then I found this link: http://blog.ryanrampersad.com/2010/03/03/setting-build-path-has-encountered-a-problem-in-eclipse/ , which indicates that when you copy files to a windows7 machine, windows may set the 'hidden' attribute on the file, and when this happens, eclipse can't work with it.然后我找到了这个链接: http : //blog.ryanrampersad.com/2010/03/03/setting-build-path-has-encountered-a-problem-in-eclipse/ ,这表明当你将文件复制到windows7 机器,windows 可能会在文件上设置“隐藏”属性,当发生这种情况时,eclipse 无法使用它。 I did a find files from the workspace directory, looking for '.project' (and subsequently '.classpath'), and selected all the files, right-clicked, and un-checked the 'hidden' attribute.我从工作区目录中查找文件,查找“.project”(以及随后的“.classpath”),然后选择所有文件,右键单击并取消选中“隐藏”属性。 This fixed my problem.这解决了我的问题。

The .classpath file in eclipse is a configuration file (in XML) which stores the project classpath properties. Eclipse 中的 .classpath 文件是一个配置文件(XML 格式),用于存储项目类路径属性。 If it can't be written, perhaps it's an access problem.如果不能写入,可能是访问问题。 Right-click the file in windows explorer and check under the security tab to see if you have write permissions.在 Windows 资源管理器中右键单击该文件,然后在安全选项卡下检查您是否具有写入权限。 You may have to run Eclipse as administrator.您可能必须以管理员身份运行 Eclipse。

Go to your Project in WorkSpace.转到您在 WorkSpace 中的项目。 And then change your files' attribute from hidden.然后从隐藏更改文件的属性。

Also, then close-open your project and then clean it.此外,然后关闭打开您的项目,然后清理它。

This should work.这应该有效。

右键单击 Project >> Source >> Format - 对我有用!

Go to the project folder and remove hidden property for the ".classpath" file.转到项目文件夹并删除“.classpath”文件的隐藏属性。 Hope this helps.希望这会有所帮助。 Thanks.谢谢。

The below solution worked for me.以下解决方案对我有用。

Go to your project folder --> Right click folder --> Properties --> In general tab, Uncheck the attribute(last field), Read-only (Only applies to this folder) option.转到您的项目文件夹 --> 右键单击​​文件夹 --> 属性 --> 在常规选项卡中,取消选中属性(最后一个字段)、只读(仅适用于此文件夹)选项。

Then try adding jars in eclipse.然后尝试在 eclipse 中添加 jars。

Hope this helps希望这有帮助

As doc_180 mentioned, the .Classpath would be hidden.正如 doc_180 所提到的, .Classpath 将被隐藏。 Right click > Properties and Unhide the file, you should be ok.右键单击> 属性并取消隐藏文件,您应该没问题。

Just had the same issue after trying to create my view on a new PC.尝试在新 PC 上创建视图后遇到了同样的问题。 The cause of the issue for me was that .classpath file was marked as read-only, for whatever reason.对我来说问题的原因是.classpath文件被标记为只读,无论出于何种原因。 To resolve this I did the following:为了解决这个问题,我做了以下事情:

Go to workspace directory --> Java Source folder --> Project Directory --> right click on .classpath and select Properties from the list --> uncheck 'Read-only' and/or 'Hidden' attribute checkbox(es) --> Click 'Apply' button.转到工作区目录 --> Java 源文件夹 --> 项目目录 --> 右键单击.classpath并从列表中选择属性 --> 取消选中“只读”和/或“隐藏”属性复选框- -> 点击“应用”按钮。

I had a similar problem after changing my project to Gradle.将我的项目更改为 Gradle 后,我遇到了类似的问题。 When I right-clicked on javaw.exe->Properties in the 'debug' view, I saw the classpath was (mostly) missing, for instance the 'bin' directory containing the classes wasn't there.当我在“调试”视图中右键单击 javaw.exe->属性时,我看到类路径(大部分)丢失了,例如包含类的“bin”目录不存在。

Solution for me was just to delete the 'run debug configuration' and create a new one.对我来说,解决方案只是删除“运行调试配置”并创建一个新配置。 After that the classpath was included and I could run it from Eclipse again.之后,类路径被包含在内,我可以再次从 Eclipse 运行它。

Hope this helps someone out there.希望这可以帮助那里的人。

An intern here just had this problem.这里的实习生刚刚遇到了这个问题。 He put the project on the user Document folder.他把项目放在用户的Document文件夹中。 I moved his project to the Eclipse workspace folder, removed the project from Eclipse and imported it again.我将他的项目移动到 Eclipse 工作区文件夹,从 Eclipse 中删除该项目并再次导入它。 Then the .classpath file was generated.然后生成了 .classpath 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM