简体   繁体   English

m2e如何决定项目是否具有java性质?

[英]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.

相关问题 如何让eclipse在我的m2e maven项目中检测到新的Java类? - How can I make eclipse detect my new java class in my m2e maven project? 如何强制Eclipse m2e插件将jdk用于项目 - How to force Eclipse m2e plugin to use jdk for a project 在Eclipse m2e中,如何引用工作区项目? - In Eclipse m2e, how to reference workspace project? 如何使用m2e创建一个简单的Maven项目 - How to create a simple maven project using m2e 如何在Eclipse中打开Java项目(使用Maven)? (我使用M2E还是maven-eclipse-plugin) - How do I open a Java project (that uses maven) in Eclipse? (Do I use M2E or maven-eclipse-plugin) M2Eclipse:当Maven更新工作区中的项目时,如何避免M2E更改我的类路径 - M2Eclipse: How to avoid M2E to change my classpath while maven updating project in workspace 如何升级M2E版本 - how to upgrade version of m2e 为什么M2e插件在Maven jar项目的目标文件夹中构建为WEB-INF / classs? - Why does the m2e plugin build to a WEB-INF/classes in the target folder for a maven jar project? m2e插件-Eclipse-创建了Java类和包。 不被认可为项目的一部分 - m2e plugin - Eclipse - created Java class and package. Not recognized as part of the project 保存文件时,如何使eclipse m2e构建当前项目以及引用该文件的EAR项目? - On saving a file, how to make eclipse m2e build the current project AND the EAR project that references it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM