| Author |
how to compile utility class
|
david liu
Greenhorn
Joined: Feb 20, 2002
Posts: 6
|
|
i want to compile a file with utility class the code(file) is: -------------------------- package moreservlets; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloServlet3 extends HttpServlet { ........... out.println(ServletUtilities.headWithTitle(title)); ........... } the code of utility class -------------- package moreservlets; import javax.servlet.*; import javax.servlet.http.*; public class ServletUtilities { ........... } first of all ,i compile the utility class by typing " javac -d C:\jakarta-tomcat-4.0.3\webapps\ROOT\WEB-INF\classes ServletUtilities.java" it worked well, and ServletUtilities.class was put in the directory of moreservlets , but when i try to compile HelloServlet3.java by using the way above,there is error message, "HelloServlet3.java:23: cannot resolve symbol symbol : variable ServletUtilities location: class moreservlets.HelloServlet3 out.println(ServletUtilities.headWithTitle(title) + ^ 1 error " what is the correct way of compiling utility class?? these two codes are example codes(no error)
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12265
|
|
Personally, I use ANT to control all compilation, copying of compiled class files to the right directory etc etc. - it lets you build specific classpaths so you won't see compilation errors like that. Furthermore, I keep all servlet source code completely separate from the Tomcat directories. Things get way too complicated when you mix Java source into your servlet directories. Think of the trouble you will have installing the next upgrade of Tomcat when your source is all mixed in. Bill
|
Java Resources at www.wbrogden.com
|
 |
Mike Curwen
Ranch Hand
Joined: Feb 20, 2001
Posts: 3695
|
|
It's related to classpath. Your servlet cannot find the utility class file you just compiled. *Assuming* your java source file is at... C:\jakarta-tomcat-4.0.3\webapps\ROOT\WEB-INF\ *Assuming* you command prompt is at the above directory... Type the following: javac -classpath .;classes;ThePathTo_servlet.jar -d classes HelloServlet3.java [ March 26, 2002: Message edited by: Mike Curwen ]
|
 |
 |
|
|
subject: how to compile utility class
|
|
|