2

我有多模块项目,这是父 pom。

<?xml version="1.0" encoding="UTF-8"?>
<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>com.atoms</groupId>
    <artifactId>atoms-parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>
    <url/>
    <modules>
        <module>atoms-persistence</module>
        <module>atoms-reglas</module>
        <module>atoms-webservice</module>
    </modules>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>

                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>assemble.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

在项目 atom-persitence 中,我有以下文件:

com.atoms.vo.*

com.atoms.service.*

com.atoms.dao.*

在atoms-reglas中我有:

com.atoms.rules.*

我如何使用程序集插件来制作一个只有以下类的 jar:

com.atoms.vo.* 和 com.atoms.rules.* ?

4

2 回答 2

5

尝试以下方式:

<assembly>
    <id>atoms</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${basedir}/target/classes
            </directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>com/atoms/vo.**</include>
                <include>com/atoms/rules/**</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>
于 2009-11-23T16:10:44.500 回答
1

首先,明确指定您要在您的pom.xml(您稍后需要的元素的includes/在 2.2 之前的版本中不符合预期-beta-3)。我在这里使用 2.2-beta-4 版本:excludesunpackOptions

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <configuration>
    <descriptors>
      <descriptor>assemble.xml</descriptor>
    </descriptors>
  </configuration>
</plugin>

然后,使用您选择的模块声明 amoduleSets并指定您要includes在您的assembly.xml:

<assembly>
  <id>my-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
        <include>com.atoms:atoms-persistence</include>
        <include>com.atoms:atoms-reglas</include>
      </includes>
      <binaries>
        <outputDirectory>/</outputDirectory>
        <unpack>true</unpack>
        <unpackOptions>
          <includes>
            <include>com/atoms/vo/**</include>
            <include>com/atoms/rules/**</include>
          </includes>
        </unpackOptions>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

最后,从父项目运行以下命令:

mvn clean package assembly:assembly

这将构建一个target/atoms-parent-1.0-my-assembly.jar仅包含所需类的类。

于 2009-11-23T16:13:48.660 回答