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

1.pom文件引入依赖

        <!-- 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包

<!-- 打包时候用 -->
            <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包的错误了

你可能感兴趣的:(spring,boot,jar,linux)