How to run jar file using Runtime

G

Grzesiek

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
 
G

Grzesiek

Why I can type "app.jar" in Windows command line but i cant put
"Runtime.getRuntime().exec("app.jar");"

in my java code?
 
L

Lew

Grzesiek said:
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:

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top