在tomcat8的catalina.sh中,针对如何设置环境变量进行了注释说明:
# Control Script for the CATALINA Server
#
# Environment Variable Prerequisites
#
# Do not set the variables in this script. Instead put them into a script
# setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
意思是,不要在catalina.sh这个脚本中设置环境变量,这样会无法区分自定义的变量和tomcat默认变量,如果需要设置环境变量,只需要将环境变量写进一个叫做setenv.sh(Linux)/setenv.bat(windows)的脚本中,并将该脚本放在CATALINA_BASE/bin目录下即可,tomcat会自动加载该文件。
这里给出一个脚本demo:
export JAVA_OPTS="-Xms256m -Xmx512m -XX:NewRatio=4 -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9998 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"