maven引入项目内本地包方法

发布于:2025-04-04 ⋅ 阅读:(27) ⋅ 点赞:(0)

最近在写java实现excel转pdf功能;
网上有个包很好用,免费:spire.xls.free-5.3.0.jar

但是maven打包项目时报错,找不到这个包。

jar包位置如下:
在这里插入图片描述

项目/src/jar/spire.xls.free-5.3.0.jar

解决方法:

pom.xml里增加配置。


		<dependency>
			<groupId>com.example</groupId>
			<artifactId>my-library</artifactId>
			<version>1.0.0</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/jar/spire.xls.free-5.3.0.jar</systemPath>
		</dependency>

发现这样配置后,本地可以启动了,打包也没有报错;

但是项目运行时发现,还是不行,执行包里的方法就会报错,没有把这个jar包打进去。

完整配置应该是这样:


		<dependency>
			<groupId>com.example</groupId>
			<artifactId>my-library</artifactId>
			<version>1.0.0</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/jar/spire.xls.free-5.3.0.jar</systemPath>
		</dependency>
    </dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<includeSystemScope>true</includeSystemScope>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

需要配置pluginconfiguration,设置打包时把scope-system的jar包也打进去才行。

经过测试,这样就没问题了。


网站公告

今日签到

点亮在社区的每一天
去签到