Skip to content
Advertisement

How to pass parameters to a packaged java application (.exe)

I need to package a Java program so it’s an exe that runs without depending on an installed Java. (from what I read Launch4J or jpackage can do the job)
And I need to pass parameters to this program program via the commandline.
Finally I need results generated by the Java program back in the calling application.

How do I do that?

Does a Java sitting in an exe have access to command line parameters?

I could do the data exchange via a file, eg sitting in the temp folder.
But I’d prefer not to use a fix-coded filename as it might happen that 2 threads call the Java at the same time…

Thanks for your thoughts!

Advertisement

Answer

An EXE generated by jpackage behaves in same manner as your original application except that all the Java / JVM path and options are unchangable, so the built in JVM is launching your class. All command line arguments are passed on.

It does not accept say new system property -Dprop=value but will let you pass all arguments you add to the command line to the main(String[]args) of your launch class such as:

yourapp.exe arg1 arg2

Don’t use jpackage --arguments unless you want the arguments hardwired into the exe as well. See Packaging Tool User’s Guide

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement