从JAR内部运行* .exe文件 [英] Run *.exe file from inside JAR

查看:153
本文介绍了从JAR内部运行* .exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的JAR文件,我用 Maven Shade 插件创建。

I have a huge JAR file, which I created with Maven Shade plugin.

我运行这个 java -jar foo.jar ,我的用户界面就会打开。现在我想执行 * .exe 文件,该文件也在该JAR文件中,我该怎么做?

I run this with java -jar foo.jar , and my UI opens. Now I want to execute *.exe file, which is also in that JAR file, how can I do this?

我尝试将exe放到我的类路径并从那里运行它,但在尝试后我发现classpath实际上是我的JAR所在的位置。

I tried putting the exe to my classpath and run it from there, but after trying I found out that classpath is actually the location, where my JAR is.

有什么建议吗?

在这里找到这个东西,但这真的是最好的解决方案吗?看起来很多工作,我想我在这里有不同的情况,因为我可以自己定义exe的位置,JAR是由我创建的。

Found this thing here, but is this really the best solution? Seems like alot of work, I think I have different case here, because I can define the location of exe myself and the JAR is created by me.

包装在jar内的运行执行文件

为什么我需要这个?

我想给用户一个可执行的文件,但是我的程序正在使用*。可执行程序。我应该把exe放在我的jar旁边,并且会有2个文件或者有我的要求的解决方案吗?

推荐答案

将文件复制到临时位置并运行它是可行的方法。您链接到的答案会做更多必要的工作,因为您可以将您的exe文件作为InputStream并将其复制到具有Apache Commons IO FileUtils.copy(in,out)等实用程序的文件中/ code>

Copying the file to a temporary location and running it is the way to go. The answer you linked to does much more work that necessary, as you can get your exe file as an InputStream and copy it to a file with a utility like Apache Commons IO FileUtils.copy(in, out)

参见如何将jar中的文本文件复制到jar外的文件中?例如。

这篇关于从JAR内部运行* .exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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