I have been trying to "dockerize" a microservice that I have built using java. However, I am having some issues with the classpath when using Docker. I am on a Linux machine using java open jdk 1.8. My dockerfile looks something like:
FROM openjdk:version
#`Make the directories I need
RUN mkdir -p /opt/service/libs
ENV LIBS_PATH=/opt/service/libs
ENV CLASSPATH=LIBS_PATH"/*"
COPY ./target/libs $LIBS_PATH
COPY ./target/MY_SERVICE.jar $LIBS_PATH
ENTRYPOINT java -cp $CLASSPATH "com.org.service.mainClass"
I have noticed when I do this and I echo the $CLASSPATH inside of the docker container, (using docker run), it returns all of the adresses of the jar files, but with a space in between instead of a : seperator. This implies two things, it knows where all of these jar files are and that the jar files have been successfully copied. I still get an error on the java -cp line. The error is as follows:
Error: Could not find or load main class .opt.service.libs.FirstJarInLibsFolder.jar
If I change the CLASSPATH
to have the :
separators where it is supposed to, I instead get the error:
Error: Could not find or load main class com.org.service.mainClass
even though my JAR contains that class.
Any thoughts on what it could be?
I have tried what is detailed above.