Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
930 views
in Technique[技术] by (71.8m points)

maven 2 - Disable the default-jar execution

I am using Maven Assembly plugin to pack a jar file.

But when I run mvn package, maven always trigger the [jar:jar {execution: default-jar}] to create a default jar file.

So I will have 2 jar files (one created by Assembly plugin and one created by Maven jar which i don't want to be created).

How can I turn off the default-jar execution?

In my pom.xml, I am using: <packaging>jar</packaging>.

I don't want to change it to <packaging>pom</packaging>.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

(...) So i will have 2 jar files (one created by assembly plugin and one created by maven jar which i dont want to be created).

Looks like you're doing pretty complicated things. Maybe Maven is not the right tool in your case.

How can I turn off the execution: default-jar.

You can set the <phase> of the corresponding execution to something unknown, like none:

  <plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>default-jar</id>
        <phase>none</phase>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <configuration>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <!-- this is used for inheritance merges -->
        <phase>package</phase>
        <!-- append to the packaging phase. -->
        <goals>
          <goal>single</goal>
          <!-- goals == mojos -->
        </goals>
      </execution>
    </executions>
  </plugin>

This seems to work as long as you're providing something else to be installed, like an assembly (I only tested install). But of course, this is a hack.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...