简体   繁体   中英

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!

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"'

您是否尝试过保留引号但是转义路径分隔符?

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

很确定你应该在“C:\\ WINDOWS \\ system32 \\ javaw.exe”周围加上引号,即使没有空格。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM