In a project, there are usually more than one main program. When packaging jar files, you must specify the main program. For Maven, configure the main program as follows:
In pox. xml
<Build> <plugins> <plugin> <groupid> Org. apache. maven. plugins </groupid> <artifactid> Maven-shade-plugin </artifactid> <executions> <execution> <phase> package </phase> <goals> <goal> shade </ goal> </goals> <configuration> <transformers> <transformer implementation = "org. apache. maven. plugins. shade. resource. manifestresourcetransformer "> <mainclass> CN. vicky. skstatistics. money. APP: This is the main program class </mainclass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> <finalname> skmoneystatistics </finalname> </build>
You can double-click to run the jar program.
If a jar contains multiple main programs, but you do not configure the default main program, or you want to run the specified main program, run the following command:
Java-CP example03-1.0-SNAPSHOT.jar CN. Vicky. example03.helloagent
-CP <directory and Class search path for zip/jar files>
Example03-1.0-SNAPSHOT.jar jar package
Main Program class specified by CN. Vicky. example03.helloagent