1

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.

  • what kind of external jar file are you dealing with. Can't you add this as a dependency in pom? – pvpkiran Sep 25 '19 at 09:57
  • can you show your pom.xml file – Keaz Sep 25 '19 at 10:56
  • 1
    Does this answer your question? [Add external library .jar to Spring boot .jar internal /lib](https://stackoverflow.com/questions/30207842/add-external-library-jar-to-spring-boot-jar-internal-lib) – Waqas Ahmed Apr 23 '20 at 13:29

4 Answers4

1

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.

Alexey Usharovski
  • 1,404
  • 13
  • 31
1

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

Shailesh Chandra
  • 2,164
  • 2
  • 17
  • 25
0

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>
so-random-dude
  • 15,277
  • 10
  • 68
  • 113
-1

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>