.project and .classpath files are missing in eclipse
I have a project where there are a no of applications built as separate Java projects.
These have been sent over by someone and somehow the.project
and the .classpath
files have not been copied.
So when I try to import it into eclipse it gives me an error:"No project found
".
First of all, the reason why you can not Import your project into Eclipse workstation is that you do not have .project
and .classpath
file.
Now that you know why this happens, so all we need to do is to create .project
and .classpath
file inside the project file. Here is how you do it:
First, create .classpath
file:
Create a new txt file and name it
.classpath
.Copy and paste following code and save it:
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> </classpath>
Then, create .project
file:
Create a new txt file and name it .
project
Copy paste following code:
<?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>HereIsTheProjectName</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription>
You have to change the name field to your project name. You can do this in line 3 by changing
HereIsTheProjectName
to your own project name and then saving it.
I've better solution for this issue, only for MAVEN users. To resolve it follow below steps.
- GO inside your project
D:\workspace\project\
. 2.Open command Line prompt and run this command : mvn eclipse:eclipse
Definitely, Your issue will gone.
You cannot import them as project if .project and .classpath are missing. You can create a new Java project and copy the source files into it.
Let Eclipse Create the Files
Eclipse will make these files for you, but the way to make it do so is not very intuitive.
In Eclipse, make sure the project is not currently showing up in the Project Explorer or Package Explorer. If it is, right-click it and click the Delete button - and make sure the "Delete from Disk" option is unchecked before you hit "Ok"!!!
Select File / New / Java Project
Uncheck Use Default Location, then Click "Browse" and find the folder it is located in.
Click "Next" for more options, or just "Finish".
Eclipse will import the project and automatically create the default .project
and .classpath
files for you. With the one case I tried, with source in the default src/main/java folder, I could build and run fine at this point.
See the Java Build Path help page:
- either you create project in the parent directories of the sources (in which case you add an existing subdirectory as your sources)
- or you create an empty project in your Eclipse workspace, and use the "link" feature
Creates a new folder that links to an location outside of the workspace
That being said, you will still have to re-create the correct classpath yourself.
You don't have need to do anything. Just copy these two files from another projects and paste into that project directory where you getting issue.
In VS Code it solved by just right-click on the src (the folder which contains all java files) folder and select the " Add folder to Java source path" option. If it didn't' worked, then try to remove it first by selecting "remove the folder from Java source path" (this will not result in any data loss) and then adding it again.
Restart once when done. Hope it works for you in Eclipse too.
精彩评论