java 是否有用于更改目录的 JVM 命令行选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7838750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a JVM command-line option to change directory?
提问by Jeff Axelrod
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.
总之,我想知道,是否有 JVM 命令行选项来更改起始工作目录?如果这很重要,我正在运行 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."
我正在使用一个名为 Robolectric for Eclipse 的工具在没有模拟的情况下在主机 PC 上测试 Android 应用程序。Robolectric 需要创建一个测试项目,但测试本身要从被测 Android 项目中运行。这是通过从 Eclipse 中完成的,在设置中将运行配置设置为被测项目:“运行所选项目、包或源文件夹中的所有测试。”
I want to do this from the JVM command line options, if possible, because another tool I use, Infinitest, doesn't allowyou to specify the working directory of the tests. It does, however, let you specify JVM command-line options.
我想如果可能的话,从JVM命令行选项做到这一点,因为其他的工具,我使用,Infinitest,不允许你指定测试的工作目录。但是,它允许您指定 JVM 命令行选项。
Workaround:
解决方法:
Until I find a better workaround, a successful kluge has been to copy the AndroidManifest.xml and res folder from the Android project.
在我找到更好的解决方法之前,成功的方法是从 Android 项目复制 AndroidManifest.xml 和 res 文件夹。
回答by a_horse_with_no_name
In Java SE, the "current directory" is put into the system property user.dir
.
在 Java SE 中,“当前目录”被放入系统属性中user.dir
。
Manually override this value using a -D option might work:
使用 -D 选项手动覆盖此值可能有效:
java -Duser.dir=/some/directory ....
But I don't know if this also applies to the JVM used in Android
但是不知道这是否也适用于Android中使用的JVM
回答by Ryan Stewart
"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.
“当前工作目录”是一个操作系统概念,而不是 JVM 概念,因此您需要在该级别找到解决方案,例如编写批处理或 shell 脚本。
回答by Manfred Moser
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.
我会考虑在 Maven 构建中运行 robolectric 测试。这使得运行测试变得更容易。在 Eclipse 中也是如此。并且可能也有对 Maven 的无限支持。