Home > database >  ClassNotFoundException for kotlin application inside docker container
ClassNotFoundException for kotlin application inside docker container

Time:08-09

I have simple kotlin application which I am trying to dockerise.

Dockerfile

FROM maven:3.8.1-openjdk-17-slim  AS base
RUN apt-get update
RUN apt-get upgrade -y

ENV MAVEN_CONFIG "/root/.m2"

VOLUME "/root/.m2"

COPY ./. /

ADD entrypoint.sh .

ADD target/simulation-1.0.jar ./

ENTRYPOINT ["./entrypoint.sh"]

entrypoint.sh

java -cp "kotlin-stdlib.jar;simulation-1.0.jar" com.demo.app.simulation.Simulator

Simulator.kt has main method

When I am running docker-compose with Dockerfile I am getting

Error: Could not find or load main class com.demo.app.simulation.Simulator

Caused by: java.lang.ClassNotFoundException: com.demo.app.simulation.Simulator

I am not sure what I am missing here. I am very new to Kotlin and Docker.

CodePudding user response:

I found one solution on this -

I use maven assembly plugin to build a .jar, move all my dependent jars into lib folder and run the command.

java -cp "lib\*:simulation-1.0.jar" com.demo.app.simulation.SimulatorKt
  • Related