有勇气的牛排博客

通过idea打包java Maven项目 架包与全包

有勇气的牛排 470 Java 2022-12-22 15:06:09

哈喽,大家好,我是有勇气的牛排(全网同名)🐮🐮🐮

有问题的小伙伴欢迎在文末评论,点赞、收藏是对我最大的支持!!!。

文章目录

1 仅架包

架包定义:指仅将代码打包到jar中,在运行的平台必须保证依赖。
方法:maven —> Lifecyle —> Clean —> Package

image.png

2 架包与全包(推荐)

全包定义:将maven项目中的依赖于代码都打为一个包。
方法:maven —> Plugins —> assembly —>assembly:assembly

项目配置

pom.xml

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>groupId</groupId> <artifactId>azkaban_cs</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <!-- 引入打包插件 --> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <!-- <dependencies>--> <!-- &lt;!&ndash;Lombok &ndash;&gt;--> <!-- <dependency>--> <!-- <groupId>org.projectlombok</groupId>--> <!-- <artifactId>lombok</artifactId>--> <!-- </dependency>--> <!-- </dependencies>--> </project>

新建主目录文件:assembly.xml

<assembly xmlns:xsi="" xmlns="" xsi:schemaLocation=" "> <id>${project.version}</id> <formats> <format>dir</format> <format>tar.gz</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <baseDirectory>${build.directory}</baseDirectory> <fileSets> <fileSet> <directory>conf/</directory> <outputDirectory>${project.artifactId}/conf</outputDirectory> </fileSet> <fileSet> <directory>db/</directory> <outputDirectory>${project.artifactId}/db</outputDirectory> </fileSet> <fileSet> <directory>${build.directory}</directory> <includes> <include>*.jar</include> </includes> <excludes> <exclude>*sources.jar</exclude> </excludes> <outputDirectory>${project.artifactId}/lib</outputDirectory> </fileSet> <fileSet> <directory>bin/</directory> <outputDirectory>${project.artifactId}/bin</outputDirectory> <fileMode>754</fileMode> <lineEnding>unix</lineEnding> </fileSet> </fileSets> </assembly>

开始打包

image.png


留言

专栏
文章
加入群聊