I have 2 property files which are part of my java eclipse project. Now i need to pass the path of these 2 files as a system property like -Dpath1="pathfile1"
as project will only accept it as a system property.
One option is that i can specify the absolute path but i want to specify a path relative to my project something like -Dpath1=$Project_Dir/resource/file1
. Reason being, if project directory is moved then project will start failing.
I am using eclipse to run this project and dont want to declare any new system variable for supporting relative path, so for example dont want to create a new system variable Project_Dir
. Is it possible to achieve this and how?
You can set system properties with:
System.setProperty("path1", yourPathHere);
Now, you only have to build the correct path, relative to where your project is. To do this, start off with the location of the project: How to get the path of a running JAR file?