Failed to create functional JAR

Discussion in 'Java' started by JPractitioner, Feb 26, 2006.

  1. Hi guys,

    I'm using windows 2k server with
    Java version "1.5.0_06",
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    and
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing).


    the followings are the steps i went through which lead me to this
    problem.

    1. Got my cmd promt to the working directory where i have all my
    ..classes
    2. Typed command: jar cf MyJarFile.jar *.class
    3. Created a manifest file, named it "update.txt" with the following
    content
    Manifest-Version: 1.0
    Main-Class: MyMainClass
    Created-By: 1.5.0 (Sun Microsystems Inc.)
    4. Typed command: jar umf update.txt MyJarFile.jar.
    5. I got the following output on the cmd prompt
    Feb 26, 2006 4:59:27 PM java.util.jar.Attributes read
    WARNING: Duplicate name in Manifest: Manifest-Version
    Feb 26, 2006 4:59:27 PM java.util.jar.Attributes read
    WARNING: Duplicate name in Manifest: Created-By
    6. I tried double clicking MyJarFile.jar, the mouse cursor changed to
    the hourglass, and at the taskmanager, on the process tab, i saw
    javaw.exe was run. (was a 7768 K process)
    7. No 6 scenario only happened for one ore two seconds, then the mouse
    cursor returns to normal pointer image and the javaw.exe was turned
    off.
    8. I end up with nothing being run :(
    9. googling for answers and posting in smart java people's forum (yes,
    this google group)

    Please help me.
    Thanks (a lot) in advance :)
     
    JPractitioner, Feb 26, 2006
    #1
    1. Advertising

  2. I also found that, not only that i cannot run "MyJarFile.jar",
    I also cannot run "OtherJarFileFromInternet.jar".
    Same outcome (refering to no 8 above).

    :((
     
    JPractitioner, Feb 26, 2006
    #2
    1. Advertising

  3. JPractitioner

    hiwa Guest

    You must have used a jar cmf command from the
    start for your class files *and* manifest file. In other
    words, you should have had all the required files
    at hand from the start.
     
    hiwa, Feb 26, 2006
    #3
  4. hi hiwa, thx for ur reply.
    I already did as u suggested, but the outcome was the same.

    i did
    >jar cmf MyManifestFile.txt MyJarFile.jar *.class


    However, this time there was no warnings as encountered with my steps
    (refering to no 5 of my first post for this thread)

    Thanks anyway..but i am still not getting it working. please help.


    p/s: i ve done this before but with other pc (using similar steps), and
    it worked.. and now its making me go "hmmm....." ing.
     
    JPractitioner, Feb 26, 2006
    #4
  5. JPractitioner

    hiwa Guest

    Your text file for manifest should be a single line:

    Main-Class: MyMainClass

    A colon, a space and your class name.

    These lines are automatically written by jar command runtime:

    Manifest-Version: 1.0
    Created-By: 1.5.0 (Sun Microsystems

    Making an executable jar file is simple and easy if all the
    required files are in and under the current directory. I never
    failed in making them.
     
    hiwa, Feb 26, 2006
    #5
  6. hi hiwa, yeah i tried your latest suggestions as well and its coming to
    the same result as well.
    and, i have all the classes there,,

    i will try this on other machine. i suppose there is something wrong
    with my jar tool
    hmm...

    thx anyway, hiwa :)
     
    JPractitioner, Feb 26, 2006
    #6
  7. i've tried using other sets of classes, and its working. but only for
    that set of classes.
    those are the same classes i did with the other pc i mentioned (btw,
    the pc is of similar spec in terms of jvm and os = win2k pro)
    and i still cannot run jars that i downloaded.

    what have i done wrong?
     
    JPractitioner, Feb 26, 2006
    #7
  8. JPractitioner

    Chris Uppal Guest

    hiwa wrote:

    > Your text file for manifest should be a single line:
    >
    > Main-Class: MyMainClass


    BTW. It's important to ensure (thanks to some dodgy coding by Sun) that the
    line is terminated with a newline. DOS or Unix format is acceptable, Mac
    format may be too, for all I know.

    -- chris
     
    Chris Uppal, Feb 26, 2006
    #8
  9. JPractitioner

    hiwa Guest

    Try an extremely simple one, a same class file with main()
    method and a same manif text, on both machines. If it does
    work, or, it doesn't work, you must have some extremely
    local boob in your hands. We can't see them remotely.
    Our flesh must go to your room to view them.
     
    hiwa, Feb 26, 2006
    #9
  10. JPractitioner

    Roedy Green Guest

    On 26 Feb 2006 01:23:58 -0800, "JPractitioner"
    <> wrote, quoted or indirectly quoted someone
    who said :

    >the followings are the steps i went through which lead me to this
    >problem.


    Check out the hints under http://mindprod.com/jgloss/jar.html
    and http://mindprod.com/jgloss/jarexe.html

    Before you try running your jar, examine it with JarLook or Winzip or
    some such to make sure all it as you expected. See
    http://mindprod.com/products1.html#JARLOOK

    If you are debugging, the last thing you want is javaw.exe which hides
    the console where the error messages come out. Ether change the
    association to java.exe or don't use double click, use java -jar
    myjar.jar

    see http://mindprod.com/jgloss/jre.html#TESTING
    for instructions on fixing the association.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Feb 26, 2006
    #10
  11. JPractitioner

    Roedy Green Guest

    On 26 Feb 2006 01:23:58 -0800, "JPractitioner"
    <> wrote, quoted or indirectly quoted someone
    who said :

    >the followings are the steps i went through which lead me to this
    >problem.


    Also have a look into ANT. As soon as you master the art of building
    jars by hand, you will discard that skill and let ANT do it.

    http://mindprod.com/jgloss/ant.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Feb 26, 2006
    #11
  12. Hi hiwa, thx for the reply..
    well i ve tried to learn if i can successfully jar the class from the
    following code..
    but seems to be no chance at all for me.. the thing keep not working..

    Anyway, thx for your idea


    public class Try{
    public static void main(String[] a){
    System.out.println("THIS IS A TRY");

    }
    }

    p/s: I cannot access the other pc at the moment :(
     
    JPractitioner, Feb 26, 2006
    #12
  13. Hi Roedy, thanks for your reply,
    I had tried to use use java -jar
    myjar.jar as you suggested and i can see the program is running OK!

    Now the only thing is i cannot execute the JAR by double clicking on
    it.
    will check the links out. thanks man. :)
     
    JPractitioner, Feb 26, 2006
    #13
  14. I want to execute a console program.... (expecting too see the black
    and white "dos" console when i double click on the jar). Previously i
    only tried to use jar for GUI programs. So, will this be an issue? I
    mean, can i use jar for console program?

    Thanks in advance :)
     
    JPractitioner, Feb 26, 2006
    #14
  15. Guys, I think ive got it... Thanks a lot to all especially to Roedy
    Green.
    I found the followings at http://mindprod.com/jgloss/javawexe.html


    The javaw.exe command is identical to java.exe, except that with
    javaw.exe there is no associated console window. This implies you can't
    get it to display the version with -version since there is no console
    to display it on. Use javaw.exe when you don't want a command prompt
    window to appear. The javaw.exe launcher will, however, display a
    dialog box with error information if a launch fails for some reason.
    When you assocate jar files with either java.exe or javaw.exe you will
    control whether you can see the console output.

    So, I ve reconfigure my windows file type jar configuration to run
    (read at Making Jar Files Double Clickable from
    http://mindprod.com/jgloss/jar.html) java.exe instead of javaw.exe.

    However, The console did not wait untill i "press any key to continue".

    It appeared on the screen for a while (1 or 2 seconds).. then it
    disappeared.

    Is there any way, that i could make the console to not just disappear
    like that, but to have the "press any key to continue" option.

    hiwa, u did a great job as well, now i only have to remember one line
    for my manifest file, thx buddy :)
     
    JPractitioner, Feb 26, 2006
    #15
  16. JPractitioner

    Roedy Green Guest

    On 26 Feb 2006 06:03:15 -0800, "JPractitioner"
    <> wrote, quoted or indirectly quoted someone
    who said :

    >Now the only thing is i cannot execute the JAR by double clicking on
    >it.


    you likely have double click hooked up to the wrong program.

    See http://mindprod.com/jgloss/associations.html
    for how to fix it.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Feb 26, 2006
    #16
    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:
    641
    Arnold Peters
    Jan 5, 2005
  2. muttley
    Replies:
    0
    Views:
    2,800
    muttley
    Oct 20, 2005
  3. puzzlecracker
    Replies:
    2
    Views:
    5,200
    Jean-Francois Briere
    Dec 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,879
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    706
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page