简体   繁体   中英

Run *.exe file from inside JAR

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

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?

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.

Any suggestions?

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.

run exe which is packaged inside jar

Why I need this?

I want to give user a single file executable, which he can run, but my program is using the *.exe. Should I put the exe next to my jar and there will be 2 files or there is solution for my requirements?

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)

See How do I copy a text file from a jar into a file outside of the jar? for example.

这与位置无关,而在于您需要告诉操作系统运行exe的事实,不幸的是,您无法通过在jar中提供位置来做到这一点。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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