Read properties file outside JAR file

I have a JAR file where all my code is archived for running. I have to access a properties file which need to be changed/edited before each run. I want to keep the properties file in the same directory where the JAR file is. Is there anyway to tell Java to pick up the properties file from that directory ?

Note: I do not want to keep the properties file in home directory or pass the path of the properties file in command line argument.


So, you want to treat your .properties file on the same folder as the main/runnable jar as a file rather than as a resource of the main/runnable jar. In that case, my own solution is as follows:

First thing first: your program file architecture shall be like this (assuming your main program is main.jar and its main properties file is

./ - the root of your program
 |__ main.jar

With this architecture, you can modify any property in the file using any text editor before or while your main.jar is running (depending on the current state of the program) since it is just a text-based file. For example, your file may contain:


So, when you run your main program from its root/base folder, normally you will run it like this:

java -jar ./main.jar

or, straight away:

java -jar main.jar

In your main.jar, you need to create a few utility methods for every property found in your file; let say the app.version property will have getAppVersion() method as follows:

 * Gets the app.version property value from
 * the ./ file of the base folder
 * @return app.version string
 * @throws IOException

import java.util.Properties;

public static String getAppVersion() throws IOException{

    String versionString = null;

    //to load application's properties, we use this class
    Properties mainProperties = new Properties();

    FileInputStream file;

    //the base folder is ./, the root of the file  
    String path = "./";

    //load the file handle for
    file = new FileInputStream(path);

    //load all the properties from this file

    //we have loaded the properties, so close the file handle

    //retrieve the property we are intrested, the app.version
    versionString = mainProperties.getProperty("app.version");

    return versionString;

In any part of the main program that needs the app.version value, we call its method as follows:

String version = null;
     version = getAppVersion();
catch (IOException ioe){

Leave a Reply

Your email address will not be published. Required fields are marked *