Passing arguments to java vm from NSIS script
Asked Answered
S

3

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!

Surfacetosurface answered 1/4, 2010 at 19:5 Comment(0)
S
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"'
Shae answered 2/4, 2010 at 13:54 Comment(0)
S
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"
Shavian answered 1/4, 2010 at 20:6 Comment(1)
NSIS does not escape with \, it uses $\ (And there is no need to escape \ in paths)Shae
L
1

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

Lector answered 1/4, 2010 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.