swati
swati

Reputation: 101

.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".
Is there any way to generate the missing files?

Upvotes: 10

Views: 29570

Answers (7)

abdeali004
abdeali004

Reputation: 473

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.

enter image description here

Upvotes: 0

LightCC
LightCC

Reputation: 11649

Let Eclipse Create the Files

Eclipse will make these files for you, but the way to make it do so is not very intuitive.

  1. 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"!!!

  2. Select File / New / Java Project

  3. Uncheck Use Default Location, then Click "Browse" and find the folder it is located in.

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

Upvotes: 6

Mai
Mai

Reputation: 301

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:

  1. Create a new txt file and name it .classpath.

  2. 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:

  1. Create a new txt file and name it .project

  2. 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>
    
  3. 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.

Upvotes: 8

vkstream
vkstream

Reputation: 907

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.

Upvotes: 0

vkstream
vkstream

Reputation: 907

I've better solution for this issue, only for MAVEN users. To resolve it follow below steps.

  1. GO inside your project D:\workspace\project\. 2.Open command Line prompt and run this command : mvn eclipse:eclipse

Definitely, Your issue will gone.

Upvotes: 7

VonC
VonC

Reputation: 1324347

See the Java Build Path help page:

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.

Upvotes: 0

Prakash G. R.
Prakash G. R.

Reputation: 4892

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.

Upvotes: 6

Related Questions