Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

tomcat not finding classes

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat itself has nothing to do with compiling your servlets.

The servlet-api.jar file must be in the classpath when compiling.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manuel Comnenus
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again!

Steve
 
The knights of nee want a shrubbery. And a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic