티스토리 뷰

Guide to Working with Manifests

In order to modify the manifest of the resultant JAR produced by the jar plug-in you need to create a configuration for the jar plug-in. In this first example we'll add some entries to the manifest by specifying what we'd like in the configuration element of the jar plug-in:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <mode>development</mode>
              <url>${pom.url}</url>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

As you see above you can use literal values or you can have values from the POM interpolated into literals or simply use straight POM expressions. So this is what your resultant MANIFEST.MF will look like inside the generated JAR:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jvanzyl
Build-Jdk: 1.4.2_09
Extension-Name: my-app
Specification-Vendor: MyCompany Inc
Implementation-Vendor: MyCompany Inc
Implementation-Title: my-app
Implementation-Version: 1.0-SNAPSHOT
mode: development
url: http://maven.apache.org

If you need to do more then simply add some manifest entries there are more options like activating indexing of the JAR, setting the main-class, packageName ... Here's an example of what the configuration element of the JAR plug-in might look like:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <archive>
            <!--
            <index>true</true>
            -->
            <manifest>
              <mainClass>com.mycompany.app.App</mainClass>
              <packageName>com.mycompany.app</packageName>
              <!-- options
              <addClasspath>true</addClasspath>
              <addExtensions/>
              <classpathPrefix/>
              -->
            </manifest>
            <manifestEntries>
              <mode>development</mode>
              <url>${pom.url}</url>
            </manifestEntries>
            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

So this is what your resultant MANIFEST.MF will look like inside the generated JAR:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jvanzyl
Package: org.com.foo.app
Build-Jdk: 1.4.2_09
Extension-Name: my-app
Specification-Vendor: MyCompany Inc
Implementation-Vendor: MyCompany Inc
Implementation-Title: my-app
Implementation-Version: 1.0-SNAPSHOT
Main-Class: org.com.foo.App
mode: development
url: http://maven.apache.org
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/09   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함