今天就跟大家聊聊有關使用maven怎么生成一個可執(zhí)行的jar包,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
站在用戶的角度思考問題,與客戶深入溝通,找到綿陽網站設計與綿陽網站推廣的解決方案,憑借多年的經驗,讓設計與互聯(lián)網技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網站、成都網站設計、企業(yè)官網、英文網站、手機端網站、網站推廣、主機域名、網站空間、企業(yè)郵箱。業(yè)務覆蓋綿陽地區(qū)。
從pom的xsi中可以打開描述pom的schema:
可以看到pom中,project的結構:
默認的mvn install生成的jar是不帶主類入口的,需要在maven-compile-plugin中設置主類,
4.0.0 com.cetc.di hellocetc 0.0.1-SNAPSHOT jar hellocetc http://maven.apache.org UTF-8 junit junit 3.8.1 test org.apache.maven.plugins maven-jar-plugin 1.8 com.cetc.di.hellocetc.App true lib/
執(zhí)行mvn install:
在target目錄中,發(fā)現(xiàn)jar包已經生成:
用java decompiler,可以看到manifest中已經加入了MainClass:
使用mvn help:effective-pom可以看到pom.xml的完整結構(包括繼承而來的屬性):
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building hellocetc 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-help-plugin:2.2:effective-pom (default-cli) @ hellocetc --- [INFO] Effective POMs, after inheritance, interpolation, and profiles are applied:[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.526 s [INFO] Finished at: 2021-03-18T20:05:12+08:00 [INFO] Final Memory: 10M/245M [INFO] ------------------------------------------------------------------------ 4.0.0 com.cetc.di hellocetc 0.0.1-SNAPSHOT hellocetc http://maven.apache.org UTF-8 junit junit 3.8.1 test false central Central Repository https://repo.maven.apache.org/maven2 never false central Central Repository https://repo.maven.apache.org/maven2 D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\java D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\scripts D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\java D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\classes D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\test-classes D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\main\resources D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\src\test\resources D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target hellocetc-0.0.1-SNAPSHOT maven-antrun-plugin 1.3 maven-assembly-plugin 2.2-beta-5 maven-dependency-plugin 2.8 maven-release-plugin 2.3.2 maven-jar-plugin 2.4 1.8 com.cetc.di.hellocetc.App true lib/ maven-clean-plugin 2.5 default-clean clean clean maven-resources-plugin 2.6 default-testResources process-test-resources testResources default-resources process-resources resources maven-jar-plugin 2.4 default-jar package jar 1.8 com.cetc.di.hellocetc.App true lib/ 1.8 com.cetc.di.hellocetc.App true lib/ maven-compiler-plugin 3.1 default-compile compile compile default-testCompile test-compile testCompile maven-surefire-plugin 2.12.4 default-test test test maven-install-plugin 2.4 default-install install install maven-deploy-plugin 2.7 default-deploy deploy deploy maven-site-plugin 3.3 default-site site site D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site org.apache.maven.plugins maven-project-info-reports-plugin default-deploy site-deploy deploy D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site org.apache.maven.plugins maven-project-info-reports-plugin D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site org.apache.maven.plugins maven-project-info-reports-plugin D:\Users\a\Workspaces\MyEclipse 2015\hellocetc\target\site
看完上述內容,你們對使用maven怎么生成一個可執(zhí)行的jar包有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。