Running a class from inside a jar

Discussion in 'Java' started by Derek Fountain, Jul 11, 2005.

  1. Newbie one: I have a Hello.class in my local directory which prints "Hello"
    and a World.class in ./org/test which prints "World". The World class is in
    a package (org.test) which the Hello class imports and calls to. It works
    fine.

    Now I want to put the World class in a JAR. I create the JAR with "jar cf
    World.jar World.class" which seems to work properly, but that leaves the
    question of where do I put the JAR file and how do I run the JVM such that
    it finds the class inside the JAR?

    I tried putting the JAR in the local directory and running with a CLASSPATH
    set to ., I tried putting the JAR in the org/test directory, I tried
    putting the World.jar in the CLASSPATH, and several other permutations, but
    I can't find the one that works. Can someone spell it out for me?
     
    Derek Fountain, Jul 11, 2005
    #1
    1. Advertising

  2. Derek Fountain wrote:
    > Newbie one:


    Newbie questions are better handled in comp.lang.java.help.

    > Now I want to put the World class in a JAR. I create the JAR with "jar cf
    > World.jar World.class" which seems to work properly, but that leaves the
    > question of where do I put the JAR file and how do I run the JVM such that
    > it finds the class inside the JAR?


    Read the documentation:

    http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html#-jar

    /Thomas

    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, Jul 11, 2005
    #2
    1. Advertising

  3. Derek Fountain

    teste1

    Joined:
    Sep 29, 2011
    Messages:
    1
    Thanks for a static link to a document that has now expired. This is super helpful for people who find this thread via google. Instead of providing a quick answer for a newb in need you issued the standard RTFM.

    Here is the answer for any googlers who find this thread in the future.

    jre -cp app.jar MainClass
     
    teste1, Sep 29, 2011
    #3
    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. cyril
    Replies:
    2
    Views:
    3,878
    cyril
    Aug 25, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    589
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,734
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,782
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    672
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page