在我们开发项目时,需要测试一些功能,而需要把我们开发的功能打成jar包,放到服务器上运行,因此我们需要创建一个Maven项目,并且在本地编译项目成jar包程序,指定程序的入口类,然后运行程序。下面是如何快速构建Maven项目的流程。
初始项目目录结构:
package com.longshilin.maven; public class MavenTest { public static void main(String[] args) { System.out.println("This is a new Maven Project!"); } }
配置项目入口类
源码
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.longshilin.maven.MavenTest</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
LongShiLin@LongShiLin-PC MINGW64 ~/.m2/repository/com/longshilin/maven/maven-test/0.0.1-SNAPSHOT
$ java -jar maven-test-0.0.1-SNAPSHOT.jar
This is a new Maven Project!