Home > database >  Dockerfile ENTRYPOINT for java -cp argument
Dockerfile ENTRYPOINT for java -cp argument

Time:09-27

I'm attempting to create a docker file for running a program that takes the mysqlconnector jar when I run it on gitbash:

java -cp mysql-connector-java-8.0.26.jar test.java

How do I translate this to the Dockerfile? I have attempted setting the ENTRYPOINT as the string above but get an error saying

“Could Not Find or Load Main Class” Error test.java

CodePudding user response:

Docker does know anything about your needed dependencies. You will need to move all your classes/3rd party jars into a common folder to mimic how you are doing it locally.

FROM openjdk:11

# Set up the Environment Variable for Application
ENV APP_HOME=/app

# Create the directories for Application
RUN mkdir -p ${APP_HOME}

# Setting up the Work directory
WORKDIR ${APP_HOME}

# Exposing the Application Port
EXPOSE 8080

# COPY dependencies
COPY /send-email-api/target/your-mysql-jars ${APP_HOME}

# Copying the artifact from host machine to containers
COPY /send-email-api/target/*classes ${APP_HOME}


ENTRYPOINT java -cp mysql-connector-java-8.0.26.jar test.java

or

ENTRYPOINT ["java","-cp","mysql-connector-java-8.0.26.jar","test.java"]

CodePudding user response:

Maybe do you need the package's path, for example

java -cp mysql-connector-java-8.0.26.jar my/package/test.java

And obviously this class must be have a main method

  • Related