设置自己的环境变量查找
我有独立的Java应用程序,因为我有各种模块 应用程序从一个类的 main() 方法开始,然后应用程序继续。
现在我想以键/值对的形式向各个模块共享变量,
我该怎么做?
更新:
从启动应用程序的 main() 中,我将设置一些变量。 并且从这里开始一些模块程序,
我只想要类似的功能,如 ServletContext 、 SessionContext 变量,就像在 Servlet 容器中一样
I have standalone Java application ,in that i have various modules
Application starts from one classes main() method and then application goes on.
Now i wanted share variables in form of key/value pair to various modules
How can i do it ?
Update :
From main() which kicks on application , from there i will be setting some variables.
and also from here it starts some modules programs ,
I just want similar functionality like ServletContext , SessionContext variables , just like in Servlet container
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在寻找基于 JVM 范围的简单字符串的键/值配置存储,那么系统属性通常很合适:http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
在代码中您可以使用的任何位置:
另外,
System.getProperties()
提供类似映射的属性集(它扩展了Hashtable
)。If you're looking for JVM wide simple string based key/value configuration storage then the system properties are usually a good fit: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html
Anywhere in your code you can use:
Also,
System.getProperties()
provides a map like set of properties (it extendsHashtable
).