Scott Frazer
Scott Frazer

Reputation: 2185

Maven is generating 2 JARs when I only want one

This is some output of my 'mvn package' command:

[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ my-project ---
[INFO] Building jar: /Users/sfrazer/projects/my-project/target/my-project-0.0.1.jar
[INFO] 
[INFO] --- maven-assembly-plugin:2.2-beta-5:single (jar-with-dependencies) @ my-project ---
[INFO] Building jar: /Users/sfrazer/projects/my-project/target/my-project-0.0.1-jar-with-dependencies.jar

The second jar is the correct one that I specified to build but I'm at a loss as to why the first one is being created. So I have two questions:

1) Why is the first JAR being created?

2) How do I make the second JAR be named the way the first one is?

the pom.xml is very long, but here's the relavent part for building the second JAR:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <mainClass>my.package.App</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Upvotes: 0

Views: 755

Answers (2)

matt b
matt b

Reputation: 140061

my-project-0.0.1.jar is created because maven-jar-plugin:jar is automatically bound to the package phase for projects that have jar packaging.

It would be a bad idea to disable it because other projects that depend on the artifacts of my-project would want to include a JAR of just my-project, and not a super-jar including all it's dependencies.

Upvotes: 2

Integrating Stuff
Integrating Stuff

Reputation: 5303

Because the jar-with-dependencies execution is defined as an extra execution, not a replacement of the regular jar goal, which is part of a regular package or install run.

Some people tried to disable it in this question, but in general, when making a jar with all dependencies included with maven, the "normal jar" is just packaged alongside with it/left untouched.

Upvotes: 2

Related Questions