10

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
swati
  • 101
  • 1
  • 1
  • 3
  • Not sure if this method was available when this question was posted, but Eclipse will make these files for you, at least for simple cases. Added an answer for that. – LightCC Dec 21 '18 at 06:18

7 Answers7

8

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Mai
  • 301
  • 3
  • 5
7

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.

vkstream
  • 881
  • 8
  • 8
6

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.

LightCC
  • 9,804
  • 5
  • 52
  • 92
6

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.

Prakash G. R.
  • 4,746
  • 1
  • 24
  • 35
0

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.

vkstream
  • 881
  • 8
  • 8
0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried the link feature but there the name of the packages changes and it is too tedious to change it all over again..instead i made empty projects and copied the folders..thanks – swati Jun 09 '11 at 05:50
  • @swati: the link feature wouldn't change the name of your packages. i t would allow to declare an external directory as part of your project, and make that directory a 'src' one, to be compiled. But the directories in it (representing your packages) would be unchanged. See http://stackoverflow.com/questions/1470827/external-output-folder-in-eclipse/1470833#1470833 for more. – VonC Jun 09 '11 at 08:01
0

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

abdeali004
  • 463
  • 4
  • 9