1、开发的时候,可以使用maven 来引用其他的包,是最好的选择,但是很多时候,在对接其他的第三方接口的时候, 不能不适用第三方的jar,这个时候,很多人是选择,直接SystemPath的方式使用,如:
<dependency>
<groupId>com.sf</groupId>
<artifactId>sf-novatar-log</artifactId>
<version>1.09</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sf-novatar-log-1.09.jar</systemPath>
</dependency>
这样的方式,导入一个项目下面的一个jar,这个是可行的,至少是在开发工具上,是没用任何问题的
但是,在打包运行的是,就会出现,java.lang.ClassNotFoundException, 如图所示:
这代表是,class编译的成功,但是运行时候,却找不到包。问题出在,打包的是,maven系统默认是不把《systemPath》的东西打包的,有点类似于: <scope>provided</scope>;
要是使用,只需要添加以下的就可以了:但是,这个好像会导致本地启动找不到application.yml
<build>
<resources>
<resource>
<directory>${project.basedir}/lib</directory>
<targetPath>BOOT-INF/lib/</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
</resources>
</build>
方法二:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>