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()
基础教程推荐
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Maven:无效的目标版本:10 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- JPA惰性列表上的流 2022-01-01
