就沒有簡短的途徑,一定要把 jar 引用到的所有第三方函式庫,一併全打包進 jar 裡
在 Maven 中可以透過設定幾個 build 參數來達成。
首先先在 pom.xml 裡寫上需要的參數如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
< project > < build > < plugins > <!-- any other plugins --> < plugin > < artifactId >maven-assembly-plugin</ artifactId > < executions > < execution > < phase >package</ phase > < goals > < goal >single</ goal > </ goals > </ execution > </ executions > < configuration > < descriptorRefs > < descriptorRef >jar-with-dependencies</ descriptorRef > </ descriptorRefs > < archive > < manifest > <!-- Indicate where is project main() function / the code entry. --> < mainClass >org.example.App</ mainClass > </ manifest > </ archive > </ configuration > </ plugin > </ plugins > </ build > </ project > |
最後再使用 Maven 的 console 執行以下的指令,就可以打包完成了。
1 |
mvn package |
沒有留言:
張貼留言