Reputation: 57
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>
Upvotes: 3
Views: 1743
Reputation: 51403
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.
Upvotes: 3