Java – no matter how the application starts, you can find the conf text
I'm new to Java
I have some directory structures
product/ conf/ classes/com/../..
Conf / contains some configuration files, while in class / I have my application
How do I ensure from Java code that I can find the file in conf / even though I'm executing it (e.g. from eclipse, from different directories, from crontab, etc.)
Attached:
The file in conf / is not a resource because it needs to be edited by the user Is there any way to know my name Where is class, so I can use a relative path from this directory to my directory (for example, my_class_dir /.. /.. /.. / CONF)
Solution
You can use absolute paths, including product ways
Alternatively, you can use the configuration settings by launching the program
java -DXY_HOME=/some/path/product ...
From Javacode, you can use it:
String xyHome = System.getProperty ("XY_HOME")
Or you can use an INI file in your home directory, where you can specify where to find the conf directory
Reread your question many times. I don't know what your goal is Find the conf directory (eclipse, crontab,...) independent of where you are? But the title requires CWD, which is the opposite - the directory, depending on where you are
Both are possible, but you have to decide what you want