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

时间:2022-02-23 02:06:39

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

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

3 个解决方案

#1


5  

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中设置所有env变量

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:

如果它不存在,您可能还想查找env vars:

  • /etc/tomcat/tomcat[67].conf (suse) or
  • /etc/tomcat/tomcat[67].conf(suse)或

  • /etc/default/tomcat[67].conf (e.g. ubuntu) or
  • /etc/default/tomcat[67].conf(例如ubuntu)或

  • /etc/sysconfig/tomcat[67].conf (rhel, fedora)
  • /etc/sysconfig/tomcat[67].conf(rhel, fedora)

#2


0  

got the solution...what i have done is i have put the export statements in /etc/init.d/tomcat6 at 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-app可以访问该变量。

#3


-1  

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中,您必须重新启动系统才能使更改生效。

#1


5  

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中设置所有env变量

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:

如果它不存在,您可能还想查找env vars:

  • /etc/tomcat/tomcat[67].conf (suse) or
  • /etc/tomcat/tomcat[67].conf(suse)或

  • /etc/default/tomcat[67].conf (e.g. ubuntu) or
  • /etc/default/tomcat[67].conf(例如ubuntu)或

  • /etc/sysconfig/tomcat[67].conf (rhel, fedora)
  • /etc/sysconfig/tomcat[67].conf(rhel, fedora)

#2


0  

got the solution...what i have done is i have put the export statements in /etc/init.d/tomcat6 at 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-app可以访问该变量。

#3


-1  

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中,您必须重新启动系统才能使更改生效。