【问题标题】:maven-assembly-plugin for certain files某些文件的 maven-assembly-plugin
【发布时间】:2009-11-23 15:59:26
【问题描述】:

我有一个多模块项目,这是父 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>

在原子持久性项目中,我有以下文件:

com.atoms.vo.*

com.atoms.service.*

com.atoms.dao.*

在我拥有的 atom-reglas 中:

com.atoms.rules.*

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

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

【问题讨论】:

  • 我已经回复了您的评论。请提供更新后的 pom.xml,显示您正在使用的 maven-assembly-plugin 的版本。

标签: java maven-2 maven-assembly-plugin


【解决方案1】:

尝试以下方法:

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

【讨论】:

【解决方案2】:

首先,在您的pom.xmlincludes/excludes 中的 unpackOptions在 2.2-beta-3 之前的版本中,''ll need later don't act as expected in 2.2-beta-3).我在这里使用的是 2.2-beta-4 版本:

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

然后,使用您选择的模块声明 moduleSets,并指定您要在 assembly.xml 中使用 includes 解压缩其二进制内容:

<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

【讨论】:

  • 您是否更新了 pom.xml 以使用版本 2.2-beta-4(或 2.2-beta-3)的 maven-assembly-plugin?我之前测试过这个来发布它。请提供您的 pom.xml 的更新版本。
  • 是的,我尝试使用 2.2-beta-4 maven-assembly-plugin2.2-beta-4assemble.xml
  • 请更新您的问题并提供有关您的设置和实际结果的更多信息。正如我所说,我对此进行了测试,它在 maven 2.2.1 和 maven-assembly-plugin 2.2-beta-4 上运行良好。
猜你喜欢
  • 1970-01-01
  • 2014-09-05
  • 1970-01-01
  • 2012-03-25
  • 2016-10-13
  • 2016-02-13
  • 2010-11-22
  • 1970-01-01
  • 2013-07-29
相关资源
最近更新 更多