运行.exe中打包的.exe文件 [英] Run .exe packaged in .jar
问题描述
我正在尝试将我制作的2个程序合并到一个.jar文件中。一个程序是用java编写的.jar,第二个是用c ++编写的.exe。我将这两个文件放到新的.jar中,编写了这段代码,但它没有用。当此代码导出到.jar并且没有执行2个文件时,我在cmd中收到错误没有主要清单属性,在merged.jar中。虽然它在eclipse中运行时效果很好。
I am trying to merge 2 programs I have made to one .jar file. One program is a .jar written in java and the second one is an .exe written in c++. I put both files to the new .jar, wrote this code but it didn't work. When this code was exported to .jar and executed neither of 2 files ran and I got error "no main manifest attribute, in merged.jar" in cmd. Though it worked perfectly when run in eclipse.
public class main
{
public static void main(String[] args)
{
try
{
Runtime.getRuntime().exec("cmd /c project1.jar");
Runtime.getRuntime().exec("cmd /c project2.exe");
}
catch(Exception exce)
{
/*handle exception*/
}
}
}
任何想法如何解决这个问题还是有其他办法吗?我是java的新手,所以想不出什么好的。也许有可能将这些文件放到Windows中的临时位置并在执行后将其删除?
Any idea how to fix this or is there another way to do it? I am new to java, so can't think of anything good. Maybe it would be possible to drop these files to a temporary location in windows and delete them after they're executed?
推荐答案
你可以试试这个:
String filePath = "C:/Path/to/my/file.exe";
try {
Process p = Runtime.getRuntime().exec(filePath);
} catch (Exception e) {
e.printStackTrace();
}
这篇关于运行.exe中打包的.exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!