Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between mvn assembly:single and mvn compile assembly:single

Tags:

java

maven

When I am calling mvn assembly:single, it creates a jar, but the jar does not runs and the error says Error: Could not find or load main class.. But, when I am running mvn compile assembly:single, the jar created this time, runs as expected. So my doubt is, why mvn assembly:single created jar not running and giving that error, while the later command created jar is running just fine.

Minimalistic pom

 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.3.0</version>
  <configuration>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
        <mainClass>com.org.taptest.tests.TestTAP</mainClass>
      </manifest>
     </archive>
     <descriptorRefs>
       <descriptorRef>jar-with-dependencies</descriptorRef>
     </descriptorRefs>
   </configuration>
</plugin>
like image 721
Uddhami Avatar asked Dec 06 '25 20:12

Uddhami


1 Answers

The difference is that assembly:single is a plugin goal while compile is a lifecycle phase.

Maven lifecycles are abstract build phases. When you invoke compile Maven will execute all phases until compile (included). In each phase it will execute the plugins that are registered to that phase.

Plugin goals are specific tasks that you can plug in a phase. The task of the assembly plugin for example is to package a distributable archive. That is what you define when you add a plugin <execution> to a pom.

Predefined lifecycles are selected through the <packaging>. E.g. the jar packaging.

Thus when you invoke assembly:single you tell maven to package a distribution archive. If there is nothing build that can be packaged the archive might be empty.

If you tell maven compile assembly:single is executes all phases until compile. Thus the sources are compiled to bytecode. And then it packages the compiled classes.

like image 103
René Link Avatar answered Dec 08 '25 09:12

René Link



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!