maven-2maven-plugin

adding manifest to jar file while compiling with maven2


I have made following changes to the POM.xml file for adding a manifest file that i have kept in \resources\META-INF But am unable to create an executable jar file.

<build>
  <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.5</source>
        <target>1.5</target>
          <archive>
            <manifest>
            <mainClass>com.mypackage.myMainClass</mainClass>
            <!--addClasspath>false</addClasspath-->
            </manifest>
            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
          </archive>
        </configuration>
    </plugin>
  </plugins>
</build>

Any suggestions?


Solution

  • use the maven-assembly-plugin.

    Example:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>foo.bar.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
         </plugins>
    </build>