This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes tomcat not finding classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat not finding classes" Watch "tomcat not finding classes" New topic
Author

tomcat not finding classes

Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
I am having trouble with what is probably the most basic of issues involving Tomcat 5.5.17.

I am using javac to compile a servlet and it is not able to find the packages javax.servlet.*
javax.servlet.http.*
java.io.*

I am trying to compile the servlet code from the Head First Servlet & JSP book (page 80). I am almost positive that the problem is that the packages above cannot be found because I receive the same errors when compiling without the servlet-api.jar

I am typing the command for javac, as provided on page 81, except that tomcat is my root directory. My os is WinXP.

Thanks,
Steve
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60749
    
  65

Tomcat itself has nothing to do with compiling your servlets.

The servlet-api.jar file must be in the classpath when compiling.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

At the top of the Servlets FAQ page there is a link to a page full of tips for compiling servlets and setting up your classpath.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
I have tried your suggestions and have not been able to solve the problem. I agree that the problem is not directly related to Tomcat. It's just a matter of the servlet-api.jar being in the tomcat\common\lib directory.

I am using the javac command essentially as suggested in the HFSJSP book. Here it is. Is something wrong here, or is there something else for me to check? Thanks.

my BeerSelect.java file is in the e:\myProjects\BeerV1 directory and I have made that directory the current directory.

javac -classpath \f:\tomcat\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Manuel Comnenus:

javac -classpath \f:\tomcat\common\lib\servlet-api.jar:classes:. -d classes src\com\example\web\BeerSelect.java


Two things:

1.) On windows systems, the delimter is a semi-colon ";", not a colon ":".

2.) Why is there a backslash at the beginning?
Starting a path with a backslash on windows means "go to the root of this
drive then look for a directory named "f:", then look for one named
"tomcat" etc.


Try:
-classpath f:\tomcat\common\lib\servlet-api.jar;classes;.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Also, just to clarify...
Your subject line is misleading.

It should be "javac not finding classes"
not
"tomcat not finding classes"
Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
Hi Ben,

As you stated, the problem was related to using a colon instead of a semicolon. And, yes, your suggestion for the wording of the problem is more appropriate.

I passed the SCJP by relying completely on an IDE. As a result, command-line issues were something of a weak area for me. I've decided to use the command-line for the SCWCD, at least until I really am familiar with the various options.

Thanks,
Steve
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

That's never a bad idea.
I don't like relying on IDEs myself.

By the way:
In Unix, the delimiter IS the colon.
Manuel Comnenus
Ranch Hand

Joined: Apr 26, 2006
Posts: 86
Thanks again!

Steve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: tomcat not finding classes
 
Similar Threads
creating .class file in Tomcat
Doubt from head first
compile problem w/ code in HFS book
compilation command
Compile Servlet