Monday, July 13, 2015

Creating the jar file from POM

Hello Friends, today we are going to see how to create a jar file with the use of Maven.

Here I am providing you the basic setup of creating the jar file from Maven(POM).

Open your pom.xml file and attach the following code in the field named <build>.

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>Name of the main class, with full package details</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>


Now when you have to package the project use this:

  • clean compile assembly:single


This will generate the jar in the target folder if using the Eclipse IDE.

Thanks.

No comments:

Post a Comment