1

I am running java application in docker container as executable jar. For example

$ java -jar MyApp.jar

This application refers the application resource files from class path. Since application resource files different for each environment, I am mounting the application resource files to the Kubernates pod for each environment separately. My application needs to refer this external mounted path for the application resources during the run time. After googling I found that -cp is ignored when we run as executable jar. For Example,

$ java -cp /app/resource -jar MyApp.jar

This does not work as -cp is ignored for the executable jar.

Please let me know if we have any other option. Thanks

Note: Though this is Spring Boot application, this app does not support profile based running due to framework used in the application. Application resource files I am referring are not spring boot related resource files.

0

1 Answer 1

0

There's no way to have java read and apply the Class-Path entry from the jar classpath while also adding some additional paths to the classpath on top.

Hence, you'd have to reproduce the entire class-path as stated in the jar file, and then run java -cp MyApp.jar:/app/resource:/replicate/all/entries/from/jar/manifest/here com.foo.Main.

Alternatively, ensure the Class-Path entry in the jar lists some jar that doesn't exist, and then you make it, put it in the right place, and run with java -jar myapp.jar from there.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer and clarity. here com.foo.Main is the application Main class to start with? I will give a try this one.
Yes; its what is listed in the jar manifest as Main-Class.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.