Missing .classpath file in Eclipse project

白昼怎懂夜的黑 提交于 2019-12-20 10:33:17

问题


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.

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:

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.

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

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.


回答1:


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. However, even after doing this, eclipse couldn't write to the .classpath files. 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. 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. 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. This fixed my problem.




回答2:


The .classpath file in eclipse is a configuration file (in XML) which stores the project classpath properties. 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. You may have to run Eclipse as administrator.




回答3:


Go to your Project in WorkSpace. And then change your files' attribute from hidden.

Also, then close-open your project and then clean it.

This should work.




回答4:


Go to the project folder and remove hidden property for the ".classpath" file. Hope this helps. Thanks.




回答5:


Right click Project >> Source >> Format - worked for me!




回答6:


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.

Hope this helps




回答7:


Just had the same issue after trying to create my view on a new PC. The cause of the issue for me was that .classpath file was marked as read-only, for whatever reason. 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.




回答8:


I had a similar problem after changing my project to 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.

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.

Hope this helps someone out there.




回答9:


As doc_180 mentioned, the .Classpath would be hidden. Right click > Properties and Unhide the file, you should be ok.



来源:https://stackoverflow.com/questions/4853718/missing-classpath-file-in-eclipse-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!