简体   繁体   English

带有java参数的NSIS快捷方式

[英]NSIS shortcut with java parameters

I am building a Java app that need parameters.我正在构建一个需要参数的 Java 应用程序。 The thing is that i prepared a folder with everything i need inside to run my jar.问题是我准备了一个文件夹,里面包含运行我的 jar 所需的一切。 i have a javafx folder and a JRE folder to make my app standalone/non-JRE-system-dependent.我有一个 javafx 文件夹和一个 JRE 文件夹,使我的应用程序独立/非 JRE 系统依赖。 this the the structure of my NSIS folder:这是我的 NSIS 文件夹的结构:

root folder
 |
 |_uninstaller.exe
 |
 |_subFolder
   |
   |_JREfolder
   |  |
   |  |_JRElibs
   |
   |_JFXfolder
   |  |
   |  |_JFXlibs
   |
   |_OtherResourcesFolders
   |_MainClass.jar 
   |_otherJars.jar

the thing is to launch my jar in my computer, i need to use the following sentence on a cmd:事情是在我的电脑中启动我的 jar,我需要在 cmd 上使用以下句子:

"C:\Program Files\Java\jdk-13\bin\java.exe" --module-path "C:\Program Files\Java\javafx13\lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web,javafx.base --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED -jar clienteCorreoDefinitivo.jar

so, when i made the NSIS shortcut, i tried the following sentence, but it doesnt work:所以,当我制作 NSIS 快捷方式时,我尝试了以下句子,但它不起作用:

createShortCut "$DESKTOP\ClienteCorreoStephane.lnk" "$INSTDIR\files\java-runtime\bin\java.exe --module-path $INSTDIR\files\javafx13\lib --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web,javafx.base --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED -jar $INSTDIR\files\clienteCorreoDefinitivo.jar" "" "$INSTDIR\files\recursos\myicon.ico"

Any suggestion or help on how to launch this jar with those parameters would be awsome.关于如何使用这些参数启动这个 jar 的任何建议或帮助都会很棒。

This is what you need:这是你需要的:

CreateShortCut \
  `$DESKTOP\ClienteCorreoStephane.lnk` \
  `$INSTDIR\files\java-runtime\bin\java.exe` \
  `--module-path "$INSTDIR\files\javafx13\lib" --add-modules javafx.controls,javafx.fxml,javafx.graphics,javafx.web,javafx.base --add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED -jar "$INSTDIR\files\clienteCorreoDefinitivo.jar"` \
  `$INSTDIR\files\recursos\myicon.ico`

(It is not necessary to split it to multiple lines using \\ but increases readability.) (没有必要使用\\将其拆分为多行,但会增加可读性。)

Explanation:解释:

The syntax for CreateShortCut is CreateShortCut link.lnk target.file parameters icon.file (there are more parameters, but these are the ones you need) CreateShortCut语法CreateShortCut link.lnk target.file parameters icon.file (还有更多参数,但这些是你需要的)

Now, the target file is just Java itself, so that one is set to $INSTDIR\\files\\java-runtime\\bin\\java.exe .现在,目标文件只是 Java 本身,因此将其设置为$INSTDIR\\files\\java-runtime\\bin\\java.exe The rest of the string are actually the parameters passed to Java, so they go into the 3rd parameter.字符串的其余部分实际上是传递给 Java 的参数,因此它们进入了第三个参数。

Note that I also modified the quotes a bit:请注意,我还稍微修改了引号:

This is because your $INSTDIR may very well be C:\\Program Files which contains a space.这是因为您的$INSTDIR很可能是包含空格的C:\\Program Files In this case, it would break because it would become --module-path C:\\Program Files\\thing\\files\\javafx13\\lib ... and Java would read C:\\Program as value for the module path!在这种情况下,它会中断,因为它会变成--module-path C:\\Program Files\\thing\\files\\javafx13\\lib ...并且 Java 会读取C:\\Program作为模块路径的值! For this reason there have to be " doublequotes " around those paths.出于这个原因,这些路径周围必须有"双引号"

However, this would clash with the quotes originally used for the whole "parameters" argument to NSIS, which is why I encapsulated that one in ` backticks ` instead of " doublequotes " .但是,这会与 NSIS 的整个“参数”参数最初使用的引号发生冲突,这就是为什么我将其封装在`反引号`而不是"双引号" (For consistency, I used backticks for all the NSIS arguments then.) (为了保持一致性,我当时对所有 NSIS 参数都使用了反引号。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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