简体   繁体   中英

How to pass external jar file to spring boot project?

I am creating spring boot restful application. This application uses external jar files.

When I create war file for application and deployed on local as well as server then this works fine. But when I create executable jar file of this application this is not using external jar file. I have class not found exception.

How Can I resolve this problem?

Anyone suggest me the way to pass external jar file for executing jar file.

May be that could help

    <dependency>
        <artifactId>com.google</artifactId>
        <groupId>Ab</groupId>
        <version>0.0.4.3</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/Ab.jar</systemPath>
    </dependency>

This way you can add any jar file as a maven dependency.

install your external jar using

mvn install:install-file 

then provide it as maven dependency

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

</dependency>

and spring will package it in final executable jar

for more details on installing custom jar refer this

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. Here is an article on how to do that for maven. This is for gradle ( https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow ).

Gradle

Using the plugins DSL:

plugins {
  id "com.github.johnrengelman.shadow" version "5.1.0"
}

Using legacy plugin application:

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>

I have to makes changes in pom file. This will solve my issue.

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

I just add this lines then my executable jar file works fine.

<configuration>
    <includeSystemScope>true</includeSystemScope>
    </configuration>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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