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

💖💖💖💖💖💖养成每日阅读好习惯, 每天进步, 超越昨天的自己💖💖💖💖💖💖
作者:有勇气的牛排🐮🐮🐮
愿景:输出体系化编程知识与技巧,助力软件行业发展与从业者学习减负,让编程产生更大价值。

🔎🔎🔎
Linux专栏文章: 👉👉👉Java文章专栏大全 | 有勇气的牛排👈👈👈

哈喽,大家好,我是有勇气的牛排🐮。
很多小伙伴在学习Java的过程中,可能对Java Maven打包项目方法有点小迷惑,毕竟Java知识体系庞大,全背下来肯定是有点难度的,今天牛排在学习大数据的时候总结出了使用流程,再也不用背代码了,特此分享给大家。

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

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

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有勇气的牛排

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值