简体   繁体   English

如何从可运行的jar文件中执行.exe

[英]How to execute .exe from within runnable jar file

I am working on a Java desktop application and want to execute an .exe file upon some user action. 我正在使用Java桌面应用程序,并且希望在执行某些用户操作时执行.exe文件。

I want to package the .exe inside the executable jar so that I have to ship just one item to my customer/user. 我想将.exe打包到可执行jar中,这样我就只需要向我的客户/用户运送一件商品。 But so far I have not been able to execute an .exe file which is packaged inside the jar. 但是到目前为止,我还无法执行打包在jar中的.exe文件。

One more input, the .exe in turn uses a bunch of .dll, .xml and .exe files (total 12 files), so I need to package all of them to make this work. 再输入一次,.exe依次使用一堆.dll,.xml和.exe文件(总共12个文件),因此我需要将所有文件打包以使其正常工作。 Is this possible in java or should I use another language to achieve this? 在Java中这可能吗,还是我应该使用另一种语言来实现?

I chose java because I want to support Mac platform also. 我选择Java是因为我也想支持Mac平台。 So with these .exe and .dll files (for Win), I need to package and execute a bunch of Unix executable files and dylib files also (for Mac). 因此,对于这些.exe和.dll文件(对于Win),我需要打包并执行一堆Unix可执行文件和dylib文件(对于Mac)。

What would be the best way to achieve this? 实现这一目标的最佳方法是什么?

I can think of 2 ways: 我可以想到两种方式:

  1. Make one Java executable app and dynamically execute exe or Unix executable file depending on platform it is running. 制作一个Java可执行应用程序,并根据运行的平台动态执行exe或Unix可执行文件。 The problem here is executing the files which are packaged within the jar. 这里的问题是执行打包在jar中的文件。
  2. Make separate applications for Win and Mac. 为Win和Mac制作单独的应用程序。 In this case, which languages should I use? 在这种情况下,我应该使用哪种语言?

Thanks much for the help! 非常感谢您的帮助!

Applications are packaged very differently on windows and mac. Windows和Mac上的应用程序打包方式非常不同。 For the Windows version I would recommend you to distribute an installation program (see IzPack for instance) that will unpack the jar and the exe in the application directory (I don't believe you can directly execute an exe that's in a jar file). 对于Windows版本,我建议您分发一个安装程序(例如,请参阅IzPack ),该程序将在应用程序目录中解压缩jar和exe(我不相信您可以直接执行jar文件中的exe)。 A MacOS application is actually a directory with a certain structure, so in your case, the said directory could contain both the jar and the exe. MacOS应用程序实际上是具有特定结构的目录,因此,在您的情况下,所述目录可以包含jar和exe。

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

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