Results 1 to 2 of 2
  1. #1
    Yasemin Gokce is offline Member
    Join Date
    Jun 2009
    Rep Power

    Default Compiling/Running Project in Command Line: "Could not find main class" Error


    I have a problem and I have looked at many places, including java-forums dot org slash "/new-java/2191-could-not-find-main-class-program-will-exit.html", but could not solve my problem (I have to type this way b/c I can't post links as a new member). I'd greatly appreciate your help.

    I am using Eclipse for a project for a project with 5 packages and a bunch of classes and interfaces. The following Jar Files are showing up under my project name in Eclipse.

    It's running fine in Eclipse, but for various reasons I have to compile and run it from the Windows command line. Compiling has been fine, I have just used
    Java Code:
    javac directoryOfFirstPackage\*.java directoryOfSecondPackage\*.java
    and so on.

    But when it comes to running the files, I am getting the a bunch of error lines and with
    Java Code:
    Could not find the main class: SendAMessage. Program will exit
    at the end.

    SendAMessage is the name of the class that I run in Eclipse and that runs fine. It has references to classes in its own package, as well as classes in the other four packages.

    What I have tried:
    1) I have added "C:\Sun\SDK\jdk\jre\bin", "C:\Sun\SDK\jdk\jre\lib", "C:\Sun\SDK\jdk\lib", "C:\Sun\SDK\jdk\bin" to the Path variable in Vista (My Computer > Properties > Advanced System Settings > Environment Variables) and when I type "path" in command line, my addenda show up. Nothing changes when I try to run.
    2) I have copied all the .jar files I could find from the SDK directories above into the same folder with my main class. Nothing changes.
    3) I have edited the .classpath file in the project directory. All the C:\ entries below are my additions. Didn't help...
    <?xml version="1.0" encoding="UTF-8"?>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="jars1" path="C:\Sun\SDK\lib"/>
    <classpathentry kind="jars2" path="C:\Sun\SDK\bin"/>
    <classpathentry kind="jars3" path="C:\Sun\SDK\jdk\bin"/>
    <classpathentry kind="jars4" path="C:\Sun\SDK\jdk\lib"/>
    <classpathentry kind="jars5" path="C:\Sun\SDK\jdk\jre\bin"/>
    <classpathentry kind="jars6" path="C:\Sun\SDK\jdk\jre\lib"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="output" path="bin"/>

    I greatly appreciate your help.

    Best regards,
    Last edited by Yasemin Gokce; 06-30-2009 at 10:59 AM. Reason: new thing I've tried and didn't help

  2. #2
    Yasemin Gokce is offline Member
    Join Date
    Jun 2009
    Rep Power

    Default Solved


    I solved my problem. It was a mix of 1) not editing the classpath variable correctly and 2) not restarting the command line for the changes to be effective. In case it helps anybody,

    java -classpath SourceDirectoryContainingTheFullPackageDirectory package1.package2.ClassIWantToRun

    This page: java dot sun dot com /j2se/1.3/docs/tooldocs/win32/classpath.html was most helpful.
    Last edited by Yasemin Gokce; 06-30-2009 at 02:32 PM. Reason: minor grammatical mistake

Similar Threads

  1. Replies: 6
    Last Post: 05-18-2010, 05:11 PM
  2. Replies: 12
    Last Post: 12-05-2008, 05:37 AM
  3. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

Posting Permissions

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