Can you set the current running directory from the java command line?

34,188

Solution 1

There is a JVM argument -Duser.dir which can be used to set working directory for JVM.

Solution 2

If it all possible I would rather use a script to run the java application and set the directory in the script:

#!/bin/sh
cd <your dir>
java <some arguments>

The JNI-solution may affect all kinds of relative paths in your application; for examples the classpath you put in.

Share:
34,188
user538442
Author by

user538442

Updated on July 09, 2022

Comments

  • user538442
    user538442 almost 2 years

    I am running a Java application from the command line. Can I specify a command line argument to set the current running directory to something other than where the application is actually going to run?