Icon

Software Engineering, Architecture, Web Development and beyond…

Howto package executable JARs with Maven

If you want to build your project as executable JAR with maven, the maven assembly plugin would be useful.

<descriptorRef>jar-with-dependencies</descriptorRef>

part causes the dependent libraries to be packed into the JAR together with your project sources. “mainClass” of manifest section configures “Main-Class:” of Manifest file of an executable JAR.

<plugins>
  <plugin>
   <artifactId>maven-assembly-plugin</artifactId>
   <configuration>
   <archive>
      <manifest>
         <mainClass>com.foo.MainClass</mainClass>
      </manifest>
   </archive>
   <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
   </configuration>
   </plugin>
</plugins>

now run mvn with assembly:assembly

$ mvn -e clean assembly:assembly

Good Luck!

erhan

Author


Hello, I'm Erhan Bagdemir and this is my blog. I talk about Java, J2EE, Frameworks, web application development, OOAD and various other topics often related to programming.

Erhan Bagdemir  Profil von Erhan Bagdemir auf LinkedIn anzeigen

ebagdemir on Stackoverflow

ebagdemir on Twitter

    Hamburg

    Slideshow