使用带有 WTP 的 Maven Eclipse 插件的怪癖
我正在使用 Maven Eclipse 插件生成 wtp 项目。它基本上可以工作,但有一些我想摆脱的奇怪怪癖:
- 每次运行
mvn eclipse:eclipse
时都必须指定-Dwtpversion=2.0
。否则,不会生成构面信息。 - javafacet级别设置为版本1.4而不是6.0,这导致每个生成的项目都有错误
Java编译器级别与安装的Java项目facet的版本不匹配
我该如何摆脱这些怪癖?
下面是我的顶级 pom.xml。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.foo</groupId>
<artifactId>foo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>foo</name>
<url>http://maven.apache.org</url>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<additionalProjectFacets>
<jst.web>3.0</jst.web>
</additionalProjectFacets>
</configuration>
</plugin>
</plugins>
</build>
</project>
I'm using the maven eclipse plugin to generate wtp projects. It mostly works, but there are some strange quirks that I'd like to get rid of:
- I must specify
-Dwtpversion=2.0
each time I runmvn eclipse:eclipse
. Otherwise, facet information is not generated. - The java facet level is set to version 1.4 instead of 6.0, which causes each generated project to have an error
Java compiler level does not match the version of the installed Java project facet
How do I get rid of these quirks?
Below is my top-level pom.xml.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.foo</groupId>
<artifactId>foo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>foo</name>
<url>http://maven.apache.org</url>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<additionalProjectFacets>
<jst.web>3.0</jst.web>
</additionalProjectFacets>
</configuration>
</plugin>
</plugins>
</build>
</project>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有同样的问题。
我通过在
声明中将编译器插件的源版本和目标版本设置为预期版本来修复此问题:请注意,使用用户属性
maven.compiler.target
和maven.compiler.souce
代替插件配置,仍然使 eclipse 插件生成 1.4 java facet。I had the same issue.
I fixed it by setting the source and target version of the compiler-plugin to the expected version in a
<plugin-management>
declaration:Note that using the user properties
maven.compiler.target
andmaven.compiler.souce
instead of the plugin configuration, still makes the eclipse plugin to generate a 1.4 java facet.你做错事了。您可以使用 maven-eclipse-plugin (已停产或至少不再开发),或使用 m2eclipse。两者都不是。使用 m2eclipse,但请确保您还安装了 m2eclipse extras。由于一些奇怪的原因,这是两个更新站点,而不仅仅是一个。如果您成功安装了 extras,并使用标准的 web 或 ejb 工件,并且使用 m2eclipse 的项目创建向导,则 eclipse 配置将由 m2eclipse extras 自动呈现。
更新:
抱歉,maven eclipse 插件仍然存在。查看了问题跟踪系统。
首先
,第一眼看到时,我毫无头绪。 源代码告诉我们,它是一个简单的mojo参数(可以来自配置标签)。您唯一可以考虑的是,该配置在 POM 内共享(根据我的经验)。因此,如果您在 POM 顶部使用插件,并且也在底部使用,则配置是共享的(或相同的),这可能是两者的一些总结(应在源代码中检查)。因此 wtpversion 可能碰巧在 POM 中的其他位置定义,或者在 父 POM 中定义。该定义只能被环境条目覆盖。引自 Maven 文档:
插件执行第二
对于第二个,我认为您应该在additionalfacets 中声明 jst.java 方面版本。像这样: 在此 POM 中:
建议
M2eclipse 有其自身的问题。另一方面,没有必要仅仅因为 Eclipse 就修改 POM。因此,在它满足您的需要之前,您应该使用 m2ecipse + extras 而不是 maven eclipse 插件。
You do something wrong. You can use maven-eclipse-plugin (which is discontinued or at least not developed anymore), or use m2eclipse. Not both. Use m2eclipse, but make sure, that you installed m2eclipse extras as well. For some strange reasons these are two update sites, not only one. If you install extras successfully, and use standard web or ejb artifacts, eclipse configuration will be rendered by m2eclipse extras automatically if you use project creation wizard of m2eclipse.
UPDATE:
Sorry, maven eclipse plugin is still alive. Took a look at Issue tracking system.
First
For the first sight, I have no clue. The source code tells, that it is a simple mojo parameter (that can come from configuration tag). The only thing you can consider is, that configuration is shared inside a POM (according to my experience). So if you use a plugin at the top of the POM, and you use at the bottom as well, the configuration is shared (or the same), which is probably some summary of the two (should be checked in source). So wtpversion may happen to be defined somewhere else inside your POM, or in the parent POMs. This definition can be overridden by only an environment entry. Quotes from Maven documentation:
Second
For the second I think you should state jst.java facet version in additionalfacets. Like this: in this POM:
Suggestion
M2eclipse has its own problems. On the other hand there is no need to hack your POM just because of Eclipse. So until it fits Your need, You should use m2ecipse + extras instead of maven eclipse plugin.
对于 jst.web 版本,Maven eclipse 插件会考虑项目的依赖关系。如果您定义了 servlet api 依赖项:
您的 jst.web 参数将为 6.0
For the jst.web version the Maven eclipse pluging takes into accound the dependencies of the project. If you have a servlet api dependency defined :
You jst.web parameter will be 6.0