#289 Working directory relative to where the program is started



I am trying to make a command line tool that behaves like the Windows copy command. Where:
copy myfile.txt mycopy.txt
copies the relative file myfile.txt to another relative file mycopy.txt. Both the files are relative to current working directory.

But when I launch my program using the wrapper the all paths are resolved relative to the "copy.exe" file since the working directory of the JVM is the directory of the copy.exe dir.
I have played with the wrapper.working.dir configuration but it lacks a "Users current working directory" option.

Is there a way to get access to the users working directory from within Java?


  • Leif Mortenson

    Leif Mortenson - 2010-10-07

    What you are asking is not currently possible with the Wrapper. The Wrapper needs to force the working directory to a known location so it is able to reliably read from its configuration file and also write out its various state and log files.

    Yours is actually the first request for some thing like this. But I was able to implement a very simple solution which might work for you.

    Starting with version 3.5.6, the Wrapper will define a new environment variable, WRAPPER_INIT_DIR, which can be used to reference the directory from which the Wrapper was launched. This is the "current working directory" that you are asking for. This can then be passed off to the JVM as a system property so your application can make the necessary path adjustments to do what you want to do.



    Please let me know what you think of this solution. 3.5.6 will out within the next few days.


  • Leif Mortenson

    Leif Mortenson - 2010-10-07
    • milestone: --> v3.5.5
  • Tobias Tobiasen

    Tobias Tobiasen - 2010-10-07

    That is perfect and will solve my issue. Thanks.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks