-2

I already saw lot of post related to this question, but hard to figure out the best approach of doing this. I am having a maven project having two dependencies (A.Jar) and (B.Jar) in maven central repostories. I want to create a runnable jar. Which is the best approach in doing this and how to do this ? An example will be helpful. (sample POM.XML)

thanks !

DevMonk
  • 427
  • 1
  • 9
  • 23
  • 2
    possible duplicate of [How can I create an executable jar with dependencies using Maven?](http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven) – Cem Catikkas Oct 18 '14 at 05:50

1 Answers1

0

The simplest solution would be to use maven-assembly-plugin via a predefined descriptor:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
      <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>    
    </plugin>
  </plugins>
</build>

Via the above you can do simply:

mvn clean package

which results in having a file target/whatever-1.0-SNAPSHOT-jar-with-dependencies.jar which is exactly what you like to get.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235