TOMCAT_OPTS, environment variable and System.getEnv()(TOMCAT_OPTS、环境变量和 System.getEnv())
问题描述
我使用tomcat,我想在我的java代码中获取一个环境变量.
I use tomcat and I want to get an environment variable in my java code.
要设置环境变量,我使用这个 bash 命令:
To set an environment variable, I use this bash command :
export TOMCAT_OPTS=-Dmy.var=foo
之后我启动tomcat
After it I start tomcat
./startup.sh (in bin folder of tomcat)
在我的 java 代码中,我尝试获取这个变量:
In my java code, I try to get this variable :
System.getEnv("my.var")
但它返回 NULL.
我该怎么做?
我准确地说,如果我使用 maven 启动 tomcat 并使用 eclipse 环境选项卡,则找到变量!但是我需要像上面那样在生产模式下启动tomcat.
I precise that if I use maven to launch tomcat and use eclipse environment tab, the variable is found ! But I need to launch tomcat like above in production mode.
直接使用 export MY_VAR 时,它在本地运行,但不在我的服务器上...
when using export MY_VAR directly it runs in local but not on my server...
推荐答案
终于在CATALINA_HOME中找到了一个名为tomcat6.conf的配置文件.我将 export my.var=foo 添加到文件末尾, System.getenv("my.var") 现在返回值...
I finally found a config file named tomcat6.conf in CATALINA_HOME. I add export my.var=foo to the end of file and System.getenv("my.var") now returns the value...
噩梦……
这篇关于TOMCAT_OPTS、环境变量和 System.getEnv()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TOMCAT_OPTS、环境变量和 System.getEnv()
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01