简体   繁体   English

包括一个jar文件

[英]including an exe file to jar

I have written a java program that is actually works as a gui to an existing command line program. 我写了一个Java程序,它实际上是现有命令行程序的gui。 so in basic all my program does is Runtime.getRuntime().exec("myprogram parameter"); 因此,基本上我的程序所做的只是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. 因此,我已经使用Eclipse IDE将java源文件导出为可执行jar文件,并且效果很好,但是我确实需要将此myprogram.exe包含在生成的jar文件的目录中才能正常工作。

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. 现在,我正在寻找一种在jar文件中包含myprogram.exe的方法,以便可以将其捆绑为一个文件,因此首选使用Eclipse的方法。

You can simply jar it up as an extra resource (like a .css , .properties etc.). 您可以简单地将其添加为额外的资源(例如.css.properties等)。

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). 当Java程序运行时,请使用Class.getResourceAsStream()提取.exe并将其写入一个临时目录,以便从那里运行它(因为您不能直接从.jar文件运行它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM