I have created a Dockerfile and has passed a entrypoint.sh into it which is responsible for running the java command. Build of the dockerfile is happening successfully but when I run it, it shows the below error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at com.test.tp.Application.main(Application.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Dockerfile
FROM company.com/openjdk8-builder:123456789 as builder
ARG appId
ARG appDirectory
ARG oorCommand
RUN useradd -u 1001 user
RUN mkdir -p -m777 /usr/local/
COPY /entrypoint.sh /entrypoint.sh
RUN sed -i "s/__PACKAGE__/${appId}/g" "/entrypoint.sh"
RUN sed -i "s#__OOR_COMMAND__#${oorCommand}#g" "/entrypoint.sh"
RUN chown -R user: /entrypoint.sh && chmod -R u+rwx /entrypoint.sh
COPY --chown=user:user /target/* /usr/local/
USER 1001
ENTRYPOINT [ "/entrypoint.sh" ]
Entrypoint file
#!/usr/bin/env bash
set -e
CLASS_PATH="/usr/local/"
java -cp $CLASS_PATH com/test/tp/Application
pomx.xml file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>LearningKubernetes</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.source-target.version>1.8</java.source-target.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web-services -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
<version>2.6.7</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Test.java</include>
<include>**/*Test.groovy</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I am not using CMD instruction as I want some more entrypoints to be added in future. So i have implemented it in this way. I have ran the maven clean install command in the local and have the target folder created over there.
I want to get the rid of the class not found error. Can someone pls help me with it.