Read Java VM argument from file

Hey, I’m trying to make the maximum heap size customisable by editing a “memory.txt” file which contains the following:

Xmx128m

I don’t want users having to go into my bat/sh scripts in order to change the maximum memory. I’m also using an auto update system, so they can’t edit the scripts (they will get overwritten on the next update)

I execute the jar file using a bat or shell script as below.

My Windows bat file version works fine:


set /p HEAPSIZE=<memory.txt
java -%HEAPSIZE% -jar memorytest.jar

However my linux version fails (I run using sh)


HEAPSIZE= cat 'memory.txt'
java -$HEAPSIZE -jar memorytest.jar

This works though: ???


HEAPSIZE= "Xmx128m"
java -$HEAPSIZE -jar memorytest.jar

Can anyone help me get this working for linux/mac?
thanks :slight_smile:


-    HEAPSIZE= cat 'memory.txt'
+    HEAPSIZE=`cat memory.txt`
     java -$HEAPSIZE -jar memorytest.jar

note the backticks and their location

Thanks! :slight_smile: