Linux 在 Tomcat 应用程序中的 shell 脚本/访问中设置环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10153174/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:46:52  来源:igfitidea点击:

Set environment variable in shell script/access in Tomcat Application

javalinuxtomcatenvironment-variablesubuntu-10.04

提问by Anand Soni

I want to add and environment variable which can access by my tomcat web-app. I have gone through this linkbut i want to set environment variable in root user. How to do that?

我想添加可以通过我的 tomcat web-app 访问的环境变量。我已经浏览了这个链接,但我想在 root 用户中设置环境变量。怎么做?

采纳答案by Anand Soni

got the solution...what i have done is i have put the export statements in /etc/init.d/tomcat6at top and restarted the server by command sudo /etc/init.d/tomcat6 restart. So now my web-app running in tomcat server can access that variable.

得到了解决方案...我所做的是将导出语句放在 /etc/init.d/tomcat6顶部并通过命令重新启动服务器sudo /etc/init.d/tomcat6 restart。所以现在我在 tomcat 服务器中运行的 web 应用程序可以访问该变量。

回答by Raveesh Sharma

Doesnt this work?

这行不通?

Go to your environment file. sudo vi /etc/environment and Add the required variable. and save the file.

转到您的环境文件。sudo vi /etc/environment 并添加所需的变量。并保存文件。

I think in the recent Ubuntu, You would have to restart your system for the changes to take effect.

我认为在最近的 Ubuntu 中,您必须重新启动系统才能使更改生效。

回答by gsaslis

According to the docs (http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt) you should set all env vars in $CATALINA_HOME/bin/setenv.sh

根据文档(http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt),您应该在 $CATALINA_HOME/bin/setenv.sh 中设置所有环境变量

EDIT: For completeness, I guess it's worth mentioning that even though this is the recommended way, the docs above state that:

编辑:为了完整性,我想值得一提的是,尽管这是推荐的方式,但上面的文档指出:

By default the setenv script file is absent. If the script file is present both in CATALINA_BASE and in CATALINA_HOME, the one in CATALINA_BASE is preferred.

默认情况下不存在 setenv 脚本文件。如果脚本文件同时存在于 CATALINA_BASE 和 CATALINA_HOME 中,则首选 CATALINA_BASE 中的一个。

In case it is absent, you might also want to look for env vars in:

如果它不存在,您可能还想在以下位置查找环境变量:

  • /etc/tomcat/tomcat[67].conf(suse) or
  • /etc/default/tomcat[67].conf(e.g. ubuntu) or
  • /etc/sysconfig/tomcat[67].conf(rhel, fedora)
  • /etc/tomcat/tomcat[67].conf(使用)或
  • /etc/default/tomcat[67].conf(例如 ubuntu)或
  • /etc/sysconfig/tomcat[67].conf(rhel, 软呢帽)