Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spaces in JAVA_OPTS in Apache Tomcat

How can I pass a property which has spaces using JAVA_OPTS to Apache Tomcat?

For example;

-Dmy.property="How are you"

My operating system is SUSE Linux.

like image 345
user190982 Avatar asked Nov 27 '22 17:11

user190982


1 Answers

I actually figured this out using AWS Elasticbeanstalk, which lets you have spaces in the Environment Properties you can enter via the UI.

As part of the build of the server instance, the Elasticbeanstalk service replaces the /usr/bin/tomcat7 script in order to accommodate some of its requirements.

If you check this, you can see the following difference:

Default script:

if [ "$1" = "start" ]; then
    ${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \

Elasticbeanstalk script:

if [ "$1" = "start" ]; then
    eval "${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
    ...."

ie they have placed an "eval" before the command to start the JVM, and enclosed the entire command in double-quotes.

This appears to allow the JAVA_OPTS values with spaces be preserved.

like image 103
Garreth McDaid Avatar answered Jan 29 '23 04:01

Garreth McDaid