I have a java gradle project with multiple main class, i want to build a docker image with Jib and chose which main class to run when i execute docker run.
Is it possible to do this with Jib or i have to build multiple docker image for each main class i have ?
If i dont choose a mainclass in jib gradle config, it failed with :
Multiple valid main classes were found: ...
I try with a custom entrypoint, but no success for now, but i dont no how to pass the MainClass as an argument
container {
entrypoint = ['/bin/sh', '-c', 'java -cp $( cat /app/jib-classpath-file ) MainClass']
}
2
Answers
I finally found a solution quite simple with jib :
and
Container runtimes (e.g., Docker, Kubernetes, etc.) provide a way to override the entrypoint set in an image to whatever value you want. For example, with the Docker engine, you could do
If you problem is the failure above due to multiple main classes, you can set
container.mainClass
to your desired main class.