springboot项目中引入本地依赖jar包,并打包到lib文件夹中

1.springboot项目中引入本地依赖jar包,并打包到lib文件夹中

描述:下载了第三方相关jar包后,项目中引入本地jar,测试环境正常,打包线上报错提示为找到该jar
原因:应该在/WEB-INF/lib/xxx.jar,被打包到此目录:/WEB-INF/classes/lib/xxx.jar

2.引入本地依赖jar包

在这里插入图片描述
引入jar包后,在此pom.xml文件中里面添加依赖坐标,即添加中内容

<dependencies>
        <dependency>
            <groupId>org.eclipse.paho.client.mqttv3_1.0.2_dms</groupId>
            <artifactId>org.eclipse.paho.client.mqttv3_1.0.2_dms.jar</artifactId>
            <version>1</version>
            <scope>system</scope>
            <systemPath>${pom.basedir}/src/main/resources/lib/org.eclipse.paho.client.mqttv3_1.0.2_dms.jar</systemPath>
        </dependency>
    </dependencies>

3.打包到lib包

在pom的< build></ build>标签中还需进行如下修改,添加备注 打war包 之后带内容

<build>
        <!--    war的名称    -->
        <finalName>mall-portal</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <!-- 打war包 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <!-- 配置将第三方jar打进war包中,跟<packaging>war</packaging>配合 -->
                        <webResource>
                            <directory>${pom.basedir}/src/main/resources/lib/</directory>
                            <targetPath>WEB-INF/lib/</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </webResource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将外部Jar包引入Spring Boot项目打包Jar包,可以按照以下步骤进行操作: 1. 在pom.xml文件添加依赖项。例如,要引入一个名为example.jar的外部Jar包,可以通过以下方式添加依赖项: ``` <dependency> <groupId>com.example</groupId> <artifactId>example</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/lib/example.jar</systemPath> </dependency> ``` 其,systemPath指定了外部Jar包的路径,scope设置为system,表示使用系统路径下的Jar包。 2. 将外部Jar包复制到项目lib目录下,例如,将example.jar复制到项目目录下的lib文件夹。 3. 在pom.xml文件添加Maven插件,以将外部Jar包打包到生成的Jar包。例如,可以添加以下插件: ``` <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> <mainClass>com.example.Application</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> ``` 其,classpathPrefix指定了Jar包lib文件夹下的依赖项路径前缀,mainClass指定了Spring Boot应用程序的主类。 4. 使用Maven命令进行打包,生成的Jar包含外部Jar包。例如,使用以下命令进行打包: ``` mvn clean package ``` 这样,生成的Jar包含了外部Jar包,并可以在运行时使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值