Windows batch & java: Combining -XX:OnOutOfMemoryError command and batch parameters

Viewed 890

I am completely new to Windows batch programming. What I want to achieve is to write a startup script for a Java application. Yet, it does not start the Java application, but rather prints out

Usage: java [-options] class [args...]

(to execute a class)

or java [-options] -jar jarfile [args...]

(to execute a jar file)

...

which indicates that my parameters are not correctly recognized.


Here is my MCVE for the not-working script:

set memory=600000
java -XX:OnOutOfMemoryError="taskkill /PID %p" -Xmx%memory%K -jar MyApp.jar

In the real scenario, memory is calculated to set the optimal maximal heap size for the application.


Leaving out one of both parameters makes the app start. So

java -XX:OnOutOfMemoryError="taskkill /PID %p" -jar MyApp.jar

and

set memory=600000
java -Xmx%memory%K -jar MyApp.jar

works, but I need both parameters to work in one call.

1 Answers
Related