I am running a Java application from the command line. Can I specify a command line argument to set the current running directory to something other than where the application is actually going to run?
问问题
34270 次
4 回答
42
有一个 JVM 参数-Duser.dir
可用于设置 JVM 的工作目录。
于 2012-03-02T07:53:07.143 回答
5
如果可能的话,我宁愿使用脚本来运行 java 应用程序并在脚本中设置目录:
#!/bin/sh
cd <your dir>
java <some arguments>
JNI 解决方案可能会影响应用程序中的各种相对路径;例如你输入的类路径。
于 2010-12-15T08:55:10.353 回答
0
如果要更改当前目录,则必须使用 JNI 并从 Java 代码调用本机 API。例如,对于 Windows,您将使用SetCurrentDirectory
于 2010-12-14T18:34:36.897 回答