exe within a jar file  
Author Message
bkennedy_pu





PostPosted: 2006-7-14 23:29:00 Top

java-programmer, exe within a jar file 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





PostPosted: 2006-7-14 23:55:00 Top

java-programmer >> exe within a jar file
"bkennedy_pu" <email***@***.com> wrote in message
news:email***@***.com...
>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!

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





PostPosted: 2006-7-14 23:57:00 Top

java-programmer >> exe within a jar file bkennedy_pu wrote:
> 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());

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





PostPosted: 2006-7-15 0:27:00 Top

java-programmer >> exe within a jar file
"Andrew Thompson" <email***@***.com> wrote in message
news:email***@***.com...
> bkennedy_pu wrote:
>> 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());
>
> 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?

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





PostPosted: 2006-7-15 1:27:00 Top

java-programmer >> exe within a jar file 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.

Mike Schilling wrote:
> "Andrew Thompson" <email***@***.com> wrote in message
> news:email***@***.com...
> > bkennedy_pu wrote:
> >> 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());
> >
> > 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?
>
> 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.)

 
 
Morten Alver





PostPosted: 2006-7-17 17:23:00 Top

java-programmer >> exe within a jar file Mike Schilling wrote:
> "Andrew Thompson" <email***@***.com> wrote in message
> news:email***@***.com...
>
>>bkennedy_pu wrote:
>>
>>>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());
>>
>>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?
>
>
> 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

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.


--
Morten