vbNewbie
vbNewbie

Reputation: 3345

jar file not reading correct properties file

I have managed to create a jar file with the libraries packaged in a separate folder. I want to be able to deploy the jar, folder and separate properties file on different servers and it seemed to run fine. But each jar file seems to be reading the same properties file no matter what changes I make to each property file. What is the correct way to create this jar with an external properties file?

My project is setup with the properties file under /src/main/resources and the main class under /src/main/java and I call the file as follows:

fileProp.load(configuration.class.getClassLoader().getResourceAsStream("config.properties"));

Any help appreciated.

Upvotes: 0

Views: 702

Answers (2)

Sanjeev
Sanjeev

Reputation: 9946

You should put your properties file in same package as your class to read it like this

configuration.class.getClassLoader().getResourceAsStream("config.properties")

Or you can place properties file relative to your current directory and read it by

ClassLoader.getSystemResourceAsStream("config.properties");

Hope this helps

Upvotes: 1

Jacques Ramsden
Jacques Ramsden

Reputation: 871

You are reading the properties file from inside the jar file. Would it not be better to read the file in as a normal file

File file = new File('config/config.properties');
fileProp.load(file);
......

Upvotes: 1

Related Questions