I’m building a java application to run on a schedule using Cloud Run Jobs. This application has a main method that is called to perform its task. I am packaging this up into a docker container that runs successfully on my local machine using Docker Desktop. I then tag and push the image to Artifact Registry. I then select the image when setting up a new Cloud Run Jobs Instance and it fails. It is failing and exiting with an error. The logs read as this:
2022-09-06T04:03:30.441244ZError: Could not find or load main class one.studio.Main Default 2022-09-06T04:03:30.441270ZCaused by: java.lang.ClassNotFoundException: one.studio.Main Warning 2022-09-06T04:03:30.449143ZContainer called exit(1).
This really confuses me about everything I’ve been learning about Docker, in that I thought the application is able to execute the same on each machine. I’m not really sure what to include for this, as I don’t see what would have an effect on this.
Dockerfile
FROM amazoncorretto:17
COPY target/classes/ /tmp
WORKDIR /tmp
ADD ./lib/mysql-socket-factory-1.5.0-jar-with-dependencies.jar lib/
ADD ./lib/mysql-connector-java-8.0.29.jar lib/
ADD ./lib/twilio-9.0.0-rc.3-jar-with-dependencies.jar lib/
ADD ./lib/my-erp-359002-2816e69f4a8a.json /tmp/lib/my-erp-359002-2816e69f4a8a.json
ENV CLASSPATH=lib/mysql-connector-java-8.0.29.jar:${CLASSPATH}
ENV CLASSPATH=lib/mysql-socket-factory-1.5.0-jar-with-dependencies.jar:${CLASSPATH}
ENV CLASSPATH=lib/twilio-9.0.0-rc.3-jar-with-dependencies.jar:${CLASSPATH}
ENV GOOGLE_APPLICATION_CREDENTIALS="/tmp/lib/my-erp-359002-2816e69f4a8a.json"
CMD java one.studio.Main
docker-compose.yml
version: "3"
services:
web-app:
build: .