Loading property file from Resource Folder or Jar Path

Viewed 24

I have a multimodule (multiple jar files and war files) project with lots of shared properties. To make the code DRY I divided the properties in to multiple files and embed via maven resource plugin.

In some build I want to embedd the property file in the war file and in another scenario (JAR files) I dont want to embedd the property file. So I use the maven-resource plugin to copy the resource to the folder with jar and disable the embedding the property files in the jar.

I have used @PropertySource annotation to load the property files.

@PropertySource("classpath:database-postgres.properties")

This works fine in the war files where the property files are embedded in the build. But in the jar files this fails. When I used

@PropertySource("file:database-postgres.properties")

This worked in the jar scenarios. The property files are copied to the directory of the jar file.

I want to know if there is any safe method to load the property file in all the build files.

0 Answers
Related