获取“user.dir”来自命令行的 java 进程的系统属性
我正在尝试从特定 java 进程的命令行读取系统属性“user.dir”。我见过几个从 Java 代码 (System.getProperty) 获取系统属性的示例,但是我需要为另一个 java 进程设置系统属性。
我怎样才能获得相同的东西?
I am trying to read the system property "user.dir" from the command line for a particular java process. I have seen several examples of obtaining the system property from Java code (System.getProperty), however I need the system property set for another java process.
How can I obtain the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅以下链接及其摘录:
http://docs.oracle.com/ javase/tutorial/essential/environment/sysprop.html
setProperties 方法更改当前正在运行的应用程序的系统属性集。这些更改不是持久的。也就是说,更改应用程序内的系统属性不会影响该应用程序或任何其他应用程序的 Java 解释器的未来调用。运行时系统每次启动时都会重新初始化系统属性。 如果要持久保存对系统属性的更改,则应用程序必须在退出之前将值写入某个文件,并在启动时再次读取它们。
See below link with below excerpt:
http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
The setProperties method changes the set of system properties for the current running application. These changes are not persistent. That is, changing the system properties within an application will not affect future invocations of the Java interpreter for this or any other application. The runtime system re-initializes the system properties each time its starts up. If changes to system properties are to be persistent, then the application must write the values to some file before exiting and read them in again upon startup.
要获取系统属性,您可以使用
System.getProperty()
要设置系统属性,您可以使用
System.setProperty()
To get system property you can use
System.getProperty()
To set System property you can use
System.setProperty()