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

相关推荐
悟空码字2 小时前
Spring Boot 整合 MongoDB 最佳实践:CRUD、分页、事务、索引全覆盖
java·spring boot·后端
Yogurt_cry4 小时前
[树莓派4B] 闲置近10年的爱普生 L310 打印机爆改无线打印机
linux·物联网·树莓派
Johny_Zhao1 天前
OpenClaw中级到高级教程
linux·人工智能·信息安全·kubernetes·云计算·yum源·系统运维·openclaw
皮皮林5512 天前
拒绝写重复代码,试试这套开源的 SpringBoot 组件,效率翻倍~
java·spring boot
Sheffield2 天前
Docker的跨主机服务与其对应的优缺点
linux·网络协议·docker
Sheffield2 天前
Alpine是什么,为什么是Docker首选?
linux·docker·容器
Johny_Zhao3 天前
centos7安装部署openclaw
linux·人工智能·信息安全·云计算·yum源·系统运维·openclaw
haibindev3 天前
在 Windows+WSL2 上部署 OpenClaw AI员工的实践与踩坑
linux·wsl2·openclaw
0xDevNull4 天前
Linux切换JDK版本详细教程
linux