13

我有一个使用 Apache Xmlbeans 进行数据绑定的项目。目前它非常简单,它只有 src/main/xsd 中的一些 Schema-Files 和 src/main/xsdconfig 中的 xsdconfig。

我想将生成的类包含到生成的 jar 文件中。如果我指定 xmlbeans 目标,它会起作用:“mvn xmlbeans:xmlbeans package”-> 使用 xmlbeans 类创建一个 Jar

但我想在正常的构建周期内执行此操作:“mvn package”-> 应该使用 xmlbeans 类创建一个 jar,但不会。

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>

我试图将它手动绑定到“生成源”(以及“编译”阶段)阶段,但它不起作用。

<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 中?

问候,勒拉德

4

2 回答 2

15

如果在下配置插件pluginManagement,仍然需要在 下声明plugins。为了简化,我没有pluginManagement在下面的 pom.xml 中使用:

<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 生成的,作为构建的一部分进行编译和打包)。

于 2010-06-14T15:55:18.077 回答
-3

试试这个。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>xmlbeans-maven-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
        <execution>
            <id />
            <phase>generate-sources</phase>
            <goals>
                <goal>xmlbeans</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>src/main/xsd</schemaDirectory>
        <staleFile>${project.build.directory}/generated-sources/xmlbeans/.staleFlag</staleFile>
        <verbose>false</verbose>
        <quiet>false</quiet>
        <javaSource>1.6</javaSource>                    
    </configuration>
</plugin>
于 2011-03-01T03:07:51.440 回答