One, Java Run command
There are three ways to start a Java program:
1, Java-jar
In the generated jar package, the manifest file defines the main Class, which you can use to
Java-jar Test.jar
2, JAVA-CP
There is no main class configuration in the generated jar package, which can be used
JAVA-CP Test.jar Cn.matt.Test
The command can also start the Java program from the class file, which must be explicitly listed for the dependent jar package, separated by a semicolon (Windows) or colon (Linux)
JAVA-CP./target/classes;test2.jar cn.matt.Test
3, Java-djava.ext.dirs
When the jar does not contain a dependent package, it is not convenient to use JAVA-CP, which allows you to specify the dependent package directory only
Java-djava.ext.dirs=. Cn.matt.maven_test. App
Second, Java Packaging settings
With Maven packaging, the generated jar package does not run directly (without the main Class) and does not contain a dependent jar package, by default
Specify the main Class and include the dependent jar package configuration:
<build> <plugins> <plugin> <artifactid>maven-assembly-plugin</artifacti D> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainclass>cn.matt.maven_test3. app</mainclass> </manifest> </archive> </configuratio n> <executions> <execution> <id>make-assembly</id& Gt <phase>package</phase> <goals> <goal>assembly</goal > </goals> </execution> </executions> </plugin> </plugins> </build>
Reference:
MAVEN package contains the Main method jar and runs
The Java command line runs the main class in the Jar
Java packaging settings and running commands