0

I have an spring-boot application deployed on Openshift. This application is dependent on a plain old java application, which has been added as maven dependence. The maven dependence requires a foo.properties file on the classpath, it loads the foo.properties file using:

inputStream = this.getClass().getResourceAsStream("/foo.properties");

The foo.properties file will contain different values depending on the environment it's deployed to. I have tried to externalise the properties by adding a configmap to openshift, and mounting it at: /deployments/config

I have added spring properties to the openshift environment variables:

spring.config.name foo
spring.config.location /deployments/config/

However the maven dependence is unable to pick up the foo.properties, returning null.

Is what I'm attempting achievable, or are there alternative solutions to this problem?

JTK
  • 1,469
  • 2
  • 22
  • 39
  • have you tried smth. like: `java -cp "directory where foo.properties is located" -jar myapplication.jar` ? – Andrey B. Panfilov Feb 21 '23 at 14:39
  • It's not possible to use -cp and -jar together: https://stackoverflow.com/questions/13018100/execute-jar-file-with-multiple-classpath-libraries-from-command-prompt – JTK Aug 31 '23 at 14:40

2 Answers2

1

spring.config.location has nothing to do with java native getResourceAsStream method, therefore it doesn't help

For JVM to interpret /deployments/config/ as part of your classpath, you have to include this folder to the classpath in java command.

You probably have a Dockerfile with this line

java -jar service.jar

Modify it to

java -cp /deployments/config -jar service.jar
Boris
  • 1,054
  • 1
  • 13
  • 23
  • It's not possible to use -cp and -jar together: https://stackoverflow.com/questions/13018100/execute-jar-file-with-multiple-classpath-libraries-from-command-prompt – JTK Aug 31 '23 at 14:39
0

This was solved by configuring OCP4 Environment Variables: JAVA_MAIN_CLASS, JAVA_CLASSPATH

JAVA_MAIN_CLASS=-Dloader.main=your.spring.application.class org.springframework.boot.loader.JarLauncher

JAVA_CLASSPATH=/deployments/your.spring.application.jar:/deployments/data/:.

It's not possible to use both -jar and -cp on the command line: https://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/java.html#-jar

JTK
  • 1,469
  • 2
  • 22
  • 39