Results 1 to 2 of 2
- 06-30-2009, 11:40 AM #1Member
- Join Date
- Jun 2009
- Rep Power
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 usedJava Code:
javac directoryOfFirstPackage\*.java directoryOfSecondPackage\*.java
But when it comes to running the files, I am getting the a bunch of error lines and withJava Code:
Could not find the main class: SendAMessage. Program will exit
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.
Last edited by Yasemin Gokce; 06-30-2009 at 11:59 AM. Reason: new thing I've tried and didn't help
- 06-30-2009, 03:32 PM #2Member
- Join Date
- Jun 2009
- Rep Power
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 03:32 PM. Reason: minor grammatical mistake
- By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 06:11 PM
- By Tenn in forum New To JavaReplies: 12Last Post: 12-05-2008, 06:37 AM
- By Welsh in forum New To JavaReplies: 7Last Post: 01-25-2008, 01:12 AM
- By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 08:10 AM
- By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 11:55 PM