I cannnot run CommandLineJobRunner in dockerfile

Viewed 32

I run following code. But output error.

(Docker file)
From openjdk
COPY ./* /tmp
WORKDIR /tmp
ENV CLASSPATH=target/spring_batch_commandline_sample-1.0-SNAPSHOT.jar:lib/*:target/classes/*
CMD java org.springframework.batch.core.launch.support.CommandLineJobRunner -next job-setting.xml job1

Files

(error:runnning container after building image)
Error: Could not find or load main class org.springframework.batch.core.launch.support.CommandLineJobRunner
Caused by: java.lang.ClassNotFoundException: org.springframework.batch.core.launch.support.CommandLineJobRunner

I could run the files on windows powershell and wsl.

(powershell)
java -cp 'target/spring_batch_commandline_sample-1.0-SNAPSHOT.jar;lib/*' org.springframework.batch.core.launch.support.CommandLineJobRunner -next job-setting.xml job1
(wsl)
java -cp 'target/spring_batch_commandline_sample-1.0-SNAPSHOT.jar:lib/*' org.springframework.batch.core.launch.support.CommandLineJobRunner -next job-setting.xml job1

I cannnot understand the reason of this error. Please answer it.

1 Answers

Try to surround the value of CLASSPATH with "", meaning:

ENV CLASSPATH="..."

Also try to explicitly add the classpath to your command:

CMD java -cp $CLASSPATH ...

That said, I would recommend shading your jar and use a command like:

java -jar mybachjob.jar

Spring Boot does that for you, otherwise you can use maven shade plugin.

Related