Is there a JVM command-line option to change directory?

13,894

Solution 1

"Current working directory" is an OS concept, not a JVM one, so you'll need to find a solution at that level, such as writing a batch or shell script.

Solution 2

In Java SE, the "current directory" is put into the system property user.dir.

Manually override this value using a -D option might work:

java -Duser.dir=/some/directory ....

But I don't know if this also applies to the JVM used in Android

Share:
13,894
Jeff Axelrod
Author by

Jeff Axelrod

I'm an independent Android developer currently working on an educational application. It's important to me to continuously improve development techniques so I can maximize the "ilities" of software I write (reliability, maintainability, testability, understandability, etc.) Here's a mind map of tools and technologies I am presently using or investigating. You can click on hyperinks to bring you to related sites. I'm particularly interested in using Model-Driven Software Development to keep my architecture consistent and well documented. I am not yet using Scala on Android for anything other than testing, but plan to eventually migrate to Scala for the application code. Some of my favorite books: Effective Java (Bloch) Programming in Scala (Ordesky) Refactoring - Improving the Design of Existing Code (Fowler et al) Some favorite tools: Eclipse Guice + RoboGuice for dependency injection, though plan to replace this soon as startup is much too slow on Android OrmLite (ORM that works well on Android) Robotium for Android integration testing Eclispe EMF for MDSD Powermock + Mockito for mocking I learned a lot from Software Engineering Radio in its heyday.

Updated on June 13, 2022

Comments

  • Jeff Axelrod
    Jeff Axelrod almost 2 years

    In short, I want to know, is there a JVM command-line option to change the starting working directory? If it's important, I'm running jdk1.6.0_24.

    Background:

    I am using a tool called Robolectric for Eclipse to test Android applications on the host PC without emulation. Robolectric requires a test project be created, but the tests themselves to be run from the Android project under test. This is accomplished by from Eclipse, setting the run configuration to the project under test in the setting: "Run all tests in the selected project, package or source folder."

    I want to do this from the JVM command line options, if possible, because another tool I use, Infinitest, doesn't allow you to specify the working directory of the tests. It does, however, let you specify JVM command-line options.

    Workaround:

    Until I find a better workaround, a successful kluge has been to copy the AndroidManifest.xml and res folder from the Android project.

  • Jeff Axelrod
    Jeff Axelrod over 12 years
    Thanks, but I need a command-line option for the reasons given in the background section of my question.
  • Jeff Axelrod
    Jeff Axelrod over 12 years
    Infinitest's documentation doesn't indicate support for Maven. I have been playing with sbt, and did successfully build my Android application with it, but haven't yet adopted it into my normal development. I am pretty sure that sbt supports some type of automated test running after a build, which I think would replace infinitest.
  • Jeff Axelrod
    Jeff Axelrod over 12 years
    Yes, that's how I did the build.
  • Ryan Stewart
    Ryan Stewart over 12 years
    Bad idea. Anything I've ever seen about doing this says "don't". It's unreliable at best. Unless of course that's changed in Android, too. But this is just a test suite, right? Not running inside Android?
  • Ryan Stewart
    Ryan Stewart over 12 years
    Yeah, I saw. What I'm saying is that you can't do it with JVM args.
  • a_horse_with_no_name
    a_horse_with_no_name over 12 years
    I am using this approach on a regular basis and it works quite well.
  • Jeff Axelrod
    Jeff Axelrod over 12 years
    Infinitest doesn't allow you to call a shell script, only to change the flags.
  • Jeff Axelrod
    Jeff Axelrod over 12 years
    Modifying this variable is not recommended and is unreliable per this response. It didn't work for me.