Creating a JAR with main class def.

Hello Amigos,
I am having problems creating a jar file. My problem is that when I create the jar file and insert this line in my manifest file
Main-Class: classnamewhere classname is what ever class you want as explain here:
http://java.sun.com/developer/Books/javaprogramming/JAR/basics/run.html
Then I have the jar file and double click it and get the Fail to load Main-Class error.
This is what I am typing in the command line:
jar cmf MANIFEST.MF myapp.jar *.class
When I go back and extract all the files out of the jar file the manifest files looks like this:
Manifest-Version: 1.0
Created-By: 1.3.1 (IBM Corporation)Thanks in advance

No ofense but... You got to be kidding me!?!?!Not kidding at all. Had you read the online tutorial, you'd have found the following line:
Warning: The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
Have you tried it yet?

Similar Messages

  • How to create a Jar with only class files?

    Dear all,
    I want to create a jar file with only classes.My class files and java files are in different folders under com .
    say
    com
    in com there are two folders
    folder 1 -- subfolder 1
    folder 2 -- subfolder 2
    like this.
    If i want to create a jar file from com directory how should i give the jar command.Again my jar should contain only .class files.
    Any help will be appreciated
    Thanks
    lekshmi

    It doesn't work.Says "No such class or directory"
    Any other way Or is it possible to do so?Read the link I posted and create the statement to make your structure. I was thinking you were inside the com directory but if you are above it you will need something like this instead:
    jar -cf test.jar com\*.class com\subfolder1\*.class com\subfoler2\*.class
    But either way don't just copy and past this. Think about what is does so that you can make it work for you.
    Also, you might want to look into using Ant if you are going to be building this a lot.

  • Arrangement of jar containing main class

    Hello all,
    usually it is required, that that jar file (let me call it "main jar"), which contains the main class (by which the application is entered), has to be the first jar in the order of the jar files within <resources> of the jnlp file.
    Now if a patch of the "main jar" is created which doesn't contain the main class, where has this patch jar to be arranged in the jnlp file? Because it is a patch jar, usually it must be arranged in front of this main jar, that it is read before the main jar to load the patched class correctly. On the other hand it is required, that the jar with the main class has to be the first ...
    Therefore again: Where has that patch jar, described, to be arranged?
    Thanks for all good advices.
    Thomas

    The main jar does not need to be first, if you explicitly add the argument main="true":
    <jar href="jar2.jar"/>
    <jar href="jar1patch.jar" />
    <jar href="jar1.jar" main="true"/>
    the first jar is used as main only if there is no jar listed with main="true".
    /Andy

  • Assembling jar with dependent classes

    For efficient Applet use I'd like to copy selectively into a jar my applet classes plus all classes they are dependent on from a set of libraries, thus producing the minimum jar library with which the applets can run (obviously classes which are part of the standard JRE are not to be included.
    Now I can see, in outline, how to write a program to achieve this, but I have this feeling I've read about such a facility somewhere. I thought it was in ANT but I can't find it in the ANT documentation now. If someone knows of a utility (preferably free) that can do this please can you save me the trouble.

    Well, I think I've found one on sourceforge: http://genjar.sourceforge.net/
    I've also found out how to get dependant classes from a .class file relatively simply. Class references are listed in the Constants Table which is near the start of the .class file format. I've written a piece of code which seems to fetch them OK.
    package org.igis.assjar;
    * <p>Read a class file stream and return all the referenced classes from the
    * class.</p>
    * @author  malcolmm
    public class GetClassRefs {
        private static final byte CONSTANT_Class = 7;
        private static final byte CONSTANT_FieldRef = 9;
        private static final byte CONSTANT_MethodRef = 10;
        private static final byte CONSTANT_InterfaceMethodRef = 11;
        private static final byte CONSTANT_String = 8;
        private static final byte CONSTANT_Integer = 3;
        private static final byte CONSTANT_Float = 4;
        private static final byte CONSTANT_Long = 5;
        private static final byte CONSTANT_Double = 6;
        private static final byte CONSTANT_NameAndType = 12;
        private static final byte CONSTANT_Utfs = 1;
        private static final int [] lengths = new int[13];
        static {
            lengths[CONSTANT_Class] = 3;
            lengths[CONSTANT_FieldRef] = 5;
            lengths[CONSTANT_MethodRef] = 5;
            lengths[CONSTANT_InterfaceMethodRef] = 5;
            lengths[CONSTANT_String] = 3;
            lengths[CONSTANT_Integer] = 5;
            lengths[CONSTANT_Float] = 5;
            lengths[CONSTANT_Long] = 9;
            lengths[CONSTANT_Double] = 9;
            lengths[CONSTANT_NameAndType] = 5;
            lengths[CONSTANT_Utfs] = 1;
        private final static int magic = 0xcafebabe;
        String mainClass;
        String [] refs;
        /** Creates a new instance of GetClassRefs */
        public GetClassRefs(java.io.InputStream ins) throws java.io.IOException,java.lang.ClassFormatError {
            java.io.DataInputStream in = new java.io.DataInputStream(ins);
            Object[] constTable;
            int nRefs;
            if(in.readInt() != magic)
                throw new ClassFormatError("Bad class magic");
            in.skipBytes(4);
            int cpCount = in.readUnsignedShort();
            constTable = new Object[cpCount];
            nRefs = 0;
            for(int i = 1; i < cpCount; i++) {
                int tag = in.readUnsignedByte();
                switch(tag) {
                    case CONSTANT_Utfs:
                        String clsName = in.readUTF();
                        if(clsName.length() > 0) {
                            if(clsName.charAt(0) == '[') {
                                do
                                    clsName = clsName.substring(1);
                                while(clsName.charAt(0) == '[');
                                if(clsName.charAt(0) == 'L' && clsName.endsWith(";"))
                                    clsName = clsName.substring(1, clsName.length() - 1);
                            constTable[i] = clsName;
                        break;
                    case CONSTANT_Class:
                        nRefs++;
                        constTable[i] = new Integer(in.readUnsignedShort());
                        break;
                    case CONSTANT_Long:
                    case CONSTANT_Double:
                        i++;
                        in.skipBytes(8);
                        break;
                    default:
                        if(tag < 0 || tag >= lengths.length || lengths[tag] == 0)
                            throw new ClassFormatError("Invalid constants tag " + tag);
                        in.skipBytes(lengths[tag] - 1);
                        break;
            in.skipBytes(2);
            int thisClass = in.readUnsignedShort();
            if(!(constTable[thisClass] instanceof Integer))
                throw new ClassFormatError("Invalid main class index");
            int cpp = ((Integer)constTable[thisClass]).intValue();
            if(!(constTable[cpp] instanceof String))
                throw new ClassFormatError("Invalid main class pointer");
            mainClass = (String)constTable[cpp];
            refs = new String[nRefs - 1];
            int j = 0;
            for(int i = 1; i < constTable.length; i++) {
                Object entry = constTable;
    if(entry instanceof Integer) {
    int idx = ((Integer)entry).intValue();
    if(idx < 1 || idx >= constTable.length)
    throw new ClassFormatError("Out of range class reference");
    if(constTable[idx] instanceof String) {
    if(i == thisClass)
    mainClass = (String)constTable[idx];
    else
    refs[j++] = (String)constTable[idx];
    else
    throw new ClassFormatError("Class reference not string");
    public String getMainClass() {
    return mainClass;
    public String[] getRefs() throws ClassFormatError {
    return refs;

  • Create a .jar with a database in mysql????

    Hi !!!!
    I create a script in .java, and I have none error. My script use a database, to read and to save some data.
    I create a Manifest.mf
    Manifest-Version: 1.0
    Main-Class: AutoPlanning
    Class-Path: DriverJava/mm.mysql-2.04/mysql.jar
    What are the command to create this .jar?
    Thanks !!!

    I tried your advice. I create a lib directory and I copie all these .jar files :
    gnujaxp.jar
    jcommon-1.0.0-rc1.jar
    jfreechart-1.0.0-rc1.jar
    junit.jar
    servlet.jar
    mysql.jar;
    And my Manisfest file is now :
    Main-Class: AutoPlanning
    Class-Path: .;lib/gnujaxp.jar;lib/jcommon-1.0.0-rc1.jar;lib/jfreechart-1.0.0-rc1.jar;lib/junit.jar;lib/servlet.jar;lib/mysql.jar;
    Next I execute :
    - jar cvmf Manifest.mf AutoPlanning.jar *.class lib/*.jar Aide Images Config
    - java -jar AutoPlanning.jar
    Unfortunately I have still the same problem
    Driver non trouve : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Connexion refuse ou base inconnu : java.sql.SQLException: No suitable driver
    Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/data/catego
    ry/CategoryDataset
    at Fenetre.<init>(Fenetre.java:388)
    at Start.<init>(Start.java:21)
    at AutoPlanning.main(AutoPlanning.java:20)
    But thanks you for your answer :)

  • Loading jars with same class loader

    Hi all,
    I need to tell Weblogic to load various jars using same class loader.
    "various jars" means jars that belong to different web applications. (weblogic 10)
    Is that possible ?
    PS: I can not change jar location, e.g. put them in common directory or so.

    Hi,
    If you don't want to change the JAR Locations then you can try the following..
    Option1). Add the Jar Location with the Jar file name in the Server classpath...of your server startScript (like startWebLogic.sh)
    CLASSPATH=${CLASSPATH}:/opt/app/myJars/first.jar:/opt/app/myJars/second.jar:
    But in this case the Jars which are there in the classpath...will be loaded using System Classloaders and will be different from Application Classloaders...but the Classes belonging to these Jars will be available to your applications because final classpath will be the Summation of following:
    Final Classpath = Bootstrap classloader (+) System ClassLoader (including Extended Classpath from Domain Lib) (+) Application ClassLoader (+) AppModule ClassLoader
    Option2). If you dont want to add the Jars in the Server ClassPath then u can use "Optional Package" deployment feature provided by WebLogic...In this case you can deploy the JARs in WebLogic Server as Optional Packages from the Same Location where it is at present...(as you dont want to change the Jar locations) like following: http://jaysensharma.wordpress.com/2009/12/06/optional-packages/
    Thanks
    Jay SenSharma

  • Create Stanadlone JARs with Third-party API

    Hi,
    I'm working on some personal explorations using OSB 11g, and for that I need to call some JARs with my code. But, the problem is that I'm using Apache POI API for reading MS Excel files. So, how do I go about exporting the POI API along with my code into a single JAR. It has to be one JAR, since to the best of my knowledge OSB doesn't support referencing of multiple JARs at one go.

    See http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/

  • 2 Jars with same class name. NoSuchMethod. Can't change classpath

    I have overloaded a method in a class that came with an openSource package.
    Things were fine until I implemented my components in a new version of the Server application; when I discovered that the it uses the same openSource package bundled in its classpath.
    This results into a NoSuchMethod exception since I have overloaded the method with new argument types.
    1. I cannot remove or shuffle this JAR from the Server's classpath, since that would stop something else.
    2. I cannot change my code since it is implemented in a lot of places.
    Has anyone called a specific method of a jar? like E.g. "someJar.jar".SomeClass.someMethod (arg);
    If yes how?
    The above code is not possible syntactically, but I have put it for ease in interpreting the problem.
    Any input will be appreciated.
    NOTE: I cannot disclose the names of products for company policy issues.

    Just some ideas...
    1. I cannot remove or shuffle this JAR from the
    Server's classpath, since that would stop something
    else.Some servers allow for multiple classpaths - i.e. you can separately specify the classpath that the server itself uses from the one that your hosted applications will be using.
    Also, if your changes to the openSource code are only the addition of an overloaded method, why couldn't you just substitute your jar for the one the server is using, why would that break the server?
    2. I cannot change my code since it is implemented in
    a lot of places.That sounds lame. You can't do a global replace? How about just changing the package name?
    Has anyone called a specific method of a jar? like
    E.g. "someJar.jar".SomeClass.someMethod (arg);
    If yes how?Yes, but it's not as simple as your pseudo-code...
    You can use URLClassLoader to load a specific class from a specific jar file URL, and then use reflection to get the method you want from it, and then call it.
    good luck
    j

  • Issue in creating bmp file with cl_igs_chart_engine class

    Hi All,
    I want to populate dynamic graphic in a smartform.
    Im using cl_igs_chart_engine class to produce a GIF format of a chart.
    Then im trying to use class cl_igs_image_converter to convert that gif into a bmp format using INPUT = 'image/gif' and OUTPUT = 'image/x-ms-bmp'.
    but it returns with system failure exception  in
    call function 'PIGFARMDATA' .
    There is no error happening in case of converting any graphic format(bmp,tiff) to gif format but system failure exception occurs while trying to convert into bmp format.
    Appreciate your inputs.
    Cheers,
    Vikram

    Hi,
    I have taken a copy of program GRAPHICS_IGS_CE_TEST and made changes in it. In std program, file type in customizing XML is 'PNJ'. I changed it to 'BMP' as per your suggestion. However, in the
    call method l_igs_ce->execute
          exceptions
          others = 1.
    there is a call function for 'PIGFARMDATA'. Im getting exception error( sy-subrc = 2) for system failure.
    This program works fine if the file type in customizing XML is 'GIF' or 'PNG' but not for 'BMP' file types.
    Please advice.
    Cheers,
    Vikram

  • Creating batch job with 5 classes

    Hi All,
    I have a requirement in which I have to do five different operations at different time instances.
    1.Generate a report at morning 11.00 AM.
    2.update a table with more than 6000 rows at night 12.30 AM
    3.Generate a second report querying from the database at 10.00 AM Everyday.
    4.Generate an automail at 11.30 Am Everyday
    All these are plain Java classes and not web components. How could I effectively design the batch job so that it doesnot take nmuch memory and design classes so that they must be reusable like DB connection,Getting a db field value frequently etc.
    Can any one help me on this.

    http://www.google.com/search?q=job+schedule+in+java&client=netscape-pp&rls=com.netscape:en-US

  • Classes12.jar with connection.class file

    Hi All,
    I want to download classes12.jar file which contains connection.class which is used for datasoruce.Can you please get me the download URL for the same.Please help me out as i got classes12.jar file but it doesnt contain the connection.class,if it doesnt have the connection.class it gives me a JMS:112 error which says invalid connection.
    Do please help me out in getting the classes12.jar file link for download.
    Thnaks in advance.
    Regards,
    Kalyan

    What is the Oracle database version? What is the JDK version? Various versions of classes12.jar are available.
    Please download classes12.jar from
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

  • Executable JAR file: Could not find the main class.

    Hello,
    I have a problem with making an executable JAR file.
    I have written a JAVA program that consists of five different classes of which User.java is the main class and I have saved a text document with Main-Class: User and a blank line after that.
    If I try:
    jar cmf MainClass.txt User.jar User.class Beheerder.class Operator.class Manager.class MaakVisueelSchema.class
    it makes a executable jar file which actually works! :)
    But when the Operator class trys to open the MaakVisueelSchema class the screen stays blank.
    I can run MaakVisueelSchema with java MaakVisueelSchema.
    So I tried to make an executable JAR that consists only of MaakVisueelSchema, the same way as I did for User:
    Main-Class: MaakVisueelSchema
    jar cmf MainClass.txt MaakVisueelSchema.jar MaakVisueelSchema.class
    Then I get the error message:
    Could not find the main class. Program will exit.
    from the Java Virtual Machine Launcher.
    The big difference between MaakVisueelSchema and the other classes is that MaakVisueelSchema contains a PaintComponent method and an ComponentListener. Is it possible that one of those creates the error?
    Can anyone help me with this problem?
    Thanks in advance!
    Bye!

    Yes,
    I tried:
    jar xvf MaakVisueelSchema.jar
    and it returns:
    META-INF/
    META-INF/MANIFEST.MF
    MaakVisueelSchema.classN/G. You need to manually create a manifest file in a text editor, have it point to your main class, and enter it in your jar command as an argument.

  • Error msg Could not find the main class.Program will exit. in jar execution

    Hello,
    I have created a jar so that I can used it in the webapp.
    but when I click on it it says "Could not find the main class.Program will exit."
    I searched a lot in the net and found that it has to do with the manifest file.
    I even updated the manifest file using the command "jar umf main.txt filefolderupload.jar" with the class name mention along with the package heirarchy.
    (pakage heirarchy in /,\ and .)
    I am using JDK 1.5 . and have Updated JRE 1.6.
    Also tried with extending the class with JApplet, but in vain.
    Kindly help me in the above mention issue.
    tia,
    Sarwa

    This post hints at a number of misunderstandings on your part, and raises a couple of important questions.
    Note that this 'simple question' has a complicated answer. Given the complexity of it, it might pay to add Dukes to it, ..a lot of Dukes.
    The important questions are.
    1) Does this file/directory uploader need to provide the end-user with a file dialog in which they can choose a local directory to upload, or will a multi-file chooser do?
    2) Does this uploader need to upload to foreign sites, or does it upload back to its own server?
    Looking at this table I prepared to describe the [uploader/local file access|http://pscode.org/test/uploader/fileuploader.html] possibilities, if the answers to the questions are 'multi-file chooser will do' and 'home site only', the best option is a sandboxed app. launched using webstart (JNLP) - option 5. If either of those questions go the other way, option 6 (digitally signed with extended permissions) is needed.

  • Java can't find main class when manifest has certain JARs on it

    I recently wrote an Ant script that builds my application and jars it up, creating a manifest in the process. The manifest specifies the main class and a classpath that mentions other jars that exist in the same directory. Everything works as expected and I am able to run the program using "java -jar abc.jar".
    However, I recently started using classes in my program that come from a jar that should (according to the company I work for) reside in a central location rather than each application having its own copy. So, I changed my build script to reference those shared jars in a common location. But now when I run "java -jar abc.jar", I get a java.lang.ClassNotFoundException: com.example.Main. If I edit the jar's manifest and manually remove the new jars from the classpath, the ClassNotFoundException error goes away (although obviously that causes other problems.) Is there something about adding those new jars to the manifest classpath that would prevent Java from finding my main class? My manifest looks something like this and the last two jars (the ones with the absolute paths) are the jars that seem to be the root of the problem.
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.7.0
    Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
    Main-Class: com.uprr.app.rsa.Main
    Class-Path: acegi-security-1.0.6.jar commons-codec-1.4.jar commons-htt
    pclient-3.1.jar commons-lang-2.4.jar commons-logging-1.1.1.jar common
    s-pool-1.5.4.jar dom4j-1.6.1.jar jakarta-oro-2.0.8.jar jaxen-1.1.1.ja
    r jibx-run-1.2.1.jar joda-time-1.6.jar jsr173_1.0_api.jar log4j-1.2.1
    5.jar opensaml-1.1.jar spring-2.5.2.jar stax-api-1.0.1.jar wstx-asl-3
    .2.9.jar xmf-3.0.2.jar xmlsec-1.4.1.jar C:\software\tibco\ems\clients
    \java\jms.jar C:\software\tibco\ems\clients\java\tibjms.jarAny ideas?
    Brandon

    I still don't know why giving the absolute classpath entry like that would cause Java to be unable to find the jar's main class, but I did make an interesting discovery. If I give the absolute path without the drive letter, is able to find the main class again. Something like this won't work...
    Class-Path: C:\software\tibco\ems\clients\java\tibjms.jarBut something like this will...
    Class-Path: \software\tibco\ems\clients\java\tibjms.jarBut I'd still like to know why Java doesn't accept drive letters when running on a Windows machine. After all, what if my manifest needed to reference a jar that was on a different drive, like a network drive (since this whole problem came up as a result of shared common jars that need to exist outside of the project.)

  • Who to create a JAR file with JSF pages ?

    Hi,
    I'm facing the problem of using a component that has classes and JSP files (just think in a security component, or a CRUD component, etc). So far you need to copy the jar with the classes and each JSP, each one to its directory together with other dependencies.
    What are you using to package JSF's and classes ? Are you aware of some solution today for this?
    Thanks in advance,
    Juan

    Sun's App Server allows you to precompile JSPs so you don't need the .jsp files for deployment. In the past I've also servled up precompiled JSP's from a Servlet (when the server required the .jsp file there otherwise).
    For JSF, JSFTemplating allows the pages to be stored in a .jar flie directly and doesn't require any compiling. So this is very simple... this is what GlassFish is using.
    I hope this helps!
    Ken Paulsen
    https://jsftemplating.dev.java.net

Maybe you are looking for