Creating a Jar using Maven

In the earlier post, we had seen how to create a jar, in this post we will see how to create a jar using maven. Following are key points in creating the jar using maven.

1. Specify the packaging type e.g. jar.

2. Compile the source code. Use  maven-compiler-plugin here.

3. Generate eclipse related files like .classpath, etc. Use maven-eclipse-plugin. [optional]

4. Bundle the java class files in a jar. Use maven-jar-plugin.

5. Provide the main-class[entry point] for your jar in the mainfest.

6. Execute the unit-tests of your jar before creating the jar. [optional]

Refer to the sample pom.xml below:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
  <packaging>jar</packaging> <!--1.Packaging Type -->
  <name>Blog Reader</name>


        <artifactId>maven-compiler-plugin</artifactId> <!--2.Compiles the source-code -->
        <artifactId>maven-eclipse-plugin</artifactId> <!--3.Generates the eclipse-related files -->
        <artifactId>maven-jar-plugin</artifactId><!--4.Creates a jar -->
              <mainClass></mainClass><!--5.Add main class -->
        <artifactId>maven-surefire-plugin</artifactId><!--6.Executes the unit-test cases -->



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s