1:第一种方法:在应用程序中的pom文件中指定jar文件的目录即可,在pom中的dependency中如下设置:
<dependency>
<groupId>com.xu</groupId>
<artifactId>demo</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/user/demo.jar</systemPath>
</dependency>
1、其中的scope被设置成system,默认是compile,指出dependency不是去repository中查找,而是在系统目录中查找。systemPath指定了jar文件的绝对路径。也可以使用相对路径
2、因为Spring Boot在打jar包的时候会调用【spring-boot-maven-plugin】插件并执行【repackage】指令把tomcat、resoucre和lib等合并成一个新的jar,如果想要将本地jar包(系统jar)打进最终生成的jar中,必须要配置【includeSystemScope】属性,这样才能将lib中的内容放到BOOT-INFlib目录中,不然在默认不显式配置的情况下scope为system的本地jar不会被打包进最终jar中。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
## 2:第二种方法 将本地的jar文件安装到本地repository中,具体步骤如下: 1、准备好本地的jar文件 2、使用如下命令安装jar文件
mvn install:install-file -Dfile=demo.jar
-DgroupId=com.xu -DartifactId=demo
-Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
其中,-Dfile制定jar文件的位置
3、安装完之后,在另一个应用程序中使用它的时候,只要在pom文件中指定相应的dependency就可以,如:
<dependency>
<groupId>com.xu</groupId>
<artifactId>demo</artifactId>
<version>1.0</version>
</dependency>
注意:推荐使用第二种打包方式