I am new to this but need to learn fast for a project at work. I am going throught the HF Servlets & JSP book and am doing the Beer tutorial. I am working in Windows 2K as this is the OS at work. The problem is that the BeerSelect servlet will not compile as it cannot find the BeerExpert class with the import statement. Everything is set up exactly as shown in the book. I have found in the earlier exercises that I have to change the compile commands slightly from those shown in the book (I believe the examples are screenshots from Mac OS X)to work in Windows. Here is the command and output:
C:\MyProjects\beerV1>javac -classpath C:\tomcat\common\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java src\com\example\web\BeerSelect.java:3: package classes.com.example.model does not exist import classes.com.example.model.*; ^ src\com\example\web\BeerSelect.java:20: cannot find symbol symbol : class BeerExpert location: class com.example.web.BeerSelect BeerExpert be = new BeerExpert(); ^ src\com\example\web\BeerSelect.java:20: cannot find symbol symbol : class BeerExpert location: class com.example.web.BeerSelect BeerExpert be = new BeerExpert(); ^ 3 errors
The only thing on your classpath is servlet-api.jar. If other classes are needed you will need to add them to your classpath.
If you aren't familiar with setting up classpaths, it would be worth your while to break away from servlets and follow a Java tutorial or two. The "First Cup Of Java" tutorial on http://java.sun.com is excellent.
Most servlet books assume some familiarity with Java and don't go into a lot of detail abou this sort of thing.
Hi! i request you one thing if you don't mind plz send me the meterial "First Cup of Java".i went through sun's site but i was failed to download.i'm looking forward for that meterial sir. Thanking you.. Thanks&Regards, G Sirish Reddy., email@example.com.
Joined: Jun 12, 2005
I thought about it and figured it out. This worked:
If you have a small number of dependencies this technique is fine. As the number grows, however, it can become a bit cumbersome. The easiest way to handle this is to set your CLASSPATH environment variable and let the compiler find the libraries that way.
Glad you've got it working. [ June 12, 2005: Message edited by: Ben Souther ]