Run the .jar file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gaya3
    New Member
    • Aug 2007
    • 184

    Run the .jar file

    Hi all,
    When i try to run the .jar file,the following error is thrown.
    "Failed to load Main-Class manifest attribute from"
    How could i correct the above error.
    As i'm very much new to this jar file creation.I tired with
    following sample
    jar cf sample1.jar GetIP.class
    and just i run the .jar as
    java -jar sample1.jar

    is that rite are something else need to follow?
    correct me if i'm wrong.

    -Thanks & Regards,
    Hamsa
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by gaya3
    Hi all,
    When i try to run the .jar file,the following error is thrown.
    "Failed to load Main-Class manifest attribute from"
    How could i correct the above error.
    As i'm very much new to this jar file creation.I tired with
    following sample
    jar cf sample1.jar GetIP.class
    and just i run the .jar as
    java -jar sample1.jar

    is that rite are something else need to follow?
    correct me if i'm wrong.

    -Thanks & Regards,
    Hamsa
    How is the JVM supposed to know which class it has to use for startup? (of course
    that class has to have a static void main(String[] args) method defined. The JVM
    isn't that smart to figure out: "hm, this jar contains only one class, lets use that
    one for startup". You need a proper manifest entry in your jar file; go and read
    a tutorial about it.

    kind regards,

    Jos

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by JosAH
      ... go and read
      a tutorial about it.

      kind regards,

      Jos
      This one.

      Comment

      • gaya3
        New Member
        • Aug 2007
        • 184

        #4
        Originally posted by JosAH
        How is the JVM supposed to know which class it has to use for startup? (of course
        that class has to have a static void main(String[] args) method defined. The JVM
        isn't that smart to figure out: "hm, this jar contains only one class, lets use that
        one for startup". You need a proper manifest entry in your jar file; go and read
        a tutorial about it.

        kind regards,

        Jos

        Thank u Jos. It works fine.:-)

        -Thanks & regards,
        Hamsa

        Comment

        • gaya3
          New Member
          • Aug 2007
          • 184

          #5
          Originally posted by JosAH
          How is the JVM supposed to know which class it has to use for startup? (of course
          that class has to have a static void main(String[] args) method defined. The JVM
          isn't that smart to figure out: "hm, this jar contains only one class, lets use that
          one for startup". You need a proper manifest entry in your jar file; go and read
          a tutorial about it.

          kind regards,

          Jos

          Jos.. one more doubt..
          In my jar file named Myjar having the following contents..
          under MyPackage

          --> MyClass
          --> Image file (bmp)

          "MyClass" takes "Image file" as input and produce another "Image file" (bmp)as output.
          I want to write that output of that "MyClass" to the "Myjar".
          How can we do that?is there any possibility?

          -Thanks & Regards,
          Hamsa

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by gaya3
            Jos.. one more doubt..
            In my jar file named Myjar having the following contents..
            under MyPackage

            --> MyClass
            --> Image file (bmp)

            "MyClass" takes "Image file" as input and produce another "Image file" (bmp)as output.
            I want to write that output of that "MyClass" to the "Myjar".
            How can we do that?is there any possibility?

            -Thanks & Regards,
            Hamsa
            Have a look at the classes JarFile, JarInputStream, JarOutputStream and the
            parent class ZipFile and its compadres; a .jar file is basically not for writing to
            it. In you case better create a new .jar file with that class and .bmp file, it's
            a one-time operation anyway. If you want database (e.g. writable) functionality
            you know where to find them.

            kind regards,

            Jos

            Comment

            Working...