问题描述
我有一个使用Apache Xmlbeans进行数据绑定的项目.当前非常简单,它在src/main/xsd中只有一些Schema-Files,而在src/main/xsdconfig中只有xsdconfig.
I have a project which uses Apache Xmlbeans for databinding. Currently it is very simple it only has some Schema-Files in src/main/xsd and xsdconfig in src/main/xsdconfig.
我想将生成的类包含到生成的jar文件中.如果我指定xmlbeans目标,它将起作用:"mvn xmlbeans:xmlbeans包"->使用xmlbeans类创建一个Jar.
I want to include the generated Classes into the generated jar-File. It works if I specify the xmlbeans goal:"mvn xmlbeans:xmlbeans package" --> Creates a Jar with the xmlbeans classes
但是我想在正常的构建周期内执行此操作:"mvn package"->应该使用xmlbeans类创建一个jar,但不会.
But I want to do this within the normal build cycle: "mvn package" --> should create a jar with the xmlbeans classes, but won't.
以下是pom:
<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>org.test</groupId>
<artifactId>xmlbeans-maven-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
我尝试将其手动绑定到"generate-sources"(也绑定到"compile"阶段)阶段,但是它不起作用.
I tried to bind it manually to the "generate-sources" (And to the "compile" phase, too) phase, but it does not work.
<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>de.leradon</groupId>
<artifactId>xmlbeans-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>maven-xmlbeans-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
如何配置插件,以便在运行"mvn package"时将所有生成的类打包到jar中?
How can I configure the plugin, so that when I run "mvn package" all the generated classes are packaged into the jar?
问候,莱拉德
推荐答案
如果您配置在pluginManagement
下的插件,则仍需要在plugins
下声明它.为简化起见,我不在下面的pom.xml中使用pluginManagement
:
If you configure the plugin under pluginManagement
, you still need to declare it under plugins
. To simplify, I'm not using the pluginManagement
in the pom.xml below:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
有了此POM(以及src/main/xsd
中的某些XSD,这是默认位置),运行mvn clean package
就可以了(即从XSD生成源代码,将其编译并打包为构建的一部分).
With this POM (and some XSD in src/main/xsd
which is the default location), running mvn clean package
just works (i.e. sources are generated from the XSD, compiled and packaged as part of the build).
这篇关于如何自动将xmlbeans生成的代码包含到Maven jar中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!