Reputation: 7940
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?
Upvotes: 2
Views: 8358
Reputation: 1467
When using setProperty
, you can reference internal project files if you use a plain relative path.
E.g. to reference a file located at /abc/def/workspace/project/lib/driver.exe:
System.setProperty("driver", "lib/driver.exe");
It's deceivingly simple.
Upvotes: 1
Reputation: 68877
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?
Upvotes: 3
Reputation: 210
Yes, you can do it.Eclipse have build-in Path variable PROJECT_LOC, it stores location of project folder, e.x. c:\Workspace\Project1. You can use this property in launch configuration.
Upvotes: 0