Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to java vm from NSIS script

I'm developing my first java application using Eclipse. I've recently needed to adjust the amount of memory allocated by passing -Xmx256M to the JVM. The application is currently package up as a runnable jar and installed using the NSIS.

I'm having a problem passing arguments to the jar file once its installed. What is the common practice for doing this? Here is what I'm currently doing in my nsi file:

CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" "$SYSDIR\javaw.exe" "-Xmx256M -jar $INSTDIR\Foo.jar"

This results in the following being created as the shortcut Target on windows:

C:\WINDOWS\system32\javaw.exe -Xmx256M -jar  C:\Program Files\Foo\Foo.jar 

Unfortunately this does not work due to the space in C:\Program Files, If I change the link created manually to include quotes all is well:

C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\Program Files\Foo\Foo.jar"

UPDATE: Ordering of -jar and -Xmx256M swapped. The issue remains the same however. The spaces in the path to the jar file are causing an issue. I think I either need to find a way of adding quotes into the command, as shown when I manually change the target, or change my approach completely!

like image 242
CodeBuddy Avatar asked Apr 01 '10 19:04

CodeBuddy


1 Answers

NSIS strings can be quoted with single quotes, double quotes, or the backward single quote. You can also escape with $\ ($\" etc)

CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" '"$SYSDIR\javaw.exe"' '-Xmx256M -jar "$INSTDIR\Foo.jar"'
like image 81
Anders Avatar answered Sep 27 '22 21:09

Anders