如何将外部jar文件传递到spring boot项目?

我正在创建 Spring Boot Restful 应用程序。此应用程序使用外部 jar 文件。

当我为应用程序创建 war 文件并部署在本地和服务器上时,效果很好。但是,当我创建此应用程序的可执行 jar 文件时,它没有使用外部 jar 文件。我有类未发现异常。

我该如何解决这个问题?

任何人都建议我传递外部 jar 文件来执行 jar 文件的方法。


holdtom
浏览 255回答 4
4回答

守候你守候我

也许这会有所帮助&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>com.google</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>Ab</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <version>0.0.4.3</version>&nbsp; &nbsp; &nbsp; &nbsp; <scope>system</scope>&nbsp; &nbsp; &nbsp; &nbsp; <systemPath>${basedir}/lib/Ab.jar</systemPath>&nbsp; &nbsp; </dependency>这样你就可以添加任何 jar 文件作为 Maven 依赖项。

森栏

使用以下命令安装外部 jarmvn install:install-file 然后将其作为 Maven 依赖项提供<dependency>        <artifactId>your-custom-jar</artifactId>        <groupId>group.id</groupId>        <version>0.0.1</version></dependency>spring 会将其打包到最终的可执行 jar 中

波斯汪

您需要创建 Fat Jar / Uber Jar / Shadow Jar/ Shaded Jar(无论您喜欢哪个名称),以便所有依赖项都包含在 jar 文件中。摇篮使用插件 DSL:plugins {  id "com.github.johnrengelman.shadow" version "5.1.0"}使用遗留插件应用程序:buildscript {  repositories {    maven {      url "https://plugins.gradle.org/m2/"    }  }  dependencies {    classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"  }}apply plugin: "com.github.johnrengelman.shadow"梅文<plugins>    <plugin>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-maven-plugin</artifactId>        <version>2.0.1.RELEASE</version>    </plugin></plugins>

HUH函数

我必须在 pom 文件中进行更改。这将解决我的问题。<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><includeSystemScope>true</includeSystemScope></configuration></plugin></plugins></build>我只需添加这一行,然后我的可执行 jar 文件就可以正常工作。<configuration>&nbsp; &nbsp; <includeSystemScope>true</includeSystemScope>&nbsp; &nbsp; </configuration>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java