16

我正在尝试setenv.sh在 Ubuntu 12/Tomcat 7 上设置我的。Tomcat 已经安装了 apt-get 我试图创建一个多行JAVA_OPTS变量,但一直遇到错误消息。

#!/bin/sh
export JAVA_OPTS="$JAVA_OPTS -server \
-Xms512m -Xmx512m"

: not foundtomcat7/bin/catalina.sh: 4: /usr/share/tomcat7/bin/setenv.sh: 
Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME:        /usr/lib/jvm/java-7-oracle/
Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Error: Could not find or load main class

#!/bin/sh
export JAVA_OPTS="$JAVA_OPTS -server -Xms512m -Xmx512m"

: not foundtomcat7/bin/catalina.sh: 3: /usr/share/tomcat7/bin/setenv.sh: 
Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME:        /usr/lib/jvm/java-7-oracle/
Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
Invalid maximum heap size: -Xmx512m
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

我已将其更新为此,但在回声位置仅显示最后一行。

#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -server -Xms704m -Xmx704m"
JAVA_OPTS="$JAVA_OPTS -XX:OnOutOfMemoryError=/usr/share/scripts/on_server_crash.sh"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/tomcat7"
JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=128m -XX:MaxNewSize=256m -XX:NewSize=256m"
echo $JAVA_OPTS
JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=12 -XX:MaxTenuringThreshold=0"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSPermGenSweepingEnabled -XX:+DisableExplicitGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC -XX:+UseTLAB"
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -javaagent:$NR_JAR -Dnewrelic.environment=production"
echo $JAVA_OPTS
export JAVA_OPTS

当我在没有导出选项的情况下尝试“每个命令在自己的行上”时,我得到“无法识别的选项 -server

#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -server"
JAVA_OPTS="$JAVA_OPTS -Xms704m"
JAVA_OPTS="$JAVA_OPTS -Xmx704m"
JAVA_OPTS="$JAVA_OPTS -XX:OnOutOfMemoryError=/usr/share/scripts/on_server_crash.sh"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=/var/log/tomcat7"
JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=128m"
JAVA_OPTS="$JAVA_OPTS -XX:MaxNewSize=256m"
JAVA_OPTS="$JAVA_OPTS -XX:NewSize=256m"
JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=12"
JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=0"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSIncrementalMode"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSIncrementalPacing"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSClassUnloadingEnabled"
JAVA_OPTS="$JAVA_OPTS -XX:+CMSPermGenSweepingEnabled"
JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseTLAB"
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -javaagent:$NR_JAR"
JAVA_OPTS="$JAVA_OPTS -Dnewrelic.environment=production"
echo JAVA_OPTS
4

3 回答 3

25

嗯,删除整个文件并重新创建它,现在它可以工作了.....现在使用这种风格

export JAVA_OPTS="$JAVA_OPTS\
 -server\
 -Xms704m\
 -Xmx704m\
 -XX:OnOutOfMemoryError=/usr/share/scripts/on_server_crash.sh\
 -XX:+HeapDumpOnOutOfMemoryError\
 -XX:HeapDumpPath=/var/log/tomcat7\
 -XX:MaxPermSize=128m\
 -XX:MaxNewSize=256m\
 -XX:NewSize=256m\
 -XX:SurvivorRatio=12\
 -XX:MaxTenuringThreshold=0\
 -XX:+UseConcMarkSweepGC\
 -XX:+CMSIncrementalMode\
 -XX:+CMSIncrementalPacing\
 -XX:+CMSClassUnloadingEnabled\
 -XX:+CMSPermGenSweepingEnabled\
 -XX:+DisableExplicitGC\
 -XX:+UseParNewGC\
 -XX:+UseTLAB\
 -Djava.awt.headless=true\
 -javaagent:$NR_JAR\
 -Dnewrelic. environment=production"
于 2013-02-18T11:20:24.143 回答
10

你会更好:

JAVA_OPTS="$JAVA_OPTS -server "
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m"
export JAVA_OPTS
于 2013-02-17T21:35:05.507 回答
3

使用类似于 Marc 的东西结束,但在属性定义中使用空格转义

export JAVA_OPTS="$JAVA_OPTS \
-DFOO=\"bar bar\" \
-DBAZ=\"bar2 bar2\" "
于 2014-07-31T22:30:12.810 回答