"No Class Definition Found" Error, classpath?

I am trying tocompile a extremely simple servlet example and I keep getting this "java.lang.NoClassDefFoundError".

Below is the CLASSPATH and the other environmental variables that java needs. Perhaps they are incorrect. I am editing them in the System Properties -> Environmental Variables, Windows XP.

Variable |Value

CLASSPATH

C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\el-api.jar

JAVA_HOME

C:\jre1.5.0_11

PATH

C:\jre1.5.0_11\bin

The error I am getting:

Exception in thread "main" java.lang.NoClassDefFoundError: C:\Program Files\Apac

he Software Foundation\Tomcat 6/0\webapps\ROOT\p1\scodes\HelloServlet/java

Tomcat is up and running, it is working fine with JSP scripts inside the HTML files..

I was using the steps provided in this Web page: http://www.coreservlets.com/Apache-Tomcat-Tutorial/

I am missing something, but what?

Any hint/help will be very very appreciated! :-)

--MMS--

[1194 byte] By [tofuwithcoffeea] at [2007-11-27 7:04:53]
# 1
http://forum.java.sun.com/thread.jspa?threadID=571464
skp71a at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Couple of questions- How are you compiling this class? From the command line? What command are you using?- JAVA_HOME should probably point at a JDK - not just a JRE. ie you need the compiler as well as the runtime engine.eg JAVA_HOME: C:\jdk1.5.0_11
evnafetsa at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I am compiling from the command prompt. I have tried giving as inputs:

java theServlet.java(I also moved the file where javac is)

java theServlet

java "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\p1\scodes\theServlet.java"

java C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\p1\scodes\theServlet

tofuwithcoffeea at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
The Java compiler binary is called javac, which is the one you should use to compile your java sources.javac mySource.java
kaderuda at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
When I use "javac" instead of "java" it gives me the following error:'javac' is not recognized as an internal or external command,operable program or batch file.
tofuwithcoffeea at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Then my guess is you only have the JRE (Java Runtime Environment) installed on your computer.

Check what directories you have under C:\Program Files\Java.

You should have something like this, in order to be able to compile Java sources. (the JDK is what contains, among other things, javac, the Java binary compiler)

jdk1.6.0_01

jre1.6.0_01

If you don't have the JDK (Java Development Kit), download it from http://java.sun.com

kaderuda at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hmm interesting... I have these two directories:

C:\jre1.5.0_11\bin

C:\Program Files\Java\jre1.5.0_11\bin

I either installed it twice, each one with different directories, or I installed the JRE and the JDK...

I will check out what happens if I edit the CLASSPATH, PATH to point to that other directory, and then I will try to compile from that other path

.............. I'll reply later.....

tofuwithcoffeea at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
I don't think neither of those contains parts of the JDK. The JRE only contains the Java Virtual Machine, which allows you to run the compiled, binary .class files.In order to compile Java source files (i.e MyClass.java), you need the JDK, which contains the compiler, javac.exe
kaderuda at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

OMG.. I have here a real mess...

C:\Program Files\Java\j2re1.4.2_14

C:\Program Files\Java\jdk1.6.0_01

C:\Program Files\Java\jre1.5.0_03

C:\Program Files\Java\jre1.5.0_11

I think the one in bold is the right path... let me check out...

................I'll reply later....

tofuwithcoffeea at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Take a look under the Add/Remove Programs control panel, and it should show you all the versions of Java that you have installed on your system (provided that you installed them with the standard installer)

Look around the J's of course

I have things like

J2SE Development Kit ...

J2SE Runtime Environment ...

Java 2 runtime environment ...

At a guess, seeing as you have JDK1.6, you probably have a JRE1.6 somewhere as well, because they come together.

I would suggest you uninstall a couple of the old ones. At least one of those version 1.5 runtime engines. And probably the 1.4 as well.

evnafetsa at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

Finally I could compile it!

Thanks to all of you!

CLASSPATH

C:\apache-tomcat-6.0.10\webapps\ROOT;C:\apache-tomcat-6.0.10\lib\servlet-api.jar;C:\apache-tomcat-6.0.10\lib\jsp-api.jar;C:\apache-tomcat-6.0.10\lib\el-api.jar

PATH

C:\Program Files\Java\jdk1.6.0_01\bin

JAVA_HOME

C:\Program Files\Java\jdk1.6.0_01

:->

tofuwithcoffeea at 2007-7-12 18:56:11 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...