简体   繁体   中英

How to force Eclipse to see java project as java project?

I have downloaded a 3rd party project, which consists of multiple files, including Java ones.

General structure is as follows:

<topfolder>
   pom.xml
   <subfolder1>
      pom.xml
      src
         main
            java
               <normalclasspath>
            resources
         site
            apt
               index.apt
         test
            java
               <normalclasspath>

Eclipse imports this project normally, but is unable to index its Java content. For example, I can't browse from a variable to its definition, and so on.

Also I can't set my own Build Path since it says No action available .

Of course, I can refactor folder structure myself to suite eclipse needs, but are there any automation means for this?

UPDATE

Yes, this is a Maven project and Eclipse already knows that it has Maven nature. The only option now is to disable it

在此输入图像描述

But this is not a question. The question is how to add JAVA NATURE , so that Eclipse knows consistence of classpath and be able to navigate to class definitions and so on.

UPDATE 2

@75inchpianist's answer about facets helped partially. It was not available to select Java facet immediately, but required turning on facets at all first. Then Java facet was already there.

Now I see, that Eclipse interprets Java, but Maven interpretation is not full. Namely, no Maven dependencies interpreted (no Maven Dependencies node in Package Explorer ).

The attempt to add it fails:

在此输入图像描述

Right click on the project and select "Properties"

Within "Project Facets" make sure that Java is selected!

As this is a maven project (because of the pom.xml) you need to install a maven plugin for eclipse. Next you have to right click on the project and choose "Configure->Convert to Maven Project".

Now you should have your normal java structure.

Assuming that Eclipse recognizes the project as Java project yu can do the following:

If you don't want to install a maven plugin into Eclipse you can make Eclipse recognize the source correctly by adding every src/main/java folder as Source-Folder to your Build-Path.

This is better than modifying the folder structure as you can update the sources without problem later.

Add following to your .project file and refresh the project.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM