5

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!

CodeBuddy
  • 5,749
  • 1
  • 25
  • 30

3 Answers3

4

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"'
Anders
  • 97,548
  • 12
  • 110
  • 164
2

Have you tried keeping the quotes in but escaping the path separators?

C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\\Program Files\\Foo\\Foo.jar"
Bernie Perez
  • 12,513
  • 13
  • 46
  • 55
1

Pretty sure you should put quotes around "C:\WINDOWS\system32\javaw.exe" even though there are no spaces.

AaronLS
  • 37,329
  • 20
  • 143
  • 202