hexacyanide
hexacyanide

Reputation: 91629

Java: How to run a Java process in a specific directory?

When I run a jar file, say in /home/jars like such java -jar /home/jars/jarfile.jar, it seems to run in whatever directory I'm in.

How do I make it so java -jar /home/jars/jarfile.jar runs with /home/jars as the current working directory??

Upvotes: 0

Views: 141

Answers (1)

Richard Sitze
Richard Sitze

Reputation: 8463

The simple answer:

( cd /home/jars; java -jar /home/jars/jarfile.jar )

See also this response.

The analogy for most languages supporting an exec call, is the variant of exec that lets you specify a working directory.

See this for simple PHP solution.

Upvotes: 4

Related Questions