Results 1 to 3 of 3
  1. #1
    allan.clapp is offline Member
    Join Date
    Apr 2012
    Location
    Southwest Ohio
    Posts
    1
    Rep Power
    0

    Question Java is not finding the Main Class in my jar file...

    I am building a multi-player battle simulation game application. I have built the program and successfully built a jar file.

    But Java fails to see the main class when I invoke the jar file.

    Here is my manifest:

    Class-Path: GlobalConfig/GlobalConfig.jar
    LocalConfig/LocalConfig.jar Dialogs/Dialogs.jar
    SupportCode/SupportCode.jar
    Main-Class: AdminClient
    Here is my main class code:

    //
    // Description: Admin Client.
    //
    // Disk Filename: AdminClient.java
    //
    // Written By: Allan P. Clapp
    //
    // Copyright (c) 2012 Allan P. Clapp, All Rights Reserved.
    //

    import java.io.*;
    import java.awt.event.*;
    import AdminClientForms.*;
    import GlobalConfig.*;
    import LocalConfig.*;
    import Dialogs.*;

    public class AdminClient
    {
    private
    static Object MainFrameCloseLock;
    static AdminUserInfo ThisUsersInfo;
    static TheServerConnectionInfoScreen ServerConnectInfo;
    static AdminUserLoginScreen TheUserLoginScreen;
    static MainForm TheMainForm;

    public static void main (String args[])
    throws IOException, NullPointerException
    {

    //
    // PROGRAM LOGIC NOTE: This call to
    // DomainInfo.TheConnectionWasEstablished () MUST BE BEFORE the objects
    // are constructed!
    //

    //
    // Get the Connection Information.
    //
    // NOTE: This "should" only happen once.
    //

    if (!(DomainInfo.TheConnectionWasEstablished ()))
    {
    ServerConnectInfo = new TheServerConnectionInfoScreen
    (new javax.swing.JDialog (),
    AdminAreaConfig.GetSiteBanner () + " Connection Information");

    if (ServerConnectInfo == null)
    {
    throw new NullPointerException
    ("ServerConnectInfo is NULL (AdminClient.main)");
    }

    ServerConnectInfo.setVisible (true);
    }

    //
    // Create the needed objects.
    //

    MainFrameCloseLock = new Object();
    if (MainFrameCloseLock == null)
    {
    throw new NullPointerException
    ("MainFrameCloseLock is NULL (AdminClient.main)");
    }

    ThisUsersInfo = new AdminUserInfo ();
    if (ThisUsersInfo == null)
    {
    throw new NullPointerException
    ("ThisUsersInfo is NULL (AdminClient.main)");
    }

    ServerConnectInfo = new TheServerConnectionInfoScreen
    (new javax.swing.JDialog (),
    AdminAreaConfig.GetSiteBanner () +
    " Server Connection Information");
    if (ServerConnectInfo == null)
    {
    throw new NullPointerException
    ("ServerConnectInfo is NULL (AdminClient.main)");
    }

    TheUserLoginScreen = new AdminUserLoginScreen
    (new javax.swing.JDialog (),
    AdminAreaConfig.GetSiteBanner (),
    AdminAreaConfig.GetAreaName (),
    ThisUsersInfo);
    if (TheUserLoginScreen == null)
    {
    throw new NullPointerException
    ("TheUserLoginScreen is NULL (AdminClient.main)");
    }

    TheMainForm = new MainForm ();
    if (TheMainForm == null)
    {
    throw new NullPointerException
    ("TheMainForm is NULL (AdminClient.main)");
    }

    //
    //
    // Execute the main logic.
    //
    //

    //
    // Log the user in.
    //

    // TheUserLoginScreen.setVisible (true);

    //
    // The User closed the login window without logging in so shutdown.
    //

    if (!(ThisUsersInfo.GetUserIsLoggedIn ()))
    {
    // System.exit (0);
    }

    //System.out.println ("Users Name: " + ThisUsersInfo.GetName ());
    //System.out.println ("Users Initials: " + ThisUsersInfo.GetInitials ());
    //System.out.println ("System Wide Priv: " +
    // ThisUsersInfo.GetEnableSystemWidePrivilages ());

    //
    // The user is logged in so show the main screen.
    //

    TheMainForm.setVisible (true);

    Thread TheThread = new Thread()
    {
    public void run()
    {
    synchronized(MainFrameCloseLock)
    {
    while (TheMainForm.isVisible())
    {
    try
    {
    MainFrameCloseLock.wait();
    }
    catch (InterruptedException e)
    {
    }
    } // while (TheMainForm.isVisible())
    } // synchronized(MainFrameCloseLock)
    } // public void run()
    }; // Thread t = new Thread()

    TheThread.start();

    //
    // Wait for the user to close the main window.
    //

    TheMainForm.addWindowListener(new WindowAdapter()
    {
    @Override
    public void windowClosing(WindowEvent arg0)
    {
    synchronized (MainFrameCloseLock)
    {

    //
    // When they do shutdown thre program.
    //

    TheMainForm.setVisible(false);
    MainFrameCloseLock.notify();
    System.exit (0);
    }
    }
    }); // TheMainForm.addWindowListener(new WindowAdapter()
    } // public static void main (String args[])
    } // public class AdminClient
    The code compiles and create the jar without errors.

    But when I invoke the Jar file I get this:

    allan@INetMach:~/DevSFB$ java -jar AdminClient.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: AdminClient$1
    Caused by: java.lang.ClassNotFoundException: AdminClient$1
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:334)
    Could not find the main class: AdminClient. Program will exit.

    I do realize that the
    AdminClient$1
    indicates an anonymous inner class. But There should not be one. I tried placing the main program in a package but that did not work either.

    Any help in this matter will be appreciated.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Java is not finding the Main Class in my jar file...

    Use code tags, not quote tags, for posting code.
    BB Code List - Java Programming Forum

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Java is not finding the Main Class in my jar file...

    There should not be one.
    Did you look in the folder where the class files are written by the compiler to see if that class file was there?
    How are you creating the jar file?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. .jar file cant find main class
    By eLancaster in forum New To Java
    Replies: 3
    Last Post: 02-10-2011, 11:17 AM
  2. Pls. Help with finding Main Class
    By DetRich in forum New To Java
    Replies: 1
    Last Post: 11-09-2010, 05:27 PM
  3. Separate file for main and class
    By eel in forum New To Java
    Replies: 12
    Last Post: 09-18-2010, 08:24 AM
  4. Finding Jar files in a class file
    By bnrkcdc in forum Jobs Discussion
    Replies: 4
    Last Post: 09-08-2010, 01:46 PM
  5. Jar file could not find the main class
    By Collinryans in forum New To Java
    Replies: 3
    Last Post: 06-23-2010, 04:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •