Lokesh Lokesh - 1 year ago 86
Java Question

Need to set path as a system property for java project

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

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
. 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
. Is it possible to achieve this and how?

Answer Source

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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download