System.getProperty("user.dir") cannot get my project root path ,but the path which my eclipse is located
- by facebook-100005613813158
As the title goes , I have class named GetException.java,inside it ,I read a xml file in a static code block like(Because this document is shared):
static{
...
document = db.parse(new File(System.getProperty("user.dir")+"/src/exception/ExceptionCode.xml"));
...
}
To test if the file path is correct, I write a main function just inside GetException.java, it proves that the path is correct ,xml file can be read successfully.
My project root dir is "/home/wuchang/workspace/MongodbI".
But When this Class is loaded from other class,such as I called one of its static functions , it reports the error message:
/home/mrs/??/eclipse/src/exception/ExceptionCode.xml (No such file or directory)
/home/mrs/??/eclipse/ is actually my eclipse installation directory.So , I wander how System.getProperty("user.dir") returned the eclipse installation directory to me ,instead of my project root directory?