Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create executable JAR file with dependencies using Maven?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 412
    Comment on it

    Using maven we can create executable JAR file with all the requires dependencies and then we can use that JAR file to execute the whole project. So, to create the JAR file just add the below plugin inside the build tag.

    <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>

    Now after installing the desired desired dependencies through <b>mvn install</b>, launch the goal to create the JAR file.

    mvn clean compile test assembly:single


    The executable JAR file will be created inside the "Target" folder of project directory.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: