views:

202

answers:

1

Hello, I have written a java program that is actually works as a gui to an existing command line program. so in basic all my program does is Runtime.getRuntime().exec("myprogram parameter");. So I have exported my java source as a executable-jar file by using Eclipse IDE and it is working nice, however I indeed need to include this myprogram.exe to the directory of the generated jar file inorder to work.

Now I am looking for a way to include myprogram.exe inside the jar file so I can keep it bundled as a single file, a method using using Eclipse would be preferred.

+3  A: 

You can simply jar it up as an extra resource (like a .css, .properties etc.).

When your Java program runs, extract the .exe using Class.getResourceAsStream() and write it to a temporary directory in order to run it from there (since you can't run it directly from the .jar file).

Brian Agnew
thanks alot for the answer, I have put my .exe file to the Eclipse resource dir for my project, where .classpath, .project, /bin and /src exists. The exe appears at the package editor.Now when I right click my project -> export -> runnable jar it seems my jar file doesn't include this .exe file (as exe is 5 mb and generated jar is only 10 kb)
Hellnar
Eclipse jar export (IIRC) only includes class resources. You might be able to fix it by putting the exe in your src dir; Eclipse will copy it during build to bin, and it should appear in the jar.However, I suggest you evaluate using Ant for your builds, as it enables more flexibility than Eclipse's build system, it's more easily automatable and it lets your software be built without using Eclipse.
alex
I would definitely second the comment re. Ant
Brian Agnew