#AskMe

Generate jar and manifest Info in Jar in maven 2

To create jar packaging of Java project with maven 2 based, we used a plugin called: maven-jar with simply paste the code below in pom.xml of plugins section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
	<version>2.4</version>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
</plugin>

And if you want to add in your jar’s MANIFEST info, you can directly modify above plugin configuration as:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
	<version>2.4</version>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
          <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
          <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
        </manifest>
      </archive>
    </configuration>
</plugin>

Note: If your pom.xml does not have a <name> element, then the Specification-Title and Implementation-Title entries will have “Unnamed – ${project.groupId}:${project.artifactId}:${project.version}” as their value.

Another post about manifest issue related custom string in manifest classpath, see stackoverflow here.

Example:

<plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.osify.training.MyMainClass</mainClass>
              <addClasspath>true</addClasspath>
              <classpathPrefix>./</classpathPrefix>
            </manifest>
            <manifestEntries>
              <Class-Path>./../config/ j2ee.jar</Class-Path>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
</plugins>