Maven JAR with Dependencies: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "!!!Jar With Dependencies {{{ <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
!!!Jar With Dependencies
=Internal=


{{{
* [[Maven_assembly_Plugin#Other_Assembly_Use_Cases|Maven assembly Plugin]]
 
=Overview=
 
=assembly.xml=
 
<pre>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Line 22: Line 28:
   </fileSets>
   </fileSets>
</assembly>
</assembly>
}}}
</pre>
 
 
!!!Create an executable jar
 
{{{
<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          [...]
          <archive>
            <manifest>
              <mainClass>org.sample.App</mainClass>
            </manifest>
          </archive>
        </configuration>
        [...]
      </plugin>
      [...]
</project>
 
}}}
 
 
 
 
 
 
 
 
 
 
 
 
!!!Create an assembly file without any suffix
 
By default, the assembly name is the &lt;projectname&gt;-&lt;assemblyid&gt;.&lt;ext&gt; If I just want it to be &lt;projectname&gt;.&lt;ext&gt;, don't use any
{{{
    <id>...</id>
}}}
in the assembly descriptor.
 
!!!Creating two assemblies for the same project
 
{{{
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
      <executions>
          <execution>
              <id>jar-with-all-dependencies</id>
      <phase>package</phase>
              <goals>
                  <goal>single</goal>
              </goals>
              <configuration>
                  <descriptors>
                      <descriptor>src/main/assembly/jar-with-all-dependencies.xml</descriptor>
                  </descriptors>
                  <archive>
                      <manifest>
                          <mainClass>${exec.main.class}</mainClass>
                      </manifest>
                  </archive>
              </configuration>
          </execution>
          <execution>
              <id>distribution-bundle</id>
              <phase>package</phase>
              <goals>
                    <goal>single</goal>
              </goals>
              <configuration>
                    <descriptors>
                            <descriptor>src/main/assembly/distribution-bundle.xml</descriptor>
                    </descriptors>
              </configuration>
          </execution>
          </executions>
</plugin>
}}}

Latest revision as of 15:47, 7 November 2016

Internal

Overview

assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <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>