-2

I want to use my project dir to run the code when I wrote following command,

public static String userDir = System.getProperty("user.dir");

its returns me my Eclipse Dir path instead of my workspace path. I tried almost all the ways from here, but couldn't manage to solve the problem. I also tried

Path currentRelativePath = Paths.get("");
    String s = currentRelativePath.toAbsolutePath().toString();
    System.out.println("Current relative path is: " + s);

but it also display same result.

promitheus
  • 67
  • 2
  • 13
  • Possible duplicate of [Getting the Current Working Directory in Java](http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java) – rkosegi Jan 17 '17 at 09:34
  • Tried that way result was same as user.dir, isnt solved my problem. – promitheus Jan 17 '17 at 09:37

2 Answers2

1

It points to the dir where Java starts from. You are starting your app from Eclipse so it shows Eclipse dir. Try to export jar and run by java -jar my.jar.

liquid_code
  • 577
  • 7
  • 12
  • Thanks, I tried to run via Eclipse previously, it was successfully run later I deploy the code in Mercurial and then this error comes up. – promitheus Jan 17 '17 at 09:35
1

Open 'Run > Run Configuratons...'.

Find your program in the 'Java Application' section.

On the 'Arguments' tab look at the 'Working directory' section and change this to what you want.

greg-449
  • 109,219
  • 232
  • 102
  • 145