将外部库 .jar 添加到 Spring boot .jar internal/lib [英] Add external library .jar to Spring boot .jar internal /lib

查看:27
本文介绍了将外部库 .jar 添加到 Spring boot .jar internal/lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an external .jar that cannot be imported from public repositories using pom.xml, it's sqljdbc41.jar.

我可以从我的 IDE 在本地运行该项目,一切都会正常进行.下载后我引用了该库,如下所示:

I can run the project locally from my IDE, and everything will work. I referenced the library after downloading it like so:

<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 没有.

When I run mvn clean package to create my .jar file and try to run the created .jar, a mistake will pop up, which mentions the SQL Server references are not valid. I then extracted my .jar file and true enough, everything that is referenced in the pom.xml file properly gets downloaded and added, however, my SQL Server does not.

我可以,以一种非常hacky的方式*在编译为.jar后手动将sqljdbc41.jar添加到我的/lib文件夹中,它会工作,但是这看起来很不理想.什么是更好的方法?

I can, in a very hacky way* just manually add the sqljdbc41.jar to my /lib folder after it's been compiled as a .jar, and it'll work, however that seems highly unoptimal. What would be a better approach?

*用 Winrar 打开 .jar 文件,转到/lib 文件夹,手动选择我的 sqljdbc41.jar 文件,然后确保选择左下角的 No Compression 选项,Winrar 为您提供压缩选项,以防万一您通过 Google 找到此内容而没有人回答.

*Opening the .jar file with Winrar, going to the /lib folder, manually selecting my sqljdbc41.jar file, then make sure to select the No Compression option bottom left where Winrar gives you compression options, in case you find this by Google and no one answered.

推荐答案

您可以将 'includeSystemScope' 设置为 true.

you can set 'includeSystemScope' to true.

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

这篇关于将外部库 .jar 添加到 Spring boot .jar internal/lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆