Spaces in JAVA_OPTS in Apache Tomcat

Spaces in JAVA_OPTS in Apache Tomcat



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


JAVA_OPTS



For example;


-Dmy.property="How are you"



My operating system is SUSE Linux.





Linux or Windows?
– bmargulies
Dec 22 '10 at 20:26





just added OS to question ...its suse linux
– user190982
Dec 22 '10 at 20:33




4 Answers
4



Seems to me there is no way to use spaces in JAVA_OPTS, I have the same problem on OSX.
You can add your property directly to other -D options in the catalina.sh



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.



Let's open file $CATALINA_HOMEbincatalina.sh . You will see the guide from Apache Tomcat for variable JAVA_OPTS


$CATALINA_HOMEbincatalina.sh


JAVA_OPTS


# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.



You want set property -Dmy.property="How are you", it is not a property that JVM supported. You should put it in variable CATALINA_OPTS. If your property's value has space(s), wrap it inside " ".


-Dmy.property="How are you"


CATALINA_OPTS


" "


# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.



(Although you used Apache Tomcat 5.5, I quoted guide from Apache Tomcat 9.0.11 because it is existing in my computer)



try this


-Dmy.property="How are you"





Escaping spaces does not work
– Bastien Caudan
Sep 17 '14 at 12:34





Confirmed, this definitely does not work. It does not seem possible to escape spaces in any way.
– simon
Nov 11 '17 at 11:32



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế