TOMCAT_OPTS,环境变量和System.getEnv() [英] TOMCAT_OPTS, environment variable and System.getEnv()
问题描述
要使用tomcat,我想在我的java代码中获取一个环境变量。要设置一个环境变量,我使用这个bash命令:
export TOMCAT_OPTS = -Dmy.var = foo
之后我启动tomcat
./ startup.sh(在tomcat的bin文件夹中)
在我的java代码中,我尝试获取此变量:
System.getEnv(my.var)
但是它返回NULL。
我该怎么做?
确切地说,如果我使用maven启动tomcat并使用eclipse环境选项卡,该变量被发现!但是我需要在生产模式下启动tomcat。
编辑:直接使用导出MY_VAR时,它运行在本地但不在我的服务器上。
我终于在CATALINA_HOME中找到了一个名为tomcat6.conf的配置文件。
我将export my.var = foo添加到文件的末尾,System.getenv(my.var)现在返回值...
噩梦...
I use tomcat and I want to get an environment variable in my java code.
To set an environment variable, I use this bash command :
export TOMCAT_OPTS=-Dmy.var=foo
After it I start tomcat
./startup.sh (in bin folder of tomcat)
In my java code, I try to get this variable :
System.getEnv("my.var")
But it returns NULL.
How can I do that ?
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.
EDIT: when using export MY_VAR directly it runs in local but not on my server...
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...
Nightmare...
这篇关于TOMCAT_OPTS,环境变量和System.getEnv()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!