Accessing executing folder when running a jar file

I would like to be able to run a jar file java -jar myapp.jar on different folders and have it load based on the executing context.


/folder2/java -jar /myapp/myapp.jar    <------ loads /folder1/

/some/folder2/java -jar /myapp/myapp.jar   <------ loads /folder2/

Once the properties are loaded, I want it to then create some files in the current execution folder.


  1. How do I tell java to load a properties file based on the current executing context?
  2. How do I get access the folder that the jar was executing from?


When you provide a relative path to the constructor of the class File like new File(""), behind the scene, the absolute path built is

System.getProperty("user.dir") / 

with user.dir that is actually the User working directory which is also the directory from which you launch your command.

Leave a Reply

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