This discussion is archived
11 Replies Latest reply: Aug 31, 2010 10:33 AM by 795507 RSS

JAR Files will never work for me

795507 Newbie
Currently Being Moderated
I've been trying repeatedly to compress my applet's class files to prepare them for web use. However, no matter what I do, I cannot get the JAR files to work. I have tried compressing them manually through Command Line with the jar command, but it keeps on spitting out a ZipException. I've tried using the Eclipse JAR Export wizard, but the resulting jar file is invalid/corrupted. I've tried downloading several JAR Maker utilities, but in each I receive mixed results, wither the main class isn't found (even though I extract the JAR and the class is there and the manifest says the correct name) or the jar is again invalid/corrupted.

Any help?
  • 1. Re: JAR Files will never work for me
    EJP Guru
    Currently Being Moderated
    What was the text of the ZipException?
  • 2. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    java.util.zip.ZipException: attempt to write past end of STORED entry
    at java.util.zip.ZipOutputStream.write(ZipOutputStrea m.java:265)
    at sun.tools.jar.Main.addFile(Main.java:615)
    at sun.tools.jar.Main.create(Main.java:413)
    at sun.tools.jar.Main.run(Main.java:143)
    at sun.tools.jar.Main.main(Main.java:904)
    From what I can tell, it seems to be a common problem, but I've had some trouble finding a solution. Maybe I'm looking in the wrong places...?
  • 3. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    This is the code I used in command line, if it helps:

    jar cmf MANIFEST.MF homework.jar Shell.class WeekOneFirst.class
  • 4. Re: JAR Files will never work for me
    793415 Pro
    Currently Being Moderated
    Abion47 wrote:
    ..the main class isn't found (even though I extract the JAR and the class is there and the manifest says the correct name) ..
    Does the manifest file have an entirely blank line at the end? If not, add one. That is a common gotcha'.
  • 5. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    I ran the jar in command line and got this error:
    Exception in thread "main" java.land.NoClassDefFoundError: Shell$1
      at Shell.initializeWeek1(Shell.java:61)
      at Shell.initializeMenu(Shell.java:56)
      at Shell.<init>(Shell.java:34)
      at Shell.main(Shell.java:46)
    Caused by: java.lang.ClassNotFoundException: Shell$1
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPriviledged(Native Method)
      at java.net.URLClasSLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      . . . 4 more
    I looked at my code and at that point I am assigning an ActionListener to a JMenuItem:
    week1first = new JMenuItem("Random Number Generator");
    week1first.addActionListener(new ActionListener() { //<-- line 61
        public void actionPerformed(ActionEvent e) {
            layout.show(cardPanel, "1");
        }
    });
    week1.add(week1first);
    Is there something about jars that don't like menu items with ActionListeners? I commented out the addActionListener block and the jar ran fine.
  • 6. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    AndrewThompson64 wrote:
    Abion47 wrote:
    ..the main class isn't found (even though I extract the JAR and the class is there and the manifest says the correct name) ..
    Does the manifest file have an entirely blank line at the end? If not, add one. That is a common gotcha'.
    It has two, in fact.
  • 7. Re: JAR Files will never work for me
    800560 Newbie
    Currently Being Moderated
    Abion47 wrote:
    I ran the jar in command line and got this error:
    Exception in thread "main" java.land.NoClassDefFoundError: Shell$1
    . . . 4 more
    I looked at my code and at that point I am assigning an ActionListener to a JMenuItem:
    week1first = new JMenuItem("Random Number Generator");
    week1first.addActionListener(new ActionListener() { //<-- line 61
    public void actionPerformed(ActionEvent e) {
    layout.show(cardPanel, "1");
    }
    });
    week1.add(week1first);
    Is there something about jars that don't like menu items with ActionListeners? I commented out the addActionListener block and the jar ran fine.
    You are creating an annonymous class and it will be in its own .class file, with "Shell$1" in its name. That .class file needs to be in the jar (or somewhere along the Classpath).
  • 8. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    Worked perfectly. Always wondered what those extra $1 classes were...

    Last question. When I try to double-click the jar file, it says it cannot find the main class. However, if I run it through command line with the java -jar command, it runs fine. Anyone know why?
  • 9. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    Abion47 wrote:
    Worked perfectly. Always wondered what those extra $1 classes were...

    Last question. When I try to double-click the jar file, it says it cannot find the main class. However, if I run it through command line with the java -jar command, it runs fine. Anyone know why?
    I should add that this happens for most jars I try to run, even utilities that I download.
  • 10. Re: JAR Files will never work for me
    800560 Newbie
    Currently Being Moderated
    >
    > Last question. When I try to double-click the jar file, it says it cannot find the main class. However, if I run it through command line with the java -jar command, it runs fine. Anyone know why?
    >
    I should add that this happens for most jars I try to run, even utilities that I download.
    It sounds like your Windows file associations are not set up correctly. Google "set windows file association for java jar files"
  • 11. Re: JAR Files will never work for me
    795507 Newbie
    Currently Being Moderated
    Awesome. Thanks much. :)