server.xml 中的环境/系统变量

编程入门 行业动态 更新时间:2024-10-26 15:26:25
本文介绍了server.xml 中的环境/系统变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在tomcat server.xml、context.xml等配置文件中使用环境/系统变量?

How can I use environment/system variables in tomcat server.xml, context.xml, etc configuration files?

我尝试使用 ${ENV_VAR_NAME}(用于环境和系统变量)、${env.ENV_VAR_NAME}(用于环境变量).似乎没有任何效果.

I tried to use ${ENV_VAR_NAME} (both for environment and system variable), ${env.ENV_VAR_NAME} (for environment variables). And nothing seems to work.

推荐答案

在我的盒子里是如何实现的.

How it's realized in my box.

用于启动的 Bash 脚本:

Bash-script for startup:

#!/bin/sh

SMEMORY=1G
XMEMORY=1G

if [ $ENV == DEV ]; then
  port_shutdown="8005"
  port_http="8080"
  port_https="8443"
elif
  [ $ENV == SIT ]; then
  port_shutdown="8006"
  port_http="8081"
  port_https="8444"
elif
  [ $ENV == UAT ]; then
  port_shutdown="8007"
  port_http="8082"
  port_https="8445"
else
  echo "Unknown ENV"
  exit 1
fi

export CATALINA_OPTS=" ${SYSTEM_PROPS} -d64 -server -Xms$SMEMORY -Xmx$XMEMORY 
 -XX:+UseCodeCacheFlushing -XX:ReservedCodeCacheSize=64M 
 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxPermSize=1024M 
 -Dport.http=${port_http} -Dport.https=${port_https} -Dport.shutdown=${port_shutdown}"

exec $CATALINA_HOME/bin/startup.sh

server.xml中:

<Connector
  port="${port.http}"
  protocol="HTTP/1.1"
  connectionTimeout="20000"
  redirectPort="${port.https}"
/>

看一下流程:

$ ps ux | grep tomcat
... -Xms1G -Xmx1G ... -Denv=KIEV_DEV... -Dport.http=8084 -Dport.https=8446 -Dport.shutdown=8008...

检查端口:

$ netstat -anp | grep java
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 :::8084                     :::*                        LISTEN      23343/java
tcp        0      0 :::8446                     :::*                        LISTEN      23343/java

这篇关于server.xml 中的环境/系统变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-19 12:07:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/645327.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   环境   系统   server   xml

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!