Red Alert
Red Alert

Reputation: 3816

Is it possible to set the JVM working directory on startup?

I'm using JNI to startup a JVM and I can't figure out how to set the working directory. I've tried

options[1].optionString = "-Duser.dir=directory";
vm_args.options = options;

as part of my JNI_CreateJavaVM args, but it doesn't work. The user.dir system property is set to what I specified in my parameters, but the actual relative directory used by things like FileReader is the same directory as whatever I use to call the dll. Is there any way to tell the JVM where the cwd should be on startup?

Upvotes: 0

Views: 2131

Answers (2)

user207421
user207421

Reputation: 311013

You could call 'chdir()', but it isn't advisable for programs other than the shell to do so. Just change the current directory yourself in the shell before you start it.

Upvotes: 2

Samhain
Samhain

Reputation: 1765

Since the JVM isn't started as its own executable, your working directory is where your base application is running.

Upvotes: 1

Related Questions