Maven how to create jar file along with dependencies

In maven based projects dependencies can be specified in pom.xml.There are scenarios we may need build the jar file along with required dependent jar files.This is the case when we get the libraries from third party vendors. Lets take the simple example, we wanted to create simple jar file which includes all dependent files with in jar final jar file. Add the below plugin in your build configuration.Final name is the option to mention resulting jar file name.

<build>
  <finalName>Final</finalName>
  <plugins>
   <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
     <execution>
      <phase>install</phase>
      <goals>
       <goal>single</goal>
      </goals>
     </execution>
    </executions>
    <configuration>
     <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
     </descriptorRefs>
     <appendAssemblyId>false</appendAssemblyId>
    </configuration>
   </plugin>
  </plugins>
 </build>
Post a Comment (0)
Previous Post Next Post

Recent Posts