10

I try to generate a .zip file with maven (mvn package) and want to have a MANIFEST file in the zip too. The jar file itself does work. I tried to generate a MANIFEST file with maven jar plugin, but it did not work. Do I Have to do something else to get a MANIFEST file, or is it enough to use this plugin? The parent pom (parent of the parent I showed) has maven assembly plugin. (I´m completely new to maven)

pom.xml file of the parent pom:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

pom.xml file of the module:

<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <archive>
        <manifest>
          <mainClass>org.jis.Main</mainClass>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
    </configuration>
</plugin>
</plugins>

Lua Mia
  • 103
  • 1
  • 1
  • 6
  • 1
    Please refer to this answer: [http://stackoverflow.com/questions/2514429/creating-a-zip-archive-of-the-maven-target-directory](http://stackoverflow.com/questions/2514429/creating-a-zip-archive-of-the-maven-target-directory) – BlackHat May 05 '17 at 20:32

3 Answers3

6

In your case maven must be called like:

mvn clean package assembly:single

The other way to achive same result is to modify your pom:

  <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> 
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
 </plugin>

then run:

mvn clean package

ref: https://maven.apache.org/plugins/maven-assembly-plugin/usage.html

csenga
  • 3,819
  • 1
  • 21
  • 31
  • So the maven jar plugin on it´s own is not enough? Because a friend of mine did not have the assembly plugin and it worked fine for her and she also did not need to specify something in the parent pom, like I did. (it´s for school). For what exactly do I need the assembly plugin? ( I try to understand all of this to not just copy code) – Lua Mia May 06 '17 at 08:37
  • So the maven jar plugin on it´s own is not enough? > Yes, it does not enough on its own, because it can not handle your dependencies, you must get them to your classpath somehow. Besides assembly-plugin there are other approches eg. simple dependency copying:https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/ – csenga May 06 '17 at 09:42
  • Is it enough, if the maven assembly plugin is added in the parent pom? Because we work with a given parent pom and I looked it up and there is the maven-assembly-plugin specified. (BTW thanks for your help) – Lua Mia May 06 '17 at 09:53
0

I had the same issue where I was suddenly unable to run jars from CLI, removing the <pluginManagement> tag created the manifest for me.

  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 02:43
0

I had the same issue, removing the tag from pom file helped me

  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '22 at 22:15