从 NSIS 脚本将参数传递给 java vm
我正在使用 Eclipse 开发我的第一个 java 应用程序。我最近需要通过将 -Xmx256M 传递给 JVM 来调整分配的内存量。该应用程序当前打包为可运行的 jar 并使用 NSIS 安装。
安装后,我在将参数传递给 jar 文件时遇到问题。这样做的常见做法是什么?这是我当前在 nsi 文件中执行的操作:
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" "$SYSDIR\javaw.exe" "-Xmx256M -jar $INSTDIR\Foo.jar"
这会导致以下内容被创建为 Windows 上的快捷方式目标:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar C:\Program Files\Foo\Foo.jar
不幸的是,由于 C:\Program Files 中的空间,如果我更改手动创建的链接,这将不起作用包含引号一切都很好:
C:\WINDOWS\system32\javaw.exe -Xmx256M -jar "C:\Program Files\Foo\Foo.jar"
更新:-jar 和 -Xmx256M 的顺序交换。但问题仍然相同。 jar 文件路径中的空格导致了问题。我想我要么需要找到一种在命令中添加引号的方法,如我手动更改目标时所示,要么完全改变我的方法!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSIS 字符串可以用单引号、双引号或反向单引号引起来。您还可以使用 $\ ($\" 等) 进行转义
NSIS strings can be quoted with single quotes, double quotes, or the backward single quote. You can also escape with $\ ($\" etc)
您是否尝试过保留引号但转义路径分隔符?
Have you tried keeping the quotes in but escaping the path separators?
很确定你应该在“C:\WINDOWS\system32\javaw.exe”周围加上引号,即使没有空格。
Pretty sure you should put quotes around "C:\WINDOWS\system32\javaw.exe" even though there are no spaces.