Undefined Title

One of simple ways to package executable single jar with maven

2012-08-08

It’s using two plugins, jar and shade.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
          <mainClass>com.your.class.Name</mainClass>
        </manifest>
      </archive>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <!-- To build executable jar, type "mvn package" -->
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
    </execution>
  </executions>
</plugin>

And then just type such as

mvn package
java -jar target/your-artifactId-version.jar

What a simple way :)