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 / August 2007

Tip: Looking for answers? Try searching our database.

How to run jar file using Runtime

Thread view: 
Grzesiek - 13 Aug 2007 10:48 GMT
Hi,

Here is my problem. I can write:

  Runtime.getRuntime().exec("java -jar app.jar");

but suppose I have only Java Runtime Enviroment and app.jar. So i
can't type

   java -jar app.jar

because i don't have JDK

I can't type

   Runtime.getRuntime().exec("app.jar");

either.

But i can run app.jar in command line typing

  app.jar

My question is: How to run app.jar from code without using JDK? Can
Runtime be useful here?

Thanx
Grzesiek - 13 Aug 2007 11:07 GMT
Why I can type "app.jar" in Windows command line but i cant put
 "Runtime.getRuntime().exec("app.jar");"

in my java code?
Lew - 13 Aug 2007 11:29 GMT
> Why I can type "app.jar" in Windows command line but i cant put
>   "Runtime.getRuntime().exec("app.jar");"
>
> in my java code?

Why did you repeat your question?

"app.jar" is not a command; that's why you couldn't execute it.  When you
think you execute it from the command line, the command processor is actually
invoking the OS's "preferred app" association and invoking the "java" command.
 Runtime cannot do that because you didn't invoke the command processor with
it, you tried to invoke the JAR.  Without the command processor, there's
nothing to invoke the OS's association for you.

> Here is my problem. I can write:
>
[quoted text clipped - 6 lines]
>
> because i don't have JDK

Sure you can.

> I can't type
>
>     Runtime.getRuntime().exec("app.jar");
>
> either.

Because app.jar is not an executable.

> But i can run app.jar in command line typing
>
>    app.jar

Because the command processor knows how to use the OS's application associations.

> My question is: How to run app.jar from code without using JDK? Can
> Runtime be useful here?

You don't need the JDK to run a JAR, just the JRE.

Signature

Lew

Grzesiek - 13 Aug 2007 12:08 GMT
> > but suppose I have only Java Runtime Enviroment and app.jar. So i
> > can't type
[quoted text clipped - 5 lines]
> Sure you can.
> Lew

Thanx Lew, that solves my problem i think :-)


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.