簡體   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