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

只谈情不闲聊 提交于 2019-12-11 05:24:51

问题


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.


回答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.




回答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




回答3:


I would look into running the robolectric tests within a Maven build. That makes it way easier to run the tests. Within Eclipse as well. And there is probably infinitest support for Maven as well.



来源:https://stackoverflow.com/questions/7838750/is-there-a-jvm-command-line-option-to-change-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!