-2

I have added the jar in the path : root-project->lib->jumper.jar

POM.xml

<dependency>
  <groupId>com.abc</groupId>
  <artifactId>jump</artifactId>
  <version>1.0</version>
  <scope>system</scope>
  <systemPath>${basedir}/lib/jumper.jar</systemPath>
</dependency>

this works locally but when deployed to Kubernetes it's not working

Girish
  • 2,196
  • 2
  • 18
  • 24

1 Answers1

0

This happens because of <scope>system</scope>. It's telling Maven that the library is gonna be loaded in the system. To fix this issue, one thing you can do is generate a jar with all dependencies included using Maven plugin

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>your.main.class.here</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

That plugin will generate a bigger jar than usual containing all the dependencies in it.

Now it's just simple as running the jar with java -jar file.jar

  • Plugin 'org.apache.maven.plugins:maven-assembly-plugin:' not found – Girish Oct 26 '22 at 09:48
  • After Adding no errors – Girish Oct 26 '22 at 10:02
  • Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/abc/JumpLine] with root cause java.lang.NoClassDefFoundError: com/abc/JumpLine After updating like above mentioned still it's not workig – Girish Oct 26 '22 at 10:13
  • Make sure you are executing the `jar-with-dependencies` and not the one with no dependencies on it. – Leonardo Emmanuel de Azevedo Oct 26 '22 at 11:24