2

Up until now I was able to load the properties files via ClassLoader since it was a standalone app -> jar

/**
 * Path and filename for {@code.properties}.
 */
private String propertiesFileName = "./com/config/resources/config.properties";

propertiesFromFile.load(ClassLoader.getResourceAsStream(propertiesFileName));

Now I need to use this jar within a web app the problem is that via ClassLoader I get NULL

How can make that inside jar will be able to read is properties file ?

Is there I why via maven ?

Please advice

Thanks

angus
  • 3,210
  • 10
  • 41
  • 71
  • Have you already read [this question](http://stackoverflow.com/questions/3160691/how-to-read-properties-file-in-web-application)? – LaurentG Jun 21 '13 at 14:53
  • Yes I was checking this answer basically I need to remove the dot "/com/config/resources/config.properties". this will work when adding the jar to the web app lib but not when running the jar. – angus Jun 21 '13 at 15:54
  • I had some code of my own doing this until I realized it was easier to let spring read my properties files. You can pass in file locations as jvm arguments and override a base set of properties. Best of all the properties are injectable. – Ben Thurley Jun 21 '13 at 16:01

1 Answers1

1

I experienced similar issues with different behaviours on different platforms when I use java.util.Properties. In the end I settled with using Apache Commons - Java Configuration API:-

PropertiesConfiguration properties = new PropertiesConfiguration("my.properties");
String propertyValue = properties.getString("prop.key");

The path to my properties files are set in my JVM classpath prefix when I start my container.

StackEng2010
  • 342
  • 1
  • 6
  • 19