springboot项目引用外部jar包,linux部署后启动失败,找不到jar包

1.pom文件引入依赖

bash 复制代码
        <!-- https://mvnrepository.com/artifact/com.aspose/aspose-words -->
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>18.6.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aspose-words-18.6.0.jar</systemPath>
            <type>jar</type>
            <optional>true</optional>
        </dependency>

2.系统lib包下放入外部jar包

3.pom文件修改打包代码,指定读取jar包

bash 复制代码
<!-- 打包时候用 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.SpringbootInit</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib</classpathPrefix>
                        </manifest>
                        <manifestEntries>
                            <!--读取外部配置文件,放到classpath里 -->
                            <Class-Path>resources/. lib/aspose-words-18.6.0.jar</Class-Path>
                        </manifestEntries>
                    </archive>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <excludes>
                        <exclude>**/*.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>

在打包的时候指定读取外部的jar包,这样部署到linux后,启动就不会报找不到jar包的错误了

相关推荐
小小的木头人4 分钟前
Ubuntu 26.04 换阿里云镜像源
linux·ubuntu·阿里云
qq_254674419 分钟前
Ubuntu 20.04取消自动休眠的三种实现方案
linux·chrome·ubuntu
念恒1230638 分钟前
STM32---新建工程
linux·stm32·嵌入式硬件
悲伤小伞1 小时前
Linux_传输层协议TCP详解
linux·网络·c++·网络协议·tcp/ip
笨笨饿1 小时前
#72_聊聊I2C以及他们的变体
linux·c语言·网络·stm32·单片机·算法·个人开发
布局呆星1 小时前
Spring Boot+MyBatis-Plus+Vue3前后端协作Note
spring boot·typescript·vue·mybatis
ulias2121 小时前
leetcode热题 - 6
linux·算法·leetcode
路在脚下@1 小时前
@PostConstruct、@PreDestroy 和 @DependsOn注解的使用和区别
spring boot
fpcc2 小时前
跟我学C++中级篇—Linux文件读写的分析
linux·c++
techdashen2 小时前
4 个字节拿到 root 权限:Linux 内核漏洞“Copy Fail“与 Cloudflare 的应急处置全记录
linux·网络·安全