我需要通过 JAVA_OPTS 环境变量将多个系统属性传递给 Tomcat 6。我似乎无法传递包含空格的系统属性:
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS="-DsysProp1=foo -DsysProp2=bar with spaces" ./catalina.sh run
失败:
Using CATALINA_BASE: /root/apache-tomcat-6.0.37
Using CATALINA_HOME: /root/apache-tomcat-6.0.37
Using CATALINA_TMPDIR: /root/apache-tomcat-6.0.37/temp
Using JRE_HOME: /root/jre1.6.0_34/
Using CLASSPATH: /root/apache-tomcat-6.0.37/bin/bootstrap.jar
Exception in thread "main" java.lang.NoClassDefFoundError: with
Caused by: java.lang.ClassNotFoundException: with
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: with. Program will exit.
我环顾四周,答案似乎没有帮助。尝试了所有这些都没有成功:
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS="-DsysProp1=foo -DsysProp2=\"bar with spaces\"" ./catalina.sh run
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS='-DsysProp1=foo -DsysProp2="bar with spaces"' ./catalina.sh run
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS='-DsysProp1=foo -DsysProp2=bar\ with\ spaces' ./catalina.sh run