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包的错误了

相关推荐
程序员张31 小时前
Maven编译和打包插件
java·spring boot·maven
Johny_Zhao3 小时前
Docker + CentOS 部署 Zookeeper 集群 + Kubernetes Operator 自动化运维方案
linux·网络安全·docker·信息安全·zookeeper·kubernetes·云计算·系统运维
灵犀学长3 小时前
EasyExcel之SheetWriteHandler:解锁Excel写入的高阶玩法
spring boot·excel
小毛驴8503 小时前
Linux 后台启动java jar 程序 nohup java -jar
java·linux·jar
zwjapple3 小时前
docker-compose一键部署全栈项目。springboot后端,react前端
前端·spring boot·docker
好好学习啊天天向上4 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
tan180°5 小时前
MySQL表的操作(3)
linux·数据库·c++·vscode·后端·mysql
典学长编程6 小时前
Linux操作系统从入门到精通!第二天(命令行)
linux·运维·chrome
wuk9986 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
DuelCode6 小时前
Windows VMWare Centos Docker部署Springboot 应用实现文件上传返回文件http链接
java·spring boot·mysql·nginx·docker·centos·mybatis