当前位置:网站首页>Multiple ways for idea to package jars
Multiple ways for idea to package jars
2022-06-22 08:01:00 【xiaoke815】
Here is a summary of IDEA pack jar There are many ways to pack , Future projects are packaged Jar Packages can refer to the following forms :
- use IDEA It's packed in its own form
- use Maven plug-in unit maven-shade-plugin pack
- use Maven plug-in unit maven-assembly-plugin pack
use IDEA It's packed in its own way :
open IDEA Of file -> Project Structure, Enter the project configuration page . Here's the picture :
Click on Artifacts, Get into Artifacts Configuration page , Click on + , Select the option shown in the figure below .
Get into Create JAR from Modules page , Configure as shown in the figure below .
- Step 1 selection Main Function execution class .
- Step 2 select the options shown in the figure , The purpose is for third parties Jar Do additional configuration when packaging packages , Do not select this option if no additional configuration is required ( But there is no guarantee that the package will succeed )
- The third step needs to be in src/main Under the table of contents , Create a new one resources Catalog , take MANIFEST.MF The files are kept here , Because if you use the default value , stay IDEA12 There will be bug.
Click on OK after , The following interface appears , Right click on the <output root>, Click on Create Directory, Create a libs, Will all third parties JAR In the libs Under the table of contents .
After success , As shown in the figure below :
After putting it in , Click on what we want to type jar Name , Inside is kafka-cps.jar, choice classpath To configure .
The result of editing is as follows :
Here will be all jar All written in libs/ Inside . Click on OK, Back to the configuration page .
Also note that on the configuration page , Check build on make
Finally, click... On the configuration page OK, Complete the configuration . go back to IDEA, Click on Build->Build Artifacts, choice build
Will generate what we need jar package . Its location is in the project directory out Under the table of contents /out/artifacts/kafka_cps_jar.
Now put the contents of a properly configured manifest file
use maven-shade-plugin pack
The above packaging process is too cumbersome , And it doesn't take advantage of maven Features of the management project . So , We use maven Medium maven-shade-plugin plug-in unit . stay pom.xml in , We add the following information to add the plug-in .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Main.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
This is equipped with a `configuration` Label content , Under this label There is one transformer label , Used to configure Main Function entry ( <mainClass>Main.Main</mainClass>), Of course, the content of this tag is very complicated , It's not as simple as it says , The reason why the above is so simple , Because in all classes ( Including third parties Jar) only one Main Method . If a third party jar There is Main Method , Additional configuration is required , The above configuration , It may not be successful .
For details, please refer to maven plug-in unit .
Add this code to pom.xml after , We can use it maven The order to pack . The instructions are as follows :
mvn clean compile // Before clearing target Compile the file and recompile
mvn clean package// Package the project ( Because the plug-in has been configured , therefore jar Packages are executable )
mvn clean install // Installation project , Then you can use it
And then through java -jar cps-1.0-SNAPSHOT.jar function .
If you use IDEA Words , You can do it by bringing it with you maven Instead of executing the above command, the management tool . As shown in the figure below , Click on the blue part in turn .
use maven-assembly-plugin pack
The above method , We also need to click many commands to package . This time with a new plug-in , It can be packaged more easily . Again , stay pom.xml Add the following code to . The above maven-shade-plugin Plug in code can be deleted . Better not write 2 Plug in codes .
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Main.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
There is also a manifest Tag to configure Main Function entry . Then the following instructions are used to implement the packaging .
mvn assembly:assembly
If you use IDEA Words , You can do it by bringing it with you maven Instead of executing the above command, the management tool . As shown in the figure below , Click on the blue part .
And then by executing java -jar cps-1.0-SNAPSHOT-jar-with-dependencies.jar function .
边栏推荐
- 【圖論常見模板題】4種最短路解法和2種最小生成樹解法
- Layer drawing method
- UI draw line
- Problems caused by canvas palette width and height and canvas width and height
- Win openfeign from simple to deep
- mapTalks:基础操作与WMS/WMTS地图服务加载
- MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly
- 【Oracle 数据库】奶妈式教程day15 DDL、DML、索引、视图、序列、死锁这一篇就够了
- [common template problems in graph theory] four shortest path solutions and two minimum spanning tree solutions
- IP address planning
猜你喜欢
![[songhongkang MySQL database] [advanced chapter] [06] logical architecture of MySQL](/img/57/22d8a6dafffe685f69660fde9e8c87.png)
[songhongkang MySQL database] [advanced chapter] [06] logical architecture of MySQL

(7) Bidirectional linked list

【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构

【 Oracle database】 Nursery Mother Tutorial day13 date Function

Model electricity experiment -- Experiment 2 JFET common source amplifier circuit

QT QtableView的使用示例

模电实验——实验一 晶体管共射极单管放大器

mysql查询group by 1055 问题完美解决,最简单最便捷的方法

Invalid applet margin right, text overflow?

IP address planning
随机推荐
Some suggestions on Oracle SQL query return optimization
计算水费问题
(7) Bidirectional linked list
Windchill - how to start workflow through API
什么是分布式事务
Ugui text spacing textspacing
【Oracle 数据库】奶妈式教程 day11 数值函数
Introduction to several mainstream and easy-to-use rich text editors (WYSIWYG common editors)
(9) Sequential queue and stack queue
【 Oracle database】 Nursery Mother Tutorial day13 date Function
Thoughts on the construction of data analysis platform for small and medium-sized enterprises (I)
Excellent cases of data visualization
Kubernetes practice
LR 2022 ultra detailed installation tutorial "latest"
模电实验——实验二 JFET共源极放大电路
The applet uses the step bar vant steps in vant
Energy and interference of waves
充电宝的玄机
Wechat applets will directly open the parent element when the child element of flex:1 is too long (the text is too long)
Scrollrect for tableview