Jar File

hello

I have bundled my application in a jar file
i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method

Comments

  • : hello
    :
    : I have bundled my application in a jar file
    : i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method
    :

    Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file

    More info here:
    http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • : : hello
    : :
    : : I have bundled my application in a jar file
    : : i just want ti know how to tell the jar file the entry point of my application i-e class containining the main method
    : :
    :
    : Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file
    :
    : More info here:
    : http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    :
    :
    how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file


  • : how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file

    The MANIFEST.MF file is a text file. All it needs to contain is the following code and be in the META-INF directory inside the JAR file (which is a ZIP file with a different extension).

    [code]
    Main-Class: mypackage.MyMainClass
    [/code]

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • : : how to Add a "Main-Class:" entry to the META-INF/MANIFEST.MF file
    :
    : The MANIFEST.MF file is a text file. All it needs to contain is the following code and be in the META-INF directory inside the JAR file (which is a ZIP file with a different extension).
    :
    : [code]
    : Main-Class: mypackage.MyMainClass
    : [/code]
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    :
    :

    sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
    plz give me example

  • : sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
    : plz give me example

    http://java.sun.com/docs/books/tutorial/jar/basics/
    http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html

    A manifest file is just a text file; for a class:
    [code]
    package mypackage;
    public class MyClass {
    public static void main(String[] args) {
    System.out.println("Hello, World!");
    }
    }
    [/code]
    You could have a manifest just containing:
    [code]
    Main-Class: mypackage.MyClass
    [/code]
    You can use a ZIP application to create a JAR file containing:
    [code]
    META-INF/MANIFEST.MF
    mypackage/MyClass.class
    [/code]
    This can be executed using the -jar switch:
    [code]
    java -jar myjar.jar
    [/code]

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • : : sir idon't know how to this Main-CLass entry in to the Mesifest-Inf file
    : : plz give me example
    :
    : http://java.sun.com/docs/books/tutorial/jar/basics/
    : http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html
    :
    : A manifest file is just a text file; for a class:
    : [code]
    : package mypackage;
    : public class MyClass {
    : public static void main(String[] args) {
    : System.out.println("Hello, World!");
    : }
    : }

    hi
    Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the
    Java virtual Machine Launcher "Could not find the main class,Program will exit!"
    Steps following to create the Jar file are
    1)I've created the txt file naming entrypoint class having the following header

    Main-Class: myApplication.mymainclass

    2)by the use of following command am creating the Jar file

    jar cmf entrypointclass myApplication.jar myApplication

    but when i run the jar file on the dos prompt using
    java -jar myApplication.jar
    the following error is occuring
    Exception in thread "main" java.lang.NoClassDefFoundError: amain

    Could I have constructed the jar file wrong?
    : [/code]
    : You could have a manifest just containing:
    : [code]
    : Main-Class: mypackage.MyClass
    : [/code]
    : You can use a ZIP application to create a JAR file containing:
    : [code]
    : META-INF/MANIFEST.MF
    : mypackage/MyClass.class
    : [/code]
    : This can be executed using the -jar switch:
    : [code]
    : java -jar myjar.jar
    : [/code]
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    :
    :

  • : Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the
    : Java virtual Machine Launcher "Could not find the main class,Program will exit!"

    You can list the contents of a JAR file using the command:
    [code]
    jar tf jarfilename.jar
    [/code]

    Ensure all the files you wanted to add are present. Class files should be in a directory structure corresponding to their packages.

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

  • : : Thanks a lot for your help.but when i double click the jar file.The following excetion is thrown by the
    : : Java virtual Machine Launcher "Could not find the main class,Program will exit!"
    :
    : You can list the contents of a JAR file using the command:
    : [code]
    : jar tf jarfilename.jar
    : [/code]
    :
    : Ensure all the files you wanted to add are present. Class files should be in a directory structure corresponding to their packages.
    :
    : ---------------------------------
    : [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]
    :
    :


    sir! this all is true for all packaged classes
    but what strategy i must atopt when my classes are not packaged


  • Here is an example for creating a JAR file using the GNU ZIP command (available for Win32 from http://unxutils.sourceforge.net/ ).

    I have the following files enumerated by the DIR command:
    [code]
    C:demo1>dir /s /b
    C:demo1META-INF
    C:demo1MyClass.class
    C:demo1MyClass.java
    C:demo1META-INFMANIFEST.MF
    [/code]

    MANIFEST.MF contents:
    [code]
    Main-Class: MyClass
    [/code]
    MyClass.java contents (class has no package declaration; is in the default package):
    [code]
    public class MyClass {
    public static void main(String[] args) {
    System.out.println("Hello, World!");
    }
    }
    [/code]

    I create the JAR using the ZIP command (you probably don't want the Java source code in it, but it does no harm):
    [code]
    C:demo1>zip -r ..myjar.jar *
    adding: META-INF/ (244 bytes security) (stored 0%)
    adding: META-INF/MANIFEST.MF (164 bytes security) (deflated 10%)
    adding: MyClass.class (164 bytes security) (deflated 31%)
    adding: MyClass.java (164 bytes security) (deflated 12%)
    [/code]

    This can be run thus:
    [code]
    C:>java -jar C:myjar.jar
    Hello, World!
    [/code]

    ---------------------------------
    [size=1]HOWTO ask questions: http://catb.org/~esr/faqs/smart-questions.html[/size]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories