*
The moose likes Beginning Java and the fly likes Jars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jars" Watch "Jars" New topic
Author

Jars

Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

I have a rather newbie question so please bear with me for a while.

You see i am trying to run a jar file programmatically and i am not quite sure how to do it. You see i use windows and i always double-click on it to run but now i have a requirement to run a jar file programmatically.

This is what i have so far



My java.exe is as located as shown by the value of str1 and my jar file is located at "C:\JButtons.jar". Basically all i need is a way to run that jar file and seeting the classpath programmatically by using the Runtime class.

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You don't want to use -cp for an executable JAR file. The command line you want is

java -jar C:\JButtons.jar

You could also consider directly invoking the main() routine of the main class in the jar. The java.util.jar.JarFile and java.util.jar.Manifest classes make this fairly easy to do.


[Jess in Action][AskingGoodQuestions]
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,


Ernest this is what i am doing in the in try stsement



The rest of the code is the same as my first post.

The jar file is still not executing and i am not sure why

Hoping to hear from you

Richard West
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Richard,

Instead of



try this



Regards,
Arnab
[ August 01, 2005: Message edited by: Arnb Sen ]

Regards,<br />Arnab
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

Arnb sen thank you your code works wondeully but i have one more question ak you guys why when i use the below value for str4 the jar does not run



but if i use this below value for str4 the jar runs



Basically is there a way in which i can put the above code so that it can be put into a string array??

I know this maybe an irritating question but please bear with me

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The problem is that str2 and str3 can't be separate arguments -- they're part of the single argument, the path to the jar. So you could say

String[] str4 ={str1, " -jar ", str2 + str3};

and that would work also.
Richard West
Ranch Hand

Joined: Jan 07, 2005
Posts: 127
Hi everyone,

Thank you Ernest and Arnb, Both your responses were of great
help and now the program works

One again thank you

Richard West
 
jQuery in Action, 2nd edition
 
subject: Jars
 
Similar Threads
doubt about equals vs ==
comparing Strings
Can anyone explain what is == and equal( ) ?
equals versus ==
help!!