为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

holdtom 2023-08-23 16:49:06
我正在创建 Spring Boot Restful 应用程序。此应用程序使用外部 jar 文件。当我为应用程序创建 war 文件并部署在本地和服务器上时,效果很好。但是,当我创建此应用程序的可执行 jar 文件时,它没有使用外部 jar 文件。我有类未发现异常。我该如何解决这个问题?任何人都建议我传递外部 jar 文件来执行 jar 文件的方法。
查看完整描述

4 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

也许这会有所帮助


    <dependency>

        <artifactId>com.google</artifactId>

        <groupId>Ab</groupId>

        <version>0.0.4.3</version>

        <scope>system</scope>

        <systemPath>${basedir}/lib/Ab.jar</systemPath>

    </dependency>

这样你就可以添加任何 jar 文件作为 Maven 依赖项。


查看完整回答
反对 回复 2023-08-23
?
森栏

TA贡献1810条经验 获得超5个赞

使用以下命令安装外部 jar


mvn install:install-file 

然后将其作为 Maven 依赖项提供


<dependency>

        <artifactId>your-custom-jar</artifactId>

        <groupId>group.id</groupId>

        <version>0.0.1</version>


</dependency>

spring 会将其打包到最终的可执行 jar 中

查看完整回答
反对 回复 2023-08-23
?
波斯汪

TA贡献1811条经验 获得超4个赞

您需要创建 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>


查看完整回答
反对 回复 2023-08-23
?
HUH函数

TA贡献1836条经验 获得超4个赞

我必须在 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>

    <includeSystemScope>true</includeSystemScope>

    </configuration>


查看完整回答
反对 回复 2023-08-23
  • 4 回答
  • 0 关注
  • 222 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信