System.getProperty("user.dir") cannot get my project root path ,but the path which my eclipse is located

Posted by facebook-100005613813158 on Programmers See other posts from Programmers or by facebook-100005613813158
Published on 2013-10-18T08:45:23Z Indexed on 2013/10/18 10:14 UTC
Read the original article Hit count: 132

Filed under:
|

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?

© Programmers or respective owner

Related posts about java

Related posts about files