Including exe file in the jar

I wrote a java program that actually works as a gui for an existing command line program. so in the base program, all my programs are Runtime.getRuntime().exec("myprogram parameter");

. So I exported my java source as executable jar using Eclipse IDE and it works well, however I really need to include this myprogram.exe in the generated jar file directory for it to work.

I am now looking for a way to include myprogram.exe in a jar file so that I can save it as a single file, the preferred method would be using Eclipse.

+2


source to share


1 answer


You can simply add it as an additional resource (eg, .css

, .properties

etc.).



When your Java program starts, extract .exe

with Class.getResourceAsStream()

and write it to a temporary directory to run it from there (since you cannot run it directly from a file .jar

).

+8


source







All Articles