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
  • 7,886
  • 3
  • 32
  • 47
hexacyanide
  • 82,699
  • 31
  • 154
  • 158

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
  • 7,886
  • 3
  • 32
  • 47
  • 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