[英]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. 我正在使用一个特殊的Maven插件,它提供了一个自定义的打包类型,并定义了一个特殊的生命周期映射。 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). 但它仍然是一个类似Java的项目,因此我希望Eclipse(使用m2e插件)将项目作为Java项目导入(在.project文件中具有java特性)。 But it always imports it as a simple project without java nature. 但它总是将它作为一个没有Java性质的简单项目导入。 I always have to add the java nature to the .project file manually. 我总是需要手动将java特性添加到.project文件中。
I also tried keeping packaging type "jar" and changed the plugin to provide a custom lifecycle mapping for "jar". 我还尝试保持包装类型“jar”并更改插件以提供“jar”的自定义生命周期映射。 But still m2e doesn't recognize it as a java project. 但m2e仍然不认为它是一个java项目。
So how does m2e decide if it must enable the Java nature in the project or not? 那么m2e如何决定它是否必须在项目中启用Java性质呢? 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? 或者是否有一些特殊的m2e配置我可以放入Maven pom.xml告诉m2e我的项目是一个java项目?
Found it! 找到了! No need to change the packaging type to "JAR". 无需将包装类型更改为“JAR”。 I only need to include the maven-compiler-plugin in the lifecycle mapping: 我只需要在生命周期映射中包含maven-compiler-plugin:
<!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. 现在m2e在导入时将java性质添加到项目中并仍然执行自定义生命周期。
try adding maven eclipse plugin to your POM file. 尝试将maven eclipse插件添加到您的POM文件中。
> <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-eclipse-plugin</artifactId> > <version>2.9</version> > </plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.