是否有 JVM 命令行选项可以更改目录?
简而言之,我想知道,是否有 JVM 命令行选项可以更改起始工作目录?如果重要的话,我正在运行jdk1.6.0_24。
背景:
我正在使用名为 Robolectric for Eclipse 的工具在主机 PC 上测试 Android 应用程序,而无需进行模拟。 Robolectric 需要创建一个测试项目,但测试本身要从被测 Android 项目运行。这是通过在 Eclipse 中将运行配置设置为“运行所选项目、包或源文件夹中的所有测试”设置中的测试项目来完成的。
如果可能的话,我想从 JVM 命令行选项执行此操作,因为我使用另一个工具 Infinitest, < a href="https://github.com/infinitest/infinitest/issues/39" rel="nofollow">不允许您指定测试的工作目录。但是,它确实允许您指定 JVM 命令行选项。
解决方法:
在我找到更好的解决方法之前,成功的方法是从 Android 项目中复制 AndroidManifest.xml 和 res 文件夹。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Java SE 中,“当前目录”被放入系统属性
user.dir
中。使用 -D 选项手动覆盖此值可能会起作用:
但我不知道这是否也适用于 Android 中使用的 JVM
In Java SE, the "current directory" is put into the system property
user.dir
.Manually override this value using a -D option might work:
But I don't know if this also applies to the JVM used in Android
“当前工作目录”是一个操作系统概念,而不是 JVM 概念,因此您需要在该级别找到解决方案,例如编写批处理或 shell 脚本。
"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.
我会考虑在 Maven 构建中运行 robolectric 测试。这使得运行测试变得更加容易。在 Eclipse 中也是如此。而且对 Maven 的支持也可能是无限的。
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.