3 Replies Latest reply: Mar 3, 2007 1:02 PM by 807599 RSS

    Problem with JAR file

      Hi guys, I created one calculator in Java and it runs fine in my pc. But now I want to send it to my professor so that he can view it by just a mouse click.

      So, I created one JAR file. But when I click the JAR file I always get the following message " Failed to load Main-class manifest attribute from C...........atiq.jar

      For you some info:

      1. The name of my main class is Namer that extends JFrame
      2. I have 2 inner classes as ButtonListener and ComboListener inside
      main class
      3. In Manifest.mf file it's written : Main-Class: Namer

      4. In a folder I have put jar.exe, all class files, Namer.java and Manifest.mf file
      5. I wrote the following code to make the jar--- jar cfm atiq.jar Manifest.mf Namer.java *.class

      6. The atiq.jar file is created but when I click this icon, my program doesn't run and I get the above error.

      Plz help me out .....
        • 1. Re: Problem with JAR file
          You can't just dump all your .class and whatever files in a .jar file and
          expect the jvm to figure out what class to use for the main(...) method.

          You have to add a little file, named 'Manifest.mf' in a directory 'meta-inf'
          which contains at least this:
          Main-Class: YourClassThatContainsAMainMethod
          I'm about sure that other kind people will supply you with the links to
          some tutorials w.r.t. the 'jar' command if you can't find them yourself.

          kind regards,

          • 2. Re: Problem with JAR file
            All you need to do is create a text-file (e.g. Manifest.txt) and add the line
            Main-Class: yourpackage.YourClass
            to it, AND add a newline at the end of the text-file. Then use the command
            jar cmf Manifest.txt JarName.jar yourpackage/*.class
            provided you have the Manifest.txt file in the current directory and the .class files in a subdirectory named yourpackage (i.e. your class belongs to a package named yourpackage).

            • 3. Re: Problem with JAR file
              Hi guys, thanks for your replies. I followed duckbill's instructions and it works perfectly now. Thanks.