1

For my Spring boot application, I have a .conf file that is used to run the application. In this file, I put some jvm options. Currently it contains this :

JAVA_OPTS="-Xms256m -Xmx512m -Dvisualvm.display.name=ApplicationWs -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

In the future I will certainly add other options and the line will increase in size. I want to make it more readable by writing one or two options by line. But I don't find the proper syntax for this.

I want to do something like this :

# Heap Size
JAVA_OPTS="-Xms256m -Xmx512m"

# JVisualVM Name in VisualVM
JAVA_OPTS="$JAVA_OPTS -Dvisualvm.display.name=ApplicationWs"

# Jmx Configuration
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=3333 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

I already tried :

JAVA_OPTS="-Xms256m -Xmx512m"
JAVA_OPTS="$JAVA_OPTS -Dvisualvm.display.name=ApplicationWs"
export JAVA_OPTS

JAVA_OPTS="-Xms256m -Xmx512m"
JAVA_OPTS="${JAVA_OPTS} -Dvisualvm.display.name=ApplicationWs"
export JAVA_OPTS

JAVA_OPTS="-Xms256m -Xmx512m 
-Dvisualvm.display.name=ApplicationWs"

JAVA_OPTS="-Xms256m -Xmx512m "
+ " -Dvisualvm.display.name=ApplicationWs"

What is the proper syntax for a multi-line string in a spring-boot .conf file ?

YLombardi
  • 1,755
  • 5
  • 24
  • 45

3 Answers3

5

Spring boot launch script will use the shell to source the .conf file, so you can put any shell script syntax to write the configuration. I would prefer to use vars to format them in your case such as the following:

MEM_OPTS='-Xms256m -Xmx512m'
DISPLAY_NAME='visualvm.display.name=ApplicationWs'
JMXREMOTE_PORT='com.sun.management.jmxremote.port=3333'
JMXREMOTE_SSL='com.sun.management.jmxremote.ssl=false'
JMXREMOTE_AUTH='com.sun.management.jmxremote.authenticate=false'

JAVA_OPTS="${MEM_OPTS} -D${DISPLAY_NAME} -D${JMXREMOTE_PORT} -D${JMXREMOTE_SSL} -D${JMXREMOTE_AUTH}"

see here

rizjoj
  • 197
  • 2
  • 9
allen
  • 356
  • 5
  • 8
  • Thanks, this works perfectly. Today I have a lot of parameters and this is more readable if I write them like you did. – YLombardi Feb 17 '17 at 14:25
1

Try multiple line like this:

primes = 2,\
    3,\
    5,\
    7,\
    11

from: https://stackoverflow.com/a/8978515/404145

Community
  • 1
  • 1
DiveInto
  • 2,158
  • 3
  • 27
  • 50
  • I try this in my configuration file and it works. Thanks. JAVA_OPTS="-Xms256m \ -Xmx512m \ -Dvisualvm.display.name=ApplicationWs \ -Dcom.sun.management.jmxremote.port=3335 \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false" – YLombardi Aug 23 '16 at 12:31
0

Only way that actually works is to pass one line command, note semicolons and backslashes in the end:

MEMORY_PARAMS=' -Xms512M -Xmx512M '; \
JMX_MONITORING='-Dcom.sun.management.jmxremote.port=8890 -Dcom.sun.management.jmxremote.rmi.port=8890 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=13.55.666.7777'; \
REMOTE_DEBUG='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8889'; \
JAVA_OPTS=" -Dfile.encoding=UTF-8 ${MEMORY_PARAMS} ${REMOTE_DEBUG} ${JMX_MONITORING} "