0

I'm new to Linux, Java, and Apache Commons Configuration and am having issues locating a properties file between environments.

I'm building a Spring API with Maven on Windows and have a .properties file i want to pull settings from. I also am trying to publish this API to a Linux based Docker container and am confused about the file location strategies.

Everything works on Windows with the properties file in C:\users\myusers\app.properties. On the Linux container, i have both my jar and properties file here /usr/bin/myapp but I am unsure how to use any of the strategies to access both, as this fails in Docker/Linux.

Is there a best practice on where i should store the properties file in the container?

CombinedLocationStrategy strategy = new CombinedLocationStrategy(
    Arrays.asList(new HomeDirectoryLocationStrategy(), new FileSystemLocationStrategy()));

Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = 
       new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
                           .configure(params.fileBased()
                                   .setLocationStrategy(strategy)
                                   .setFileName("app.properties"));
Configuration propConfig = builder.getConfiguration();

rootDirectory = propConfig.getString("rootfolder");
aksappy
  • 3,400
  • 3
  • 23
  • 49
Cam Bruce
  • 5,632
  • 19
  • 34

1 Answers1

0

Just like in linux, we can mount volumes in docker as well. This will help in having a single volume for shared properties or locations.

Firstly, mount a directory from the host system as a volume into the container. Please see the documentation here

If you mount it say - /opt/myapp , then the files will be visible for the container at /opt/myapp.

aksappy
  • 3,400
  • 3
  • 23
  • 49
  • I don't want to share files between Windows and Docker/Linux, I just want to deploy JAR and .properties file to Docker and it's able to read the configuration based on code above – Cam Bruce Nov 15 '19 at 03:45