包括一个exe文件到jar [英] including an exe file to jar
问题描述
所以在基本的所有我的程序是
Runtime.getRuntime()。exec(myprogram参数);
。所以我已经通过使用Eclipse IDE导出了我的java源代码作为可执行文件jar文件,并且它工作不错,但是我确实需要将这个myprogram.exe包含在生成的jar文件的目录中才能正常工作。 现在我正在寻找一种方法来将myprogram.exe包含在jar文件中,这样我就可以把它捆绑成一个单一的文件,使用Eclipse的方法是首选的。
您可以简单地将其添加为额外的资源(如 .css
.properties
等)。
当您的Java程序运行时,解压缩 .exe
使用 Class.getResourceAsStream()
并将其写入临时目录,以便从那里运行它(因为您无法直接从 .jar
文件)。
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.
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).
这篇关于包括一个exe文件到jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!