File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to compile utility class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to compile utility class" Watch "how to compile utility class" New topic

how to compile utility class

david liu

Joined: Feb 20, 2002
Posts: 6
i want to compile a file with utility class
the code(file) is:
package moreservlets;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet3 extends HttpServlet {
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"
it worked well, and ServletUtilities.class was put in the directory of moreservlets , but when i try to compile by using the way above,there is error message,
" 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

Joined: Mar 22, 2000
Posts: 13037
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.
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...

*Assuming* you command prompt is at the above directory...

Type the following:
javac -classpath .;classes;ThePathTo_servlet.jar -d classes
[ March 26, 2002: Message edited by: Mike Curwen ]
I agree. Here's the link:
subject: how to compile utility class
It's not a secret anymore!