Jar format support for assembling Maven assemblies?

I configured my assembly descriptor to build a type collector

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

However, when running mvn install, get the zip files instead of jar.Where did I go wrong?

+3
source share
2 answers

This configuration creates a jar assembly with a classifier jar-assemblycontaining only the contents of the target / classes. If necessary, you can add additional sets of files to add other content to the jar. To make sure that you do not have zip archives from any previous runs in your target directory, you can delete it or run it 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 , , :

<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>    
+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 (. Usage):

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

Source: https://habr.com/ru/post/1717133/


All Articles