繁体   English   中英

如何将外部 jar 文件传递给 spring 引导项目?

[英]How to pass external jar file to spring boot project?

我正在创建 spring 启动宁静应用程序。 此应用程序使用外部 jar 文件。

当我为应用程序创建war文件并部署在本地和服务器上时,这工作正常。 但是当我创建这个应用程序的可执行 jar 文件时,这没有使用外部 jar 文件。 我有 class 未发现异常。

我该如何解决这个问题?

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

可能会有所帮助

    <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 依赖项。

使用安装您的外部 jar

mvn install:install-file 

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

<dependency>
        <artifactId>your-custom-jar</artifactId>
        <groupId>group.id</groupId>
        <version>0.0.1</version>

</dependency>

和 spring 将 package 它在最终可执行文件 jar

有关安装自定义 jar 的更多详细信息,请参阅

You need to create Fat Jar / Uber Jar / Shadow Jar/ Shaded Jar (whichever name you prefers) so that all your dependencies is wrapped inside the jar file. 这是一篇关于如何为 maven 执行此操作的文章。 This is for gradle ( https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow ).

Gradle

使用插件 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"

Maven

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.0.1.RELEASE</version>
    </plugin>
</plugins>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM