Wednesday, 21 August 2013

Passing system properties that contains spaces to Tomcat through JAVA_OPTS

Passing system properties that contains spaces to Tomcat through JAVA_OPTS

I need to pass multiple system properties to Tomcat 6 through the
JAVA_OPTS environment variable. I can't seem to pass system properties
that contain spaces:
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS="-DsysProp1=foo -DsysProp2=bar with
spaces" ./catalina.sh run
Fails with:
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.
I looked around on SO and the answers don't seem to help. Tried all of
these with no success:
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

No comments:

Post a Comment