小编典典

将外部库.jar添加到Spring boot .jar内部/ lib

spring-boot

我有一个外部.jar,它无法使用pom.xml从公共存储库导入sqljdbc41.jar

我可以从IDE在本地运行该项目,并且一切正常。我像这样下载后引用了该库:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>sqljdbc41</artifactId>
    <version>4.1</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/sqljdbc41.jar</systemPath>
</dependency>

当我运行mvn clean package以创建我的.jar文件并尝试运行创建的.jar时,将弹出一个错误,提示SQL
Server引用无效。然后,我提取了我的.jar文件,并且足够真实,pom.xml文件中正确引用的所有内容均已下载并添加,但是我的SQL
Server没有。

我可以以一种非常怪异的方式*将sqljdbc41.jar它编译为.jar后,手动将其添加到我的/
lib文件夹中,并且它可以正常工作,但是这似乎不是最佳选择。有什么更好的方法?


*使用Winrar打开.jar文件,转到/ lib文件夹,手动选择我的sqljdbc41.jar文件,然后确保选择“无压缩”选项,在左下角Winrar为您提供压缩选项,以防您被Google找到而没有人回答。


阅读 410

收藏
2020-05-30

共1个答案

小编典典

您可以将“ includeSystemScope”设置为true。

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <includeSystemScope>true</includeSystemScope>
  </configuration>
</plugin>
2020-05-30