1. 程式人生 > >使用maven-assembly-plugin外掛打包

使用maven-assembly-plugin外掛打包

在pom.xml中配置

<build>
	<pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>2.5.5</version>
				<configuration>
					<archive>
						<manifest>
							<!-- 這裡是啟動類全路徑名 -->
							<mainClass>com.xxxx.Iphoenix.App</mainClass>
						</manifest>
					</archive>
					<descriptorRefs>
						<descriptorRef>jar-with-dependencies</descriptorRef>
					</descriptorRefs>
				</configuration>
			</plugin>
		</plugins>
	</pluginManagement>
</build>

打包方式

mvn package assembly:single 

打包後會在target目錄下生成一個xxx-jar-with-dependencies.jar檔案,這個檔案不但包含了自己專案中的程式碼和資源,還包含了所有依賴包的內容。使用java -jar xxx-jar-with-dependencies.jar執行jar包。希望對你有用!