How do I add my own manifest file to a jar file?
Author: Deron Eriksson
Description: This tutorial describes how to add a custom manifest file to a jar file.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
In another tutorial, we saw how the contents of the src/main/resources folder in a mavenSW project with "jar" packaging get copied to the root level of the generated jarW file. We saw how we could put a META-INF directory in the resources directory, and files placed within META-INF could get copied into the META-INF directory of the jar file. What happens if we put a MANIFEST.MF file within src/main/resources/META-INF/MANIFEST.MF? Perhaps surprising, this file will NOT by default get copied into the generated jar file. If we'd like the values in our MANIFEST.MF file to get copied over, we need to add a reference to this file in our pom.xml file, as shown here. pom.xml<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.maventest</groupId> <artifactId>aproject</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>aproject</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> </archive> </configuration> </plugin> </plugins> </build> </project> I created the following MANIFEST.MF file. src/main/resources/META-INF/MANIFEST.MFBacon: Eggs Here: There (Continued on page 2) |