java Maven JAXB2 XJC 插件:未涵盖 M2E 插件执行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10387610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven JAXB2 XJC plugin: M2E plugin execution not covered
提问by Jean Logeart
I am using using the jaxb2 xjc
plugin for generating java files from a XSD
. Therefore I used to configure my pom.xml as follows:
我正在使用该jaxb2 xjc
插件从XSD
. 因此,我用来配置我的 pom.xml 如下:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.mypackage.model</packageName>
<schemaDirectory>${basedir}/src/main/resources/XSD</schemaDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
I changed my developing environment to Eclipse Indigo and this does not work any more. The error says: "Plugin execution not covered by lifecycle configuration". I understand I have to define the execution of my plugin differently so that it works in my new environment.
我将我的开发环境更改为 Eclipse Indigo,这不再起作用。错误说:“生命周期配置未涵盖插件执行”。我知道我必须以不同的方式定义我的插件的执行,以便它在我的新环境中工作。
I followed the instructions on this page M2E plugin execution not coveredbut the source files are not generated when executing the generate-sources
phase.
我按照此页面上的说明进行了未涵盖 M2E 插件执行但在执行generate-sources
阶段时未生成源文件。
Could anybody show me how to exactly refactor my pom so that my files are properly generated?
有人能告诉我如何准确重构我的 pom 以便正确生成我的文件吗?
Thanks for helping!
感谢您的帮助!
回答by Steve Perkins
It turns out that I dideventually find an answer! Eclipse's integration with Maven has known compatibility issues with numerous Maven plugins.
事实证明,我最终确实找到了答案!Eclipse 与 Maven 的集成已知存在与众多 Maven 插件的兼容性问题。
When you can successfully run a Maven build from the command-line outside of Eclipse, yet but Eclipse shows "execution not covered" errors in your POM, then try adding this plugin:
当您可以从 Eclipse 之外的命令行成功运行 Maven 构建,但 Eclipse 在您的 POM 中显示“执行未涵盖”错误时,请尝试添加此插件:
<build>
...
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<versionRange>[1.3,)</versionRange>
<goals>
<goal>xjc</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
As indicated in the above comment, this plugin doesn't do anything outside of Eclipse. It simply tells Eclipse when to execute the JAXB plugin, since Eclipse isn't smart enough to figure that out on its own.
正如上面的评论中所指出的,这个插件在 Eclipse 之外不做任何事情。它只是告诉 Eclipse 何时执行 JAXB 插件,因为 Eclipse 不够聪明,无法自行解决。
I found this snippet on another StackOverflow question, and adopted it to the "jaxb2-maven-plugin" plugin rather than the plugin at issue in the the other question.
我在另一个 StackOverflow 问题上找到了这个片段,并将它用于“jaxb2-maven-plugin”插件,而不是另一个问题中的有问题的插件。
回答by davidfmatheson
You could also switch to the maven-jaxb2-plugin
which has support in M2E. Steve Perkins' answer above is generally applicable for those plugins which M2E doesn't support, though.
您也可以切换到maven-jaxb2-plugin
M2E 支持的。不过,Steve Perkins 的回答通常适用于 M2E 不支持的那些插件。
回答by tomasb
I'm not sure if this applies to your environment, but if the app is split into maven modules then the best solution fitting my needs I found so far is to remove all affected modules from eclipse IDE. Whenever I need to regenerate I simply build from command line with mvn install. Eclipse is then using packages from repo and not trying to build on its own, no runOnIncremental
fiddle-around needed (which I was using for quite some time), no red modules/lines, builds faster too.
我不确定这是否适用于您的环境,但是如果应用程序被拆分为 maven 模块,那么我目前找到的最适合我的需求的解决方案是从 eclipse IDE 中删除所有受影响的模块。每当我需要重新生成时,我只需使用 mvn install 从命令行构建。Eclipse 然后使用来自 repo 的包,而不是尝试自己构建,不需要runOnIncremental
摆弄(我使用了很长一段时间),没有红色模块/行,构建速度也更快。