Wrote a small tool in Java, using MAVEN Java engineering. When you are finished, you want to package into an executable jar package.
Use Maven's plugin maven-assembly-plugin
Add in Pom.xml
<build>
<plugins>
<plugin>
<artifactid>maven-assembly-plugin</ artifactid>
<configuration>
<archive>
<manifest>
<mainClass> org.kuan.wang.app</mainclass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</ configuration>
</plugin>
</plugins>
</build>
To execute a command:
MVN Clean Compile Assembly:single
Generate Maventestapp-1.0-snapshot-jar-with-dependencies.jar in target folder
This jar pack is the executable jar, and can be executed with the command Java-jar Path\jarfile.
Note: Compile must be assembly:single before your project code (class file) will not be packaged .
Assembly:single is the goal of Maven.
Typically, this goal is bound to the phase of the MAVEN build so that it can be executed automatically. MVN package is used to package jar packages. Just the jar package is not executable.
In the above Pom file Riga <executions>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.kuan.wang.App</mainClass>
</ manifest>
</archive>
<descriptorRefs>
<descriptorref>jar-with-dependencies </descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!--this are used for inheritance merges-->
< Phase>package</phase> <!--bind to the packaging phase-->
<goals>
<goal>single </goal>
</goals>
</execution>
</executions>
</plugin>
In this case, run the following command directly.
MVN Clean Package
There are also a few points to note.
1. It is necessary to have
<archive>
<manifest>
<mainClass>org.kuan.wang.App</mainClass>
</ Manifest>
</archive>
Or you'll get an error.
No main manifest attribute, in Target\maventestapp-1.0-snapshot-jar-with-dependencies.jar
<mainClass> is the entrance to your own project.
2. Using mvn clean compile assembly:single, only one jar package is generated, with jar-with-dependencies in name, which can be executed.
Using MVN package to generate two jar packages, the Jar-with-dependencies jar in the name is executable.
3. If you use <goal>assembly</goal>
MVN assembly:assembly with a command generates two jar packages. Same as using the MVN package.
There is no need to add compile to the front like command assembly:single.