I have an application that requires configuration on start-up. However, I can't store this in /resources since every environment that will host this application will be completely different. For now, I want to add a directory from the filesystem to the classpath - let's say /tr/apps/ (where /tr/apps/ is the root of where the application is deployed).
I found a Maven plugin which looked like it would do the job: https://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html
So I added this to my pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>/tr/apps</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
Now I have to use the following method to get the file:
InputStream inputStream = Thread.currentThread().getContextClassloader().getResourceAsStream("tr/apps/myFile.txt")
if(inputStream == null) {
throw new Exception("myFile.txt not found");
}
This exception always seems to be thrown (i.e. it isn't able to find the file on the classpath). Does anybody know why this is? Or if there is an alternative plugin/solution for this?
Would really appreciate any input!