jar help

Discussion in 'Java' started by SP, Jun 28, 2003.

  1. SP

    SP Guest

    hi
    i have been trying to make a jar file for the following files

    hello.java
    hello.class
    with the following command

    jar cf hello.jar hello.*

    it is created and with
    jar tf hello.jar

    i am able to see the list of files which is in this case
    META-INF/
    META-INF/MANIFEST.MF
    hello.class
    hello.java

    but it doesn't run with
    java -jar hello.jar

    following error appears
    Failed to load Main-Class manifest attribute from
    hello.jar

    i tried to fix it with

    jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
    entry Main-Class: path.hello)

    to no avail!
    and another thing is although the dir META-INF is shown as above it is not
    created in the folder..where is it created??

    help please

    Greetingz
    Sunil
     
    SP, Jun 28, 2003
    #1
    1. Advertising

  2. SP wrote:

    > i tried to fix it with
    >
    > jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
    > entry Main-Class: path.hello)


    Is the class hello in the package path? If it's not in any package, just
    use "Main-Class: hello".

    (Btw, class names in java should be capitalized, so use Hello instead of
    hello for the class name.)

    > to no avail!
    > and another thing is although the dir META-INF is shown as above it is not
    > created in the folder..where is it created??


    The jar program creates that directory, you need not worry about it.
     
    Haakon Nilsen, Jun 28, 2003
    #2
    1. Advertising

  3. SP

    ghl Guest

    "SP" <> wrote in message
    news:l4gLa.43143$...
    > hi
    > i have been trying to make a jar file for the following files
    >
    > hello.java
    > hello.class
    > with the following command
    >
    > jar cf hello.jar hello.*
    >
    > it is created and with
    > jar tf hello.jar
    >
    > i am able to see the list of files which is in this case
    > META-INF/
    > META-INF/MANIFEST.MF
    > hello.class
    > hello.java
    >
    > but it doesn't run with
    > java -jar hello.jar

    [Assuming all your files are in the same directory...]
    To run the application from a jar file by specifying the jar (hello.jar) the
    jar file manifest.mf file must contain a header of the form
    Main-Class: start-classname
    This tells Java which class to load and call first.
    You can modify the manifest.mf file in the jar by creating a file with the
    needed header and updating the jar file using the jar command uvfm.
    The file you need would be something like myMan.txt and would contain the
    line
    Main-Class: hello
    The jar update would be
    jar uvfm hello.jar myMan.txt
    This will update the jar with the header in myMan.txt

    You can then run the app with
    java -jar hello.jar

    By putting the jar file in the JAVA_HOME\jre\lib\ext directory you can run
    the app with
    java hello
    from anywhere.
    Have fun.
    --
    Gary
     
    ghl, Jun 28, 2003
    #3
  4. SP

    hh Guest

    SP wrote:
    > hi
    > i have been trying to make a jar file for the following files
    >
    > hello.java
    > hello.class
    > with the following command
    >
    > jar cf hello.jar hello.*
    >
    > it is created and with
    > jar tf hello.jar
    >
    > i am able to see the list of files which is in this case
    > META-INF/
    > META-INF/MANIFEST.MF
    > hello.class
    > hello.java
    >
    > but it doesn't run with
    > java -jar hello.jar
    >
    > following error appears
    > Failed to load Main-Class manifest attribute from
    > hello.jar
    >
    > i tried to fix it with
    >
    > jar cfm hello.jar mymainclass hello.*(after creating mymainclass with the
    > entry Main-Class: path.hello)
    >
    > to no avail!
    > and another thing is although the dir META-INF is shown as above it is not
    > created in the folder..where is it created??
    >
    > help please
    >
    > Greetingz
    > Sunil
    >
    >


    To add to the other two responses, you might find a tool such as JavaJar
    useful: http://pivotonic.com/
     
    hh, Jun 28, 2003
    #4
  5. SP

    Liu, Chunyen Guest

    use "jar cvf hello.jar hello.class"
    There is no need to include the source code (*.java)

    > -----Original Message-----
    > From: SP [SMTP:]
    > Posted At: Saturday, June 28, 2003 7:44 AM
    > Posted To: comp.lang.java.programmer
    > Conversation: jar help
    > Subject: jar help
    >
    > hi
    > i have been trying to make a jar file for the following files
    >
    > hello.java
    > hello.class
    > with the following command
    >
    > jar cf hello.jar hello.*
    >
    > it is created and with
    > jar tf hello.jar
    >
    > i am able to see the list of files which is in this case
    > META-INF/
    > META-INF/MANIFEST.MF
    > hello.class
    > hello.java
    >
    > but it doesn't run with
    > java -jar hello.jar
    >
    > following error appears
    > Failed to load Main-Class manifest attribute from
    > hello.jar
    >
    > i tried to fix it with
    >
    > jar cfm hello.jar mymainclass hello.*(after creating mymainclass with
    > the
    > entry Main-Class: path.hello)
    >
    > to no avail!
    > and another thing is although the dir META-INF is shown as above it is
    > not
    > created in the folder..where is it created??
    >
    > help please
    >
    > Greetingz
    > Sunil
    >
     
    Liu, Chunyen, Jun 30, 2003
    #5
    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. James Alan Farrell
    Replies:
    6
    Views:
    9,710
    Andrew Thompson
    Jan 9, 2004
  2. Arnold Peters
    Replies:
    0
    Views:
    591
    Arnold Peters
    Jan 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,736
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,784
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    673
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page