简体   繁体   中英

NSIS shortcut with java parameters

I am building a Java app that need parameters. The thing is that i prepared a folder with everything i need inside to run my jar. i have a javafx folder and a JRE folder to make my app standalone/non-JRE-system-dependent. this the the structure of my NSIS folder:

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:

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

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.

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)

Now, the target file is just Java itself, so that one is set to $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.

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. 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! 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 " . (For consistency, I used backticks for all the NSIS arguments then.)

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