The Artima Developer Community
Sponsored Link

Java Answers Forum
unable to compile servlet

4 replies on 1 page. Most recent reply: Nov 21, 2007 8:00 PM by Doug Gunnoe

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Christy Fong

Posts: 2
Nickname: servlet101
Registered: Nov, 2007

unable to compile servlet Posted: Nov 14, 2007 5:55 AM
Reply to this message Reply
Advertisement
Hi all,

I new to java servlet. I need help to compile the servlet code under Tomcat 5.028
Thanks.

===================================================
I used Tomcat 5.028 and installed in c:\program files\tomcat 5.0

The enivornment variables I set up as

classpath .;c:\j2sdk1.4.2_16\lib\tools.jar;c:\j2sdk1.4.2_16\bin;%CATALINA_HOME%\common\li b\servlet-api.jar;%CLASSPATH%

path %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\j2sdk1.4.2_16\ bin;d:\

JAVA_HOME C:\j2sdk1.4.2_16
CATALINE_HOME C:\program files\tomcat 5.0

//Ch1Servlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Ch1Servlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println("<html>" + "<body>" + "<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+ "<br>" + today + "</body>" + "</html>");

}
}


===================================================

This is my file structure: C:\project1
C:\project1\classes
C:\project1\src
C:\project1\etc

I placed Ch1Servlet.java in C:\project1\src;

I have no problem to compile Ch1Servlet.java from C:\project1\src without any error => javac Ch1Servlet.java


But if I used the suggestion from book:


C:\project1>javac -classpath /project1/classes/tomcat/common/lib/servlet-api.jar
-d classes src/Ch1Servlet.java

I got 5 errors as:

"package javax.servlet does not exist"
"package javax.servlet.http does not exist"
"HttpServletRequest, cannot resolve system", etc

My objective is to compile java servlet code(.class file) to c:\project1\classes


How to do it, or what I did wrong?
Please advise.


Doug Gunnoe

Posts: 22
Nickname: dgun
Registered: May, 2007

Re: unable to compile servlet Posted: Nov 16, 2007 2:14 AM
Reply to this message Reply
"/project1/classes/tomcat/common/lib/servlet-api.jar"

I'm not 100% sure what they are trying to do in the book and what packages they are trying to pick up in the above directory, but it looks to me that the file path is wrong.

Try changing the above to the path where servlet-api.jar resides on your system.

c:\program files\tomcat 5.0\*Whatever else*

And also, maybe try the full path here as well "src/Ch1Servlet.java" (<--I think your slash is backwards?)

instead: -d classes C:\project1\src\Ch1Servlet.java


Good luck.

Christy Fong

Posts: 2
Nickname: servlet101
Registered: Nov, 2007

Re: unable to compile servlet Posted: Nov 19, 2007 12:36 AM
Reply to this message Reply
Thank you for your reply.

I tried what you suggested:

C:\project1\> javac -classpath c:\program files\tomcat 5.0\common\lib\servlet-api.jar -d classes c:\project1\src\Ch1Servlet1.java

I got errors as:
javac: invalid flag: files\tomcat


I am going no where... My question is

How to compile servlet from command prompt and put the class file into the desire destination?

Thanks.

ss ni

Posts: 6
Nickname: sudhir0
Registered: Oct, 2007

Re: unable to compile servlet Posted: Nov 21, 2007 4:06 AM
Reply to this message Reply
You can compile a servlet just like an ordinary class.
just make sure that servlet-api.jar is in classpath.

http://www.jyog.com

Doug Gunnoe

Posts: 22
Nickname: dgun
Registered: May, 2007

Re: unable to compile servlet Posted: Nov 21, 2007 8:00 PM
Reply to this message Reply
> I got errors as:
> javac: invalid flag: files\tomcat

Oh. I'm sorry. I don't think the "classes" part should be in the argument. "classes" would have to refer to a directory.

Here is the -d switch, from sun's website

"-d directory
Set the destination directory for class files. The destination directory must already exist; javac will not create the destination directory. If a class is part of a package, javac puts the class file in a subdirectory reflecting the package name, creating directories as needed. For example, if you specify -d c:\myclasses and the class is called com.mypackage.MyClass, then the class file is called c:\myclasses\com\mypackage\MyClass.class.
If -d is not specified, javac puts the class file in the same directory as the source file.

Note that the directory specified by -d is not automatically added to your user class path."

And also, I noticed in your argument that you set the classptah with the "-classpath" and the directory with the "-d" switch, but where is the file you are compiling?

should it not be: javac someFile.java -classpath stuff -d stuff

?

Anyway, I hope that I am not doing more harm than good. :|

Flat View: This topic has 4 replies on 1 page
Topic: unable to compile servlet Previous Topic   Next Topic Topic: market bill

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use