SpringBoot部署Jar

如下图,工程里面引用了自定义的两个jar,目的:

1. 打jar

2.配置文件与jar和lib全部分离,方便下次更新jar以及随意更改配置文件

3. pom.xml中的 <build>标签

 <build>
        <finalName>最终jar的名称</finalName>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <!--不打包资源文件-->
                    <excludes>
                        <exclude>*.yml</exclude>
                    </excludes>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!--MANIFEST.MF 中 Class-Path 加入前缀-->
                            <classpathPrefix>lib/</classpathPrefix>
                            <!--jar包不包含唯一版本标识-->
                            <useUniqueVersions>false</useUniqueVersions>
                            <!--指定入口类,修改成自己项目的入口类 -->
                            <mainClass>com.wenge.ShortVideoApplication</mainClass>
                        </manifest>
                        <manifestEntries>
                            <!--MANIFEST.MF 中 Class-Path 加入资源文件目录-->
                            <Class-Path>./resources/</Class-Path>
                        </manifestEntries>
                    </archive>
                    <outputDirectory>${project.build.directory}/out</outputDirectory>
                </configuration>
            </plugin>
            <!--拷贝第三方依赖文件到指定目录-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/out/lib/
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!--拷贝资源文件 copy-resources-->
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <include>*.yml</include>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.directory}/out/resources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
        </plugins>
基于上面的,可以修改下面位置,逐一引入第三方jar
<manifestEntries>
    <Class-Path>./resources/ ./jars/KwsExpConvert-1.1.jar/ ./jars/ZHConverter.jar</Class-Path>
</manifestEntries>

或者 (参考maven引入外部jar包的几种方式_像你这样的的博客-CSDN博客_maven打包引入外部jar包)

将本地jar安装到本地maven

mvn install:install-file -Dfile=D:\GX_workspace\short-video\jars\KwsExpConvert-1.1.jar -DgroupId=com.wenge -DartifactId=expression -Dversion=0.1 -Dpackaging=jar

mvn install:install-file -Dfile=D:\GX_workspace\short-video\jars\ZHConverter.jar -DgroupId=com.wenge -DartifactId=ZHConverter -Dversion=0.1 -Dpackaging=jar

然后,按照平时的引用,在pom.xml中添加

<dependency>
    <groupId>com.wenge</groupId>
    <artifactId>expression</artifactId>
    <version>0.1</version>
</dependency>
<dependency>
    <groupId>com.wenge</groupId>
    <artifactId>ZHConverter</artifactId>
    <version>0.1</version>
</dependency>

这样打包就没问题了。

如果仅是自己使用,引用第三方jar

pom.xml中配置如下:

    <dependency>
            <groupId>com.wenge</groupId>
            <artifactId>expression</artifactId>
            <scope>system</scope>
            <version>0.1</version>
            <systemPath>${pom.basedir}/jars/KwsExpConvert-1.1.jar</systemPath>
        </dependency>
       <dependency>
            <groupId>com.wenge</groupId>
            <artifactId>ZHConverter</artifactId>
            <scope>system</scope>
            <version>0.1</version>
            <systemPath>${pom.basedir}/jars/ZHConverter.jar</systemPath>
        </dependency>

 基于上面的,如果不分离打包的话,直接在<build>中添加如下:

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>

此文章仅限于自己总结使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值