Is JDK required to run a jar file?

G

Grzesiek

Hi,
I have the following problem. I creted App.jar file. In App.java i
have a line:

Runtime.getRuntime("java -jar DoIt.jar");

Now i want to run App.jar on a computer wher\e there is only JRE and
no JDK, so "java" command is unknown. Is it possible to run App.jar
using only JRE? If not, how should i change the line above?

Thanx
 
L

Lew

Grzesiek said:
Hi,
I have the following problem. I creted App.jar file. In App.java i
have a line:

Runtime.getRuntime("java -jar DoIt.jar");

Now i want to run App.jar on a computer wher\e there is only JRE and
no JDK, so "java" command is unknown. Is it possible to run App.jar
using only JRE? If not, how should i change the line above?

"java" is a command in the JRE.

Most folks use all lower-case letters for JAR names. This is not so much a
matter of convention as of laziness, but it is widespread. However, the word
"I" in English should always be spelled with an initial upper-case letter.

Try using the right method of the Runtime class. The line you show will not
compile, because getRuntime() does not take an argument. Have you read the
Javadocs?
<http://java.sun.com/javase/6/docs/api/java/lang/Runtime.html#getRuntime()>

Read the Javadocs on the various Runtime exec() methods. And next time,
prepare an SSCCE (Simple Self-Contained Correct (compilable) Example) that
evinces your difficulty. The act of preparing it and reviewing its error
message(s) will likely show you the trouble and its solution on your own.

<http://www.physci.org/codes/sscce.html>

If you had done that, you'd've seen right away that your version of
getRuntime() won't compile, and the error message would've told you why.
 
K

Kunkhmer

Hi,
I have the following problem. I creted App.jar file. In App.java i
have a line:

Runtime.getRuntime("java -jar DoIt.jar");

Now i want to run App.jar on a computer wher\e there is only JRE and
no JDK, so "java" command is unknown. Is it possible to run App.jar
using only JRE? If not, how should i change the line above?

Thanx


Try this line.
Runtime.getRuntime().exec("java -jar DoIt.jar")
No JDK needed
 
T

Thomas Fritsch

Grzesiek said:
I have the following problem. I creted App.jar file. In App.java i
have a line:

Runtime.getRuntime("java -jar DoIt.jar");

Now i want to run App.jar on a computer wher\e there is only JRE and
no JDK, so "java" command is unknown.
Your conclusion is wrong. The "java" command *is* part of the JRE.

For example on my Windows, the JRE 1.5.0_10 is installed in
"C:\Programme\Java\jre1.5.0_10\". The java command of this JRE is
"C:\Programme\Java\jre1.5.0_10\bin\java.exe".
There is no need for any JDK to be installed to run your java
application. On the other hand: a JRE doesn't contain any development
tools (like "javac.exe", "jar.exe", ...).

However, if you have a JDK installed, you'll have a second JRE inside
that. For example on my Windows, the JDK 1.5.0_10 is installed in
"C:\Program Files\Java\jre1.5.0_10\". It contains a complete JRE in
"C:\Program Files\Java\jre1.5.0_10\jre\". Especially, there is a java
command in it: "C:\Program Files\Java\jre1.5.0_10\jre\bin\java.exe".
Is it possible to run App.jar using only JRE?
Yes.
 
T

Thomas Fritsch

Thomas said:
Your conclusion is wrong. The "java" command *is* part of the JRE.

For example on my Windows, the JRE 1.5.0_10 is installed in
"C:\Programme\Java\jre1.5.0_10\". The java command of this JRE is
"C:\Programme\Java\jre1.5.0_10\bin\java.exe".
There is no need for any JDK to be installed to run your java
application. On the other hand: a JRE doesn't contain any development
tools (like "javac.exe", "jar.exe", ...).

However, if you have a JDK installed, you'll have a second JRE inside
that. For example on my Windows, the JDK 1.5.0_10 is installed in
"C:\Program Files\Java\jre1.5.0_10\". It contains a complete JRE in
"C:\Program Files\Java\jre1.5.0_10\jre\". Especially, there is a java
command in it: "C:\Program Files\Java\jre1.5.0_10\jre\bin\java.exe".
Oops, I meant to write:
on my Windows, the JDK 1.5.0_10 is installed in
"C:\Program Files\Java\jdk1.5.0_10\". It contains a complete JRE in
"C:\Program Files\Java\jdk1.5.0_10\jre\". Especially, there is a java
command in it: "C:\Program Files\Java\jdk1.5.0_10\jre\bin\java.exe".
Sorry for the confusion.
 

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,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top