Run .exe packaged in .jar

女生的网名这么多〃 提交于 2019-12-11 04:24:01

问题


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*/
      }
       }
   }

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?


回答1:


Have a look at the JAR File Specification.

You have to update your MANIFEST file to populate a "Main-Class" attribute with the class that contains you main() method.




回答2:


You can try this:

    String filePath = "C:/Path/to/my/file.exe";
    try {

        Process p = Runtime.getRuntime().exec(filePath);

    } catch (Exception e) {
        e.printStackTrace();
    }


来源:https://stackoverflow.com/questions/11134564/run-exe-packaged-in-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!