Convert Eclipse project type from general to Java

2020-02-05 00:54发布

问题:

I'm taking over another team's project and am experiencing some bizarre Eclipse issues.

I'm using Subversive as my plugin, and when I go to check the trunk out it brings me to a standard "Check Out As" dialog where it allows me to select the check out method, and the only one that works for me (or is applicable) is the last option (Check out as a project with the name specified).

So I specify the name, and the project then checks out as normal and all is well, except...

Although this is supposed to be a Java project (WARs up into a Java web app), it seems that the team that made the project created it as a general project (by going to Project > Properties > Resource > Type = 'Project').

As such, none of the typical features that come with a Java project are enabled, including (but certainly not limited to):

  • F3 doesn't work, even if the type is defined inside the same package (folder in this case) as the type I'm currently editing (because Eclipse isn't treating this like a Java project)
  • Can't search for Java classes
  • Can't build from inside Eclipse (because there are not source packages, only folders), etc.
  • This list goes on and on...

So my question(s) are:

  • Is there a way to convert this General Project type into a Java Project without having to make a whole new project and copying everything over?
  • I'm wondering if I checked the project out incorrectly, but none of the checkout methods (in Subversive) were really applicable: (1) Check out as a project configured using the New Project Wizard (why check out as a new project?!?), (2) Find projects in the children of the selected resource (no), (3) Check out as a folder into an existing project (no).
  • Is there any other avenue I could take here to "Java-ify" this project?

回答1:

Under Project Properties -> Project Facets -> Convert to faceted form... you can select Java - this will add the Java functionalities to your project. There you can also add other facets like Dynamic Web Module if necessary.

From what you have written the project was checked out correctly. The option Check out as a project configured using the New Project Wizard is applicable when the .project file does not exist in the repository and you have to select the project type manually. It will only create a new Eclipse project locally.



回答2:

Partial response: you can convert your project to a Java project by adding the following nature to the .project file contained at the root of your project:

<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
 </natures>

And I think that the purpose of the Checkout as New project is to be able to create an "Eclipse project" for a project that has no .project and .classpath file. This allows you, for example, to say that the project is actually a Java project.