简体   繁体   中英

How does m2e decide if project has java nature?

I'm using a special Maven plugin which provides a custom packaging type and defines a special lifecycle mapping. But it is still a Java-like project so I'd like Eclipse (with m2e plugin) to import the project as a Java project (With java nature in .project file). But it always imports it as a simple project without java nature. I always have to add the java nature to the .project file manually.

I also tried keeping packaging type "jar" and changed the plugin to provide a custom lifecycle mapping for "jar". But still m2e doesn't recognize it as a java project.

So how does m2e decide if it must enable the Java nature in the project or not? Or is there some special m2e configuration I can put into the Maven pom.xml to tell m2e that my project is a java project?

Found it! No need to change the packaging type to "JAR". I only need to include the maven-compiler-plugin in the lifecycle mapping:

<!DOCTYPE component-set>
<component-set>
  <components>
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>custom</role-hint>
      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
      <configuration>
        <phases>
          <compile>
            org.apache.maven.plugins:maven-compiler-plugin:compile,
            my.custom.plugin:compile
          </compile>
        </phases>
      </configuration>
    </component>
  </components>
</component-set>

Now m2e adds the java nature to the project when importing it and still executes the custom life cycle.

try adding maven eclipse plugin to your POM file.

 > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-eclipse-plugin</artifactId> > <version>2.9</version> > </plugin> 

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