Maven JAXB2 XJC插件:M2E插件执行未覆盖

时间:2023-01-26 09:25:26

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生成java文件。因此,我曾经配置我的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 covered but the source files are not generated when executing the generate-sources phase.

我遵循了这个页面M2E插件执行的说明,但是在执行generalsource阶段时没有生成源文件。

Could anybody show me how to exactly refactor my pom so that my files are properly generated?

有人能告诉我如何重构我的pom以便我的文件被正确地生成吗?

Thanks for helping!

谢谢你的帮助!

3 个解决方案

#1


15  

It turns out that I did eventually 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 * question, and adopted it to the "jaxb2-maven-plugin" plugin rather than the plugin at issue in the the other question.

我在另一个*的问题上找到了这段代码,并将它应用到“jaxb2-maven-plugin”而不是另一个问题中的plugin。

#2


3  

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不支持的插件。

#3


0  

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安装从命令行构建。然后,Eclipse将使用repo的包,而不是试图自己构建,不需要(我花了相当长的时间使用)不需要任何增量的解决方案,也没有红色的模块/行,构建速度也更快。

#1


15  

It turns out that I did eventually 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 * question, and adopted it to the "jaxb2-maven-plugin" plugin rather than the plugin at issue in the the other question.

我在另一个*的问题上找到了这段代码,并将它应用到“jaxb2-maven-plugin”而不是另一个问题中的plugin。

#2


3  

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不支持的插件。

#3


0  

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安装从命令行构建。然后,Eclipse将使用repo的包,而不是试图自己构建,不需要(我花了相当长的时间使用)不需要任何增量的解决方案,也没有红色的模块/行,构建速度也更快。