设置自己的环境变量查找

发布于 2024-12-17 21:18:15 字数 244 浏览 4 评论 0原文

我有独立的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2024-12-24 21:18:15

如果您正在寻找基于 JVM 范围的简单字符串的键/值配置存储,那么系统属性通常很合适:http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

在代码中您可以使用的任何位置:

String configThingValue = System.getProperty("config-thing");

System.setProperty("config-thing", "config thing value");

另外, 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:

String configThingValue = System.getProperty("config-thing");

System.setProperty("config-thing", "config thing value");

Also, System.getProperties() provides a map like set of properties (it extends Hashtable).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文