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

查看:39
本文介绍了从 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 放入我的类路径并从那里运行它,但在尝试之后我发现类路径实际上是我的 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

为什么我需要这个?

我想给用户一个可执行文件,他可以运行它,但我的程序使用的是 *.exe.我应该将 exe 放在我的 jar 旁边并且会有 2 个文件,还是有满足我要求的解决方案?

推荐答案

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

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天全站免登陆