0

I have a custom Java runtime image for Windows called java.exe and I can simply execute java -jar HelloWorld.jar to run my HelloWorld application. Using Inno Setup, I want to create an installer for my HelloWorld application. I can create an installer for java.exe, but obviously it would just run my custom Java image, whereas what I want is to run java -jar HelloWorld.jar.

Does anyone know how this can be achieved? Inno Setup does not seem to support application parameters.

I found a hack, which is to create a batch file that would execute my command. The problem is that it opens an extra CMD window. I was able to overcome this using a visual basic script that calls the batch file. It works, but I wonder if there is a better way.

claude
  • 99
  • 8
  • 2
    In your "hack" you can change `java` to `javaw` and you won't get a CMD window. – Stephen C Nov 20 '22 at 06:13
  • Thanks for the suggestion for using javaw. However, as the title of the question suggests, it is about how to send parameters to a program, not about how to prevent a CMD window from opening. – claude Nov 20 '22 at 21:36
  • I also found that the [icon] section in Inno supports parameters and a flag called “run minimized”. So in fact, I could just put the “-jar HelloWorlr.jar” as a parameter. I ended up doing something else however - I created a C based executable to run (via exec) the program with parameters. Feels cleaner and more robust to user changes – claude Nov 20 '22 at 21:44
  • Is the installer supposed to run the java program during installation? Or is it supposed to be setting up the java program for the user to run after installation is complete? – StayOnTarget Nov 21 '22 at 12:18

1 Answers1

0

Based on the Inno Setup design, the way to pass parameters to the executable (Java in this case) is via the parameters configuration of the [icon] section. And using “minimized” in the Flags of the [icon] would cause the application to launch without opening any CMD windows. The only downside of using [icon] parameters is that they are visible and modifiable by right clicking on the application icon. An alternative approach is to create a .bat file, or better yet: a .exe file that calls the application with the required parameters. If using .exe, then a simple call to execv would do. There’s no need to fork.

claude
  • 99
  • 8
  • In your question you wrote about *running* your Java program in installer. I do not think your question even remotely suggests that you actually wanted your installer to create a (desktop) icon to run your program. + And using `javaw` is imo better solution than using "minimized" flag. – Martin Prikryl Nov 21 '22 at 08:01
  • See [Creating a shortcut to execute a program with command-line parameters in Inno Setup](https://stackoverflow.com/q/52907525/850848). – Martin Prikryl Nov 21 '22 at 08:02