Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

exe within a jar file

Thread view: 
bkennedy_pu - 14 Jul 2006 16:29 GMT
I want to package and run an exe within an executable jar file. I've
tried using the getClass().getResource("relative/exe/location"), but
receive the following error when running the jar

java.io.IOException: CreateProcess:
jar:file:\E:\test\TestProgram.jar!\myexe.exe error=2

this occurs when I run the following code:

Runtime rt = Runtime.getRuntime();
Process proc =
rt.exec(this.getClass().getResource("/myexe.exe").toString());

I would appreciate any help or suggestions on the subject. We've
considered extracting it an running it from a temp location and
cleaning up the directory, but we would like to avoid this. Thanks!
Mike Schilling - 14 Jul 2006 16:55 GMT
>I want to package and run an exe within an executable jar file. I've
> tried using the getClass().getResource("relative/exe/location"), but
[quoted text clipped - 12 lines]
> considered extracting it an running it from a temp location and
> cleaning up the directory, but we would like to avoid this. Thanks!

You haven't said which OS you're using, but in all the ones I'm familiar
with, the argument to Runtime.exec has to be something the native OS can
run, i.e. a file, not a entry in a zip file.  You'll need to extract it.
Andrew Thompson - 14 Jul 2006 16:57 GMT
> I want to package and run an exe within an executable jar file. I've
> tried using the getClass().getResource("relative/exe/location"), but
[quoted text clipped - 8 lines]
> Process proc =
> rt.exec(this.getClass().getResource("/myexe.exe").toString());

It is not surprising that Win. cannot launch the .exe while
it is compressed.   That is a luxury that we Java programmers
have come to expect, but applies mostly to Java classes.

> I would appreciate any help or suggestions on the subject. We've
> considered extracting it an running it from a temp location and
> cleaning up the directory, but we would like to avoid this.

..well that was exactly what I was going to suggest,
since I feel it would be the best solution.  Why do you
want to avoid that?

Andrew T.
Mike Schilling - 14 Jul 2006 17:26 GMT
>> I want to package and run an exe within an executable jar file. I've
>> tried using the getClass().getResource("relative/exe/location"), but
[quoted text clipped - 20 lines]
> since I feel it would be the best solution.  Why do you
> want to avoid that?

Think of all the issues it creates:

* The need to find a writeable temp directory
* The need to find a unique name to extract it to
* The problem of what to do if there isn't sufficient free space
* The impossibility of always deleting ithe executable afterward

None of these is insuperable, but it would be  easier not to deal with them,
if that were possible (which it isn't.)
bkennedy_pu - 14 Jul 2006 18:27 GMT
I am running a windows environment, but the reasons mike brought up are
exactly the reasons why we don't want to extract the files.

> >> I want to package and run an exe within an executable jar file. I've
> >> tried using the getClass().getResource("relative/exe/location"), but
[quoted text clipped - 30 lines]
> None of these is insuperable, but it would be  easier not to deal with them,
> if that were possible (which it isn't.)
Morten Alver - 17 Jul 2006 10:19 GMT
>>>I want to package and run an exe within an executable jar file. I've
>>>tried using the getClass().getResource("relative/exe/location"), but
[quoted text clipped - 25 lines]
> * The need to find a writeable temp directory
> * The need to find a unique name to extract it to

You can do it like this (from
http://javaalmanac.com/egs/java.io/CreateTempFile.html):
File temp = File.createTempFile("pattern", ".suffix");

... which finds the proper directory for you, and makes up a unique name.

> * The impossibility of always deleting ithe executable afterward

According to the page linked above you can use:

// Delete temp file when program exits.
temp.deleteOnExit();

... but I'm not sure if that method guarantees that the file will be
deleted.

Signature

Morten



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.