0

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??

Richard Sitze
  • 8,262
  • 3
  • 36
  • 48
hexacyanide
  • 88,222
  • 31
  • 159
  • 162

1 Answers1

4

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.

Community
  • 1
  • 1
Richard Sitze
  • 8,262
  • 3
  • 36
  • 48
  • Read the link provided in answer. The bottom line portable solution is that the JVM must be launched into the desired directory. The link does provide other alternatives. – Richard Sitze Aug 14 '12 at 01:16