Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put properties file in eclipse and how to access the path both locally and on server

I saw some similar questions on this,but I don't understand them enough so i want to ask the question and tailor it my own way.

I have a properties file that I store in src/main/resources, and then reference this in my code like so:

    Properties prop = new Properties();
    InputStream input = null;

    try { 
        input = new FileInputStream("src/main/resources/app.properties");

        // load a properties file
        prop.load(input);

this works locally, however when I create a .war file and deploy it to the sever it has no idea where the properties file is. Where do I put this properties file, and how do I reference it in the code, so that I can run it locally, and on the server without any problems?

like image 479
eaglei22 Avatar asked Dec 19 '25 04:12

eaglei22


1 Answers

I assume you have maven project, you can put that properties file at src/main/resources/app.properties and change the code to read it as

getClass().getClassLoader().getResourceAsStream("/app.properties");
like image 61
jmj Avatar answered Dec 20 '25 18:12

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!