功能:
idea開發maven項目進行打包並支持 jar可執行主程序
主要配置項爲pom的打包配置項
詳情如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 配置主程序-->
<archive>
<manifest>
<mainClass>${exec.mainClass}</mainClass>
</manifest>
</archive>
<!-- 生成對應後綴的jar包 爲加入依賴的jar-->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
- 配置後進行 執行 mvn clean compile package會自動下載相應的包並打包
- 執行後會得到兩個jar包 帶有jar-with-dependencie後綴的爲包含依賴的jar包
- 執行 java -jar xxxx-jar-with-dependencie.jar 執行爲主程序
如果不加相關的主程序配置,打包後執行主程序需要進行加上 主程序的classpath
- 執行 java -jar xxxx-jar-with-dependencie.jar xxx.xxx.xxx.MainTest 執行相關的主程序
遇到以下問題可使用上述方法解決
- Maven 項目生成jar運行時提示“沒有主清單屬性”