maven jar选项,在构建期间创建一个额外的jar

时间:2013-08-05 13:41:24

标签: maven maven-2 maven-3 maven-plugin

在尝试创建maven构建时,我需要使用资源库,javadoc jar和编译类jar,这可以通过现有的插件轻松实现。

但我确实在src/main/resources/xsd文件夹下有XSD,我更喜欢在构建过程中在一个不同的jar中创建,是否可能?

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

好吧,MAVEN本身不支持单个pom.xml的多个工件。但是你可以创建另一个只有pom的空项目来创建另一个jar

codebase
    |- pom.xml
    |- src
    |- xsdJar
        |- pom.xml
    |- [other stuff]

现在,在xsdJar\pom.xml

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <includes>
            <include>../src/main/resources/xsd/*</include>
          </includes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

另外,请在主pom.xml

中调用上述模块
<modules>
  <module>xsdJar</module>
</modules>

答案 1 :(得分:0)

您可以使用自定义插件或assembly为maven版本添​​加其他人工制品。程序集允许您将任何资源组定义为新的工件。这个新的人工制品将以现有的方式“附着”,就像源罐子一样。

创建程序集时,需要定义描述符并将其放在src/main/assembly/xsd.xml

之类的位置

描述符看起来像:

<assembly>
   <id>xsd</id>
   <formats>
      <format>zip</format>
   </formats>
   <fileSets>
      <fileSet>
           <directory>src/main/resources/xsd</directory>
           <includes>
               <include>*.xsd</include>
           </includes>
      </fileSet>
  </fileSets>
</assembly>

第二部分是程序集插件配置,它看起来像:

  <build>   
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/xsd.xml</descriptor>
          </descriptors>           
        </configuration>
        <executions>
              <execution>
              <id>make-xsd-zip</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- bind to the packaging phase -->
              <goals>
                <goal>single</goal>
              </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

此配置应该为您提供名称为<artifactid>-<version>-<assemblyid>.zip

的人工制品