aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes How to call an .exe inside the same jar of main class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "How to call an .exe inside the same jar of main class?" Watch "How to call an .exe inside the same jar of main class?" New topic
Author

How to call an .exe inside the same jar of main class?

David de Lucca
Greenhorn

Joined: Aug 25, 2009
Posts: 10
Hi

I have a main class that i'm trying to call an .exe that is in the same folder of project and it only works on eclipse. If i build a jar file, put all files inside jar and try to run, it doesn't work. How can i call .exe from a jar?



The project tree is:

-Project
--src
-qemu.exe
-qemu.dll
-linux.img

Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

You can't. Windows doesn't allow you to execute files directly from ZIP / JAR files.

What you can do is unpack those files. Use System.getProperty("java.io.tmpdir") to get the path to the temporary files folder, then copy those files there. You can use Class.getResourceAsStream("/qemu.exe") etc to retrieve InputStreams to them.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to call an .exe inside the same jar of main class?