3

我已将我的程序集描述符配置为具有 jar 类型的程序集

<formats>
  <format>jar</format>
</formats>

但是,在运行 mvn install 时获取 zip 文件而不是 jar。我哪里出错了?

4

2 回答 2

2

你为什么不使用预定义的程序集jar-with-dependencies?在描述符文件下方:

<assembly>
  <id>jar-with-dependencies</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
    </fileSet>
  </fileSets>
</assembly>

要使用assembly:assembly预定义的描述符,请运行:

mvn assembly:assembly -DdescriptorId=jar-with-dependencies

要将程序集作为正常构建周期的一部分生成,请将单目录或单目录 mojo 绑定到包阶段(请参阅用法):

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- append to the packaging phase. -->
            <goals>
              <goal>single</goal> <!-- goals == mojos -->
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>
于 2009-09-08T11:00:24.213 回答
2

此配置生成一个 jar 程序集,其分类器jar-assembly仅包含目标/类的内容。如果需要将其他内容添加到 jar 中,您可以添加其他文件集。为确保您的目标目录中没有任何先前运行的 zip 存档,您可以将其删除或运行mvn clean.

<assembly>
  <id>jar-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

插件配置应如下所示。注意将 appendAssemblyId 设置为 false 将导致默认 jar 被程序集中的 jar 替换,如果这不是所需的行为,请删除该元素:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-2</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
          <descriptor>src/main/assembly/archive.xml</descriptor>
        </descriptors>
      </configuration>
    </execution>
  </executions>
</plugin>    
于 2009-09-08T11:14:22.047 回答