Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate executable jar packages using maven

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to use maven to generate executable jar packages, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

From the xsi of pom, you can open the schema that describes pom:

You can see the structure of project in pom:

The default jar generated by mvn install does not have a main class entry, so you need to set the main class in 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 1.8 com.cetc.di.hellocetc.App true lib/

Perform mvn install:

In the target directory, you find that the jar package has been generated:

With java decompiler, you can see that MainClass has been added to manifest:

Using mvn help:effective-pom, you can see the complete structure of pom.xml (including inherited properties):

[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: 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 1.8 com.cetc.di.hellocetc.App true lib/ maven-clean-plugin 2.5 default- 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 1. 8 com.cetc.di.hellocetc.App true lib/ 1.8 1.8 Com.cetc.di.hellocetc.App true lib/ maven-compiler-plugin 3.1 default-compile Default-testCompile test-compile testCompile maven-surefire-plugin 2.12.4 default-test Maven-install-plugin 2.4 default-install maven-deploy-plugin 2.7 default-deploy deploy Deploy maven-site-plugin 3.3default-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 read the above Have you mastered how to generate executable jar packages using maven? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report