How to run jar file using Runtime

Discussion in 'Java' started by Grzesiek, Aug 13, 2007.

  1. Grzesiek

    Grzesiek Guest

    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, Aug 13, 2007
    #1
    1. Advertising

  2. Grzesiek

    Grzesiek Guest

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

    in my java code?
     
    Grzesiek, Aug 13, 2007
    #2
    1. Advertising

  3. Grzesiek

    Lew Guest

    Grzesiek wrote:
    > 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.

    --
    Lew
     
    Lew, Aug 13, 2007
    #3
  4. Grzesiek

    Grzesiek Guest

    > > 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.
    > Lew


    Thanx Lew, that solves my problem i think :)
     
    Grzesiek, Aug 13, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    632
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,791
    muttley
    Oct 20, 2005
  3. cyberco
    Replies:
    4
    Views:
    3,870
    Roedy Green
    Feb 14, 2006
  4. Arnold Peters
    Replies:
    0
    Views:
    702
    Arnold Peters
    Jan 5, 2005
  5. tiewknvc9
    Replies:
    8
    Views:
    616
    tiewknvc9
    Oct 2, 2006
Loading...

Share This Page