包括一个 exe 文件到 jar [英] including an exe file to jar

查看:32
本文介绍了包括一个 exe 文件到 jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 java 程序,它实际上可以作为现有命令行程序的 gui.所以基本上我的程序所做的就是Runtime.getRuntime().exec("myprogram parameter");.所以我已经使用 Eclipse IDE 将我的 java 源文件导出为一个可执行的 jar 文件并且它运行良好,但是我确实需要将此 myprogram.exe 包含到生成的 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.

现在我正在寻找一种将 myprogram.exe 包含在 jar 文件中的方法,以便我可以将它捆绑为单个文件,最好使用使用 Eclipse 的方法.

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.

推荐答案

你可以简单地把它作为一个额外的资源(比如一个 .css.properties 等).).

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

当您的 Java 程序运行时,使用 Class.getResourceAsStream() 提取 .exe 并将其写入临时目录,以便从那里运行它(因为您不能直接从 .jar 文件运行.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆