如何从eclipse中的属性文件读取VM参数? [英] How to read VM arguments from property file in eclipse?

查看:163
本文介绍了如何从eclipse中的属性文件读取VM参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道,eclipse为我们提供了将VM参数传递给特定类的方法,请查看下图中的 VM参数部分:





但是我想以不同的方式传递这些参数,所以我可以把这些参数放在一个属性文件中,然后在代码中找回它们。



所以一旦我打电话给Lesson2类(像上图)任何其他类,我在运行之前传递给VM参数



任何建议?

解决方案

要将VM参数设置在一个类中并在另一个类中访问,您可以将参数设置为<$ c $在运行配置的 VM参数字段中,或使用 System.getProperties())中的c> -Dprop = propValue 。代码中的setProperty('prop','propValue')然后可以从被调用的类中的地图访问该属性。对于从命令行启动的应用程序也是可能的。

  $ java -Dprop = propValue SomeClass ... 

或应用服务器的启动参数(示例:Tomcat或JBoss)

  $ export JAVA_OPTS = -  Dprop = propValue

然后启动应用程序服务器。



最后,可以通过列出以空格分隔的 -Dprop = value 来设置多个属性。


As we know, eclipse offers us a way to pass VM parameters to a specific class, look at the VM Arguments section in the image below:

But I am looking to pass these arguments in a different way, so I can put these arguments in a property file, and then I retrieve them in the code.

So once I call the Lesson2 class (like in the image above) from any other class , I pass to it VM arguments before running

Any suggestions?

解决方案

To set the VM argument in one class and access it in another class, either you set the parameter as -Dprop=propValue in VM arguments field of the Run Configuration or by usingSystem.getProperties().setProperty('prop', 'propValue') in the code. The property can then be accessed from the map in the called class. This is also possible for applications started from command line as

$ java -Dprop=propValue SomeClass ...

or application server's start parameter (Example: Tomcat or JBoss)

$ export JAVA_OPTS="-Dprop=propValue"

and then starting the application server.

Lastly, multiple properties can be set by listing -Dprop=value separated by spaces.

这篇关于如何从eclipse中的属性文件读取VM参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆