WildDev
WildDev

Reputation: 2367

JBoss7/WildFly webapp - how to access properties file from class

I try to load webapp project's settings from own config.properties file, but there's no success: the file not found. I can't use ServletContext method, because i've access the file from ordinary class.

file = Config.class.getClassLoader().getResourceAsStream("/config.properties");

- it's returns null.

I've tried to put the file to WEB-INF and resources folders, still doesn't work :(

Any ideas how to force this work?

Upvotes: 0

Views: 345

Answers (2)

zsom
zsom

Reputation: 499

Try putting files in WEB-INF/classes .

If you put your config in src, than after compile it will be in WEB-INF/classes.

Upvotes: 2

Pau Carre
Pau Carre

Reputation: 471

My recommendation for configuration files that would solve your problem is to place them in a folder that depends on an environment variable.

If you application is called MyApp, then you can force the user to place that file in the folder that points the environment variable MY_APP. You could in fact make it mandatory to run the application with a start up check.

Usually you should specify default values for your configuration parameters if you want your application to run without the environment variable.

To get enviroment variables in Java you can use System.getenv();

Upvotes: 0

Related Questions