maven構(gòu)建jar包的步驟:
1.執(zhí)行可執(zhí)行的class兽泄,代碼內(nèi)需要有入口main方法
2.通過mvn package來構(gòu)建jar包
3.使用java -jar test.jar來執(zhí)行jar包
一熊户、包含依賴jar包
maven的pom.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.delon</groupId>
<artifactId>bugly</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- 工程所需jar包引用開始 -->
<!-- 單元測試 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- 代碼所需依賴 -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.3.0</version>
</dependency>
<!-- 代碼所需依賴 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.2</version>
</dependency>
<!-- 工程所需jar包引用開始 -->
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此處指定main方法入口的class -->
<mainClass>com.xxx.uploadFile</mainClass>
</manifest>
</archive>
ta </configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
生成jar包崭放,會(huì)生成在target目錄下
執(zhí)行打包
mvn package
執(zhí)行:
# 運(yùn)行jar
java -jar test.jar