147

I checked out a project from SVN and did not specify the project type, so it checked out as a "default" project. What is the easiest way to quickly convert this into a "Java" project?

I'm using Eclipse version 3.3.2.

Pops
  • 30,199
  • 37
  • 136
  • 151
Joe Dean
  • 3,356
  • 5
  • 26
  • 31

11 Answers11

128

Open the .project file and add java nature and builders.

<projectDescription>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

And in .classpath, reference the Java libs:

<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
vip
  • 1,707
  • 2
  • 16
  • 46
Chris Marasti-Georg
  • 34,091
  • 15
  • 92
  • 137
  • 27
    I agree with Lorenzo, editing configuration files by hand is a good way to get into trouble with Eclipse. – Adam Apr 25 '12 at 18:13
  • 5
    @Ricky It can be done via the UI in certain versions, with certain plugins. – Chris Marasti-Georg Apr 09 '13 at 13:45
  • 1
    @ChrisMarasti-Georg Yes you are right but even so the solution should imply installing those plugins or updating the UI rather than tweaking an xml by hand specially when the user doesn't know what he is doing. Also because that defies the purpose of having an advanced IDE. – ricardoespsanto Apr 09 '13 at 17:01
  • 1
    In my case, I just had to add the tag to . I had imported an existing Maven project, and Eclipse didn't recognize it as a Java project. However, Eclipse had already correctly configured a Maven section. HTH. – Nathan Smith Mar 12 '14 at 18:42
  • @flashdisk it should be in the root directory of the project. – Chris Marasti-Georg Apr 16 '15 at 21:08
  • After doing this you may need to open the project's Properties and configure the Java Build Path to identify where your source directories are found (e.g., 'src') and specify where Eclipse should generate the .class files ('bin'). – Brian de Alwis Jul 03 '15 at 18:06
  • You can get into trouble editing configuration files like this, but sometimes it's the only way I've found to get past a stuck point. – James Drinkard Dec 17 '15 at 19:55
  • Suggested .project edits worked but not .classpath. What I ended up doing is check the .classpath file of another Eclipse project I had and copying it. Had to clean the build afterwards. Worked like a charm. – yara Mar 01 '16 at 18:12
  • Don't forget to add the src directory to the classpath too `` and bin too for that matter `` – krispy Nov 11 '17 at 20:12
121

Manually changing XML and/or settings is very dangerous in eclipse unless you know exactly what you're doing. In the other case you might end up finding your complete project is screwed. Taking a backup is very recommended!

How to do it just using Eclipse?

  1. Select project.
  2. Open the project properties through Project -> Properties.
  3. Go to "Targetted Runtimes" and add the proper runtime. Click APPLY.
  4. Go to "Project Facets" and select the JAVA facet which has appeared due to step 4. Click APPLY
  5. Set your build path.
  6. If it's a Maven project, you might want to select the project, click Maven -> Update Project configuration...

That did it for me. And Eclipse is configured correctly. Hope it'll work for you too.

gioele
  • 9,748
  • 5
  • 55
  • 80
Lorenzo
  • 1,219
  • 1
  • 8
  • 2
  • 26
    Lorenzo has the proper way to do it. Using Indigo: Right click on project > Properties... > Project Facets > Check Java > Apply – Thien Oct 27 '11 at 18:48
  • 13
    In Eclipse Indigo there is no "Targetted Runtimes" entry in Project Properties, at least I couldn't find it. – simon Apr 24 '12 at 15:25
  • 1
    @simon Just go straight to Project Facets. You may need to enable facets for the project. – Adam Apr 25 '12 at 18:12
  • 8
    @Lorenzo I'm using STS and I don't have "Java facet" under Project Facets". Any ideas? – Robert Aug 02 '12 at 14:25
  • Beautiful, I finally know how to do this without hacks. – Mansoor Siddiqui Jan 24 '13 at 21:33
  • 17
    Note that "Project Facets" is only available in the Java EE version of Eclipse (or with WTP installed). See [Eclipse Bug 102527](https://bugs.eclipse.org/bugs/show_bug.cgi?id=102527) for having this functionality in all versions. – robinst Feb 12 '13 at 20:58
  • @Lorenzo So I turned my project into an faceted Java project and it works great, but now I have this file that was generated: org.eclipse.wst.common.project.facet.core.xml that lists out a specific runtime jdk version. Will this prevent other team members from working on this project if they don't have the same runtime? – yellavon Feb 15 '13 at 14:44
  • 1
    In my case, it was a Maven project, and Update Project... indeed worked. Thanks! – thSoft Jul 11 '13 at 08:38
  • 10
    didn't work! I dont have "Targetted Runtimes" and "Project Facets" – Lai Sep 25 '13 at 10:33
  • 2
    @'robinst' comment: Loading Java EE from Eclipse -> Install New Software allowed me to add project facets, including Java. Thanks. – Robert Casey Jan 10 '15 at 22:11
  • this answer is out of date, see @victor-grazi 's answer below – Anomaly May 06 '19 at 15:20
54

In recent versions of eclipse the fix is slightly different...

  1. Right click and select Project Properties
  2. Select Project Facets
  3. If necessary, click "Convert to faceted form"
  4. Select "Java" facet
  5. Click OK
Victor Grazi
  • 15,563
  • 14
  • 61
  • 94
23

I deleted the project without removing content. I then created a new Java project from an existing resource. Pointing at my SVN checkout root folder. This worked for me. Although, Chris' way would have been much quicker. That's good to note for future. Thanks!

Joe Dean
  • 3,356
  • 5
  • 26
  • 31
  • Your way works, but an important point: as noted [here](http://stackoverflow.com/questions/2636201/how-to-create-a-project-from-existing-source-in-eclipse-and-then-find-it) you must NOT uncheck "use default location". – Robin Green Jul 26 '13 at 15:15
13

Using project Project facets we can configure characteristics and requirements for projects.

To find Project facets on eclipse:

  • Step 1: Right click on the project and choose properties from the menu.
  • Step 2:Select project facets option. Click on Convert to faceted form... enter image description here

  • Step 3: We can find all available facets you can select and change their settings. enter image description here

Premraj
  • 72,055
  • 26
  • 237
  • 180
13

In newer versions of eclipse (I'm using 4.9.0) there is another, possibly easier, methods. As well as Project Facets, there are now Project Natures. Here the process is simple get the Project Natures property page up, and then click the Add... button. This will come up with possible natures included Java Nature and Eclipse Faceted Project Properties. Just add the Java Nature and ignore the various warning messages and your done.

Project Nature

This method might be better as you don't have to convert to Faceted form first. Furthermore Java was not offered in the add Facet menu.

Salix alba
  • 7,536
  • 2
  • 32
  • 38
11

Joe's approach is actually the most effective means that I have found for doing this conversation. To elaborate a little bit more on it, you should right click on the project in the package explorer in eclipse and then select to delete it without removing directory or its contents. Next, you select to create a Java project (File -> New -> Java Project) and in the Contents part of the New Java Project dialog box, select 'Create project from existing source'.

The advantage this approach is that source folders will be properly identified. I found that mucking around with the .project file can lead to the entire directory being considered a source folder which is not what you want.

Chris J
  • 9,164
  • 7
  • 40
  • 39
  • Working with eclipse Kepler build 20140224-0627, and the "file->new->project...->... from existing sources" seems the easiest way to go. – user1050755 Mar 09 '14 at 15:49
  • This works slightly differently in Kepler, the 'Create project from existing source' bit is unnecessary. But yes, this is the best way to do it. – Luís de Sousa Aug 26 '14 at 17:33
6

You can do it directly from eclipse using the Navigator view (Window -> Show View -> Navigator). In the Navigator view select the project and open it so that you can see the file .project. Right click -> Open. You will get a XML editor view. Edit the content of the node natures and insert a new child nature with org.eclipse.jdt.core.javanature as content. Save.

Now create a file .classpath, it will open in the XML editor. Add a node named classpath, add a child named classpathentry with the attributes kind with content con and another one named path and content org.eclipse.jdt.launching.JRE_CONTAINER. Save-

Much easier: copy the files .project and .classpath from an existing Java project and edit the node result name to the name of this project. Maybe you have to refresh the project (F5).

You'll get the same result as with the solution of Chris Marasti-Georg.

Edit

enter image description here

drumherum
  • 153
  • 3
  • 6
3

Another possible way is to delete the project from Eclipse (but don't delete the project contents from disk!) and then use the New Java Project wizard to create a project in-place. That wizard will detect the Java code and set up build paths automatically.

Brian de Alwis
  • 2,814
  • 2
  • 18
  • 32
1
  1. Right click on project
  2. Configure -> 'Convert to Faceted Form'
  3. You will get a popup, Select 'Java' in 'Project Facet' column.
  4. Press Apply and Ok.
Kumar
  • 33
  • 1
  • 9
  • Configure just has 2 options for me: 1. Convert to Maven 2. Configure and detect nested project. Do I need to active anything to see that "Configure to Faceted Form"? – Reihan_amn May 07 '17 at 19:08
  • 1
    @Reihan_amn it looks like your current installation of eclipse does not support that. I am not sure which plugins are responsible for the "Faceted form", but if you download the [Eclipse EE version](http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neon3) you get it by default. – semTex May 09 '17 at 09:24
1

Depending on the Eclipse in question the required WTP packages may be found with different names. For example in Eclipse Luna I found it easiest to search with "Tools" and choose one that mentioned Tools for Java EE development. That added the project facet functionality. Searching with "WTP" wasn't of much help.

  • to get the facet options I installed new software: Eclipse Java EE Developer Tools, searching for 'tools' in Eclipse Oxygen – D M Aug 23 '17 at 08:41