2

以下代码段创建了 2 个 JARS:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>build-dependency</id>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>dependency</classifier>
                <classesDirectory>${project.build.directory}\dependency</classesDirectory>
                <includes>
                    <include>${dependancyInclude}</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <classifier>module</classifier>
                <classesDirectory>${project.build.directory}\classes</classesDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

我想使用程序集插件将这两个 JAR 合并为一个,目前我有以下内容:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <!-- Combine all the JARs in the /target folder into one JAR -->
        <execution>
            <id>make-assembly</id>
            <phase>compile</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <attach>true</attach>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <appendAssemblyId>true</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>

目前只有两个 JARS 之一包含在由程序集插件创建的最终 JAR 中。

4

1 回答 1

3

如果我理解正确,您实际上是想将 jar 文件合并到一个大 jar 文件中。这可以使用 maven-shade-plugin(而不是 maven-assembly-plugin)来实现。

例如:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.0</version>
        <configuration>
           <!-- Put your configuration here, if you need any extra settings.
                (You should be okay with the defaults). -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
于 2013-03-26T12:32:56.533 回答