This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes same error when using XP and Eclipse to run program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "same error when using XP and Eclipse to run program" Watch "same error when using XP and Eclipse to run program" New topic
Author

same error when using XP and Eclipse to run program

Derek B Smith
Greenhorn

Joined: Oct 08, 2006
Posts: 9
Hi!

I am using Eclipse IDE to practice Java 5 coding as well as the DOS command line. I am referencing HeadFirst Java for practice and the code error I cannot fix is this from the command line and from within Eclipse IDE:
Any help please?

thank you
derek


From Eclipse:
java.lang.NoClassDefFoundError: DooBee
Exception in thread "main"

From DOS:
C:\temp>javac DooBee.java

C:\temp>java DooBee
Exception in thread "main" java.lang.NoClassDefFoundError: DooBee

Here is my test code:

public class DooBee {
public static void main (String[] args) {
int x = 1;
while (x < 3) {
System.out.print("Doo");
System.out.print("Bee");
x += 1;
}

if (x == 3) {
System.out.print("Do");
} // end if
} // end main
} // end class

Here are my ENV variable:

C:\temp>echo %PATH%
C:\Perl\bin\;C:\ClarifyCRM12.0\Configurator\Common Files\CCAutomation;C:\ClarifyCRM12.0\Clarif
yClient;C:\Program Files\Compaq\Compaq Management Agents\Dmi\Win32\bin;C:\WINDOWS\system32;C:\
WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\IBM\Client Access;C:\Program Files\IBM\Clien
t Access\Shared;C:\Program Files\IBM\Client Access\Emulator;C:\Program Files\ShowCase STRATEGY
\bin;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\ENGLISH;C:\MSSQL7\BINN;C:\Program Files\M
icrosoft SQL Server\80\Tools\BINN;c:\progra~1\VIAVOI~1;C:\Sun\AppServer\jdk\bin\;C:\Sun\AppSer
ver\bin;C:\Program Files\websm\bin;C:\eclipse;C\Perl\bin;

C:\temp>echo %CLASSPATH%
C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib

C:\temp>echo %JRE_LIB%
C:\Sun\AppServer\jdk\jre\lib
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11356
    
  16

i'm assuming you're getting a class file. from the directory where that class file is (probably you're c:/temp), do this:

java -cp . DooBee


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

C:\temp>echo %CLASSPATH%
C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib


You don't have the current directory (".") in your classpath. When you try to run a Java program from the command line, Java will search for class files in the directories and JAR files that are in your classpath.

Add the current directory to your classpath:

set CLASSPATH=C:\Sun\AppServer\jdk\lib;C:\Sun\AppServer\jdk\jre\lib;.

Notice the ";." at the end.

(Note: If the CLASSPATH environment variable is not set at all, Java will look in the current directory by default).

You can also use the "-cp" (or "-classpath") option as Fred suggests, to set the classpath on the command line explicitly.
[ October 09, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Derek B Smith
Greenhorn

Joined: Oct 08, 2006
Posts: 9
that was it...thanks guys!

derek
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: same error when using XP and Eclipse to run program