• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Need help urgently: problems compiling servlets

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,
I have been struggling for the last few hours trying to compile a servlet. I have read all the posting on this topic and think I have configured it correctly, yet I just can't get my servlet to compile. Each time, I get message saying that the servlet package is not found. The following are my system details:
1) I have successfully installed the latest (beta) version of Tomcat (without Apache web server) and TOMCAT_HOME points to the Tomcat directory. When I start Tomcat, I get these messages:
Starting service Tomcat-Apache
Apache Tomcat/4.0-b3
2) I have JDK version 1.3.0_02 and the following is how I have set my environment variables:
classpath=.;c:\tomcat\classes;c:\tomcat\lib\webserver.jar\c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\lib\servlet.jar;c:\jdk1.3.0_02\tools.jar;c:\tomcat\lib\jasper-run time.jar;c:\tomcat\lib\namingfactory.jar
JAVA_HOME=C:\JDK1.3.0_02
TOMCAT_HOME=C:\tomcat
3) I have put my servlet, SimpleServlet in the directory as suggested in the posts and different websites.
I will be grateful if someone helps me. I'm getting nervous becuase I have spent already too much time.
Thank you in advance,
Sanjeev
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You get this error when you do a javac SimpleServlet ?
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. When I do
>javac SimpleServlet.java
I get this compilation error. Just to test, I also put a "import javax.swing.*" in the source code and there was no compilation error for this line of code. Is not this strange?
Thank you for any further help,
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open a new dos window and do
set CLASSPATH=c:\tomcat\lib\servlet.jar
and then do your javac.. see if this works.
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mak,
Thanks for your reply. Now, the servlet is being compiled but I cannot find the class file. As a result when I put the following URL in the browser: http://localhost:8080/examples/servlet/SimpleServlet
I get the page not found error.
WHat is going on now?
Thanks for all your help.
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First and foremost, where is your .java file ? Is it it examples\web-inf\classes ? If so, the .class file should be in the same directory after compilation.
offhand, i'd say there is a package statement at the top of your java source.
if the first statement is
package yourpackage;
access the servlet as ..:8080/examples/servlet/yourpackage.SimpleServlet
Think this should work

Originally posted by Sanjeev Arora:
I cannot find the class file. As a result when I put the following URL in the browser: http://localhost:8080/examples/servlet/SimpleServlet
I get the page not found error.
WHat is going on now?
Thanks for all your help.
Sanjeev


 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is getting stranger and stranger. Yes Mak, I do have my SimpleServlet.java file in the web-inf/classes directory. And there is no package statement in my file. My first statement is "import javax.servlet.*".
Thanks for all your help. But, I am going to keep persisting till I run this servlet successfully.
Sanjeev
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sanjeev,
I think u r able to compile the SimpleServlet.If it is compiler then u will have .class file.So what i suggest is search for SimpleServlet.class and see where it is.Once u find that copy it in web-inf\classes(See time and date to make sure it is the right one i think u will have an idea about time when u compiler it.coz u may have other .class file with same name in diff. folders).hope this helps u.

-greddy
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is turning to be a most frustrating experience. This morning, my servlet would not compile. Nor would the ones supplied by Tomcat like CookieExample, SessionExample etc. As I have mentioned before, my servlet file, SimpleServlet.java is in the Tomcat\webapps\examples\WEB-INF\classes. My classpath variable also points to \tomcat\lib\servlet.jar (in addition to other directories) as Mak had suggested.
So, can anyone help me. Am I ever going to be able to run this servlet?
Thanks for your help in advance,
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you ARE going to run the servlet.
Looks like your 'default' classpath settings are causing the compile problems. So do as I suggested and open a dos window and set CLASSPATH=c:\tomcat\lib\servlet.jar This will change the classpath for that window.
Now, put your SimpleServlet.java in say, c:\javasrc and in the SAME window where you changed your classpath, go to c:\javasrc (cd \javasrc)
Here you do a javac SimpleServlet.java This will create a SimpleServlet.class in the same directory
Now copy the SimpleServlet.class as c:\tomcat\webapps\sandeep\web-inf\classes\SimpleServlet.class (create the directories if you have to) and start tomcat.
Go to http://localhost:8080/sandeep/servlet/SimpleServlet and you should see it executed.
[This message has been edited by Mak Bhandari (edited May 01, 2001).]
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did exactly as you advised. Yet, I still get the same compilation error. Please help.
Thanks,
Sanjeev
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Sanjeev
First of all set your "servlet.jar" classpath either in "autoexec.bat" for Win95,98 or in settings -system-environment-classpath for WinNT.
Secondly register your servlet in "Servlet.properties" file.
myserv=MyServlet.
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your exact compilation error
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your efforts to help me. There are 6 error messages and I am putting the first 2 because the others occur because the compiler can't locate the javax.servlet package.
Here are the first two errors:
SimpleServlet.java:2: package javax.servlet does not exist
SimpleServlet.java:3: package javax.servlet.http does not exist
These are caused by my two import statements:
import javax.servlet.*;
import javax.servlet.http.*;
Still hoping for a resolution to this problem.
Sanjeev
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somebody please help. I'm yet to run my servlet. I have already wasted 2 days trying to successfully compile my servlet.
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
make sure you have servlet.jar on your machine.. If so open a dos window and set CLASSPATH=c:\tomcat\lib\servlet.jar
CLASSPATH in caps and no space in H=c:\.. Then cd to your source directory and javac SimpleServlet.java
If it still doesnt compile, try this servlet. You cant get simpler than this and see if it compiles. If it doesn't post the entire error message here and i'll be happy to help u. You can edit -> copy from the dos window so do that rather than typing the error message.
 
gayatri reddy
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
R u able to run the servlet.Is it possible to post ur exact autoexec.bat(just copy every thing and past) file lets check one by one.
-greddy
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanjeev,
Here i am providing some steps for u. I hope u will succed in running a servlet after following this steps.

Win 95/98/ME Environment
------------------------
open your autoexec.bat file and type the following.
1)set JAVA_HOME=<replace this with your java directory>
2)set TOMCAT_HOME=<replace this with your tomcat directory>
3)set classpath=<tomcat_directory>\lib\servlet.jar;<java_directory>\src.jar;<java_directory>\lib\tools.jar;
After editing the autoexec.bat file, restart your system such that the changes u made to the system in autoexec.bat will take effect to the os.
****************************************************************
Win NT/2000
-----------
Open Control Panel and Select System icon on it.
Here u can set the environment variables for the system.
Double click on the Classpath and add
<tomcat_directory>\lib\servlet.jar;<java_directory>\src.jar;<java_directory>\lib\tools.jar;
the above lines.
In winnt environment there is no need to restart the system.
***************************************************************
After successfully setting up the environment, u have to configure the tomcat server. But for now, to test whether the servlet is running or not, you can follow these steps.
1) Write a servlet.
2) Dont forget to put it in package.
3) This servlet should be placed in <tomcat_directory>\webapps\examples\WEB-INF\classes.
(dont worry, i will tell you how to map your own context instead of </examples> )
So, for example if you wrote a servlet called HelloWorld.java then the directory hierarchy should be as follows.
c:\tomcat\webapps\examples\WEB-INF\classes\Hello\HelloWorld.java
Note: Here Hello is a package name.
4) Compile the servlet from the same directory.
5)After successfully compiling the java file you have to map the servlet in the web.xml file.
Note: web.xml file is located under c:\tomcat\webapps\examples\WEB-INF directory.
6) Edit the file and there u have to type this lines.
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>Hello.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
7)After making changes in web.xml file restart your tomcat server.
8) In the browser address type: http://localhost:8080/examples/HelloWorld
And thats it, you can find ur servlet running.
I hope u find this info useful.
Bye.
Loke.
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In spite of all your help, my servlet just will not compile. I did just as Mak Bhandari asked me and here's the list of what I did and the errors I got:
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\>set CLASSPATH=c:\tomcat\lib\servlet.jar
C:\>cd tomcat\webapps\examples\web-inf\classes
C:\Tomcat\webapps\examples\WEB-INF\classes>javac SimpleServlet.java
SimpleServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
SimpleServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
SimpleServlet.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class SimpleServlet
public class SimpleServlet extends HttpServlet
^
SimpleServlet.java:10: cannot resolve symbol
symbol : class HttpServletRequest
location: class SimpleServlet
public void doGet (HttpServletRequest request,
^
SimpleServlet.java:11: cannot resolve symbol
symbol : class HttpServletResponse
location: class SimpleServlet
HttpServletResponse response)
^
SimpleServlet.java:12: cannot resolve symbol
symbol : class ServletException
location: class SimpleServlet
throws ServletException, IOException
^
6 errors
C:\Tomcat\webapps\examples\WEB-INF\classes>
-----------------------------------------------------------------
This is my third day with this servlet and I had big dreams with Serlvets and JSPs. But one day, with your help, I will do it. But when.....?
Thank you,
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oookey.. you are using Win 2000.. Do a couple of things and lets see if we can help you..
First.. right click My Computer -> Environment and check the value of your classpath. Post it here.
Second.. open a dos window and do a dir /s servlet.jar Post that here
Third in that Dos window, set CLASSPATH=c:\<tomcat directory>\lib\ext\servlet.jar
then do a set | more and post the value of your CLASSPATH
Lets get your servlet squared away today.. Also, you had said that it compiled on day 1.. What changes did you do since then, if any?
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your continued interest, Mak. O.K. Here's how my classpath variable is set:
classpath=.;c:\tomcat\classes;c:\tomcat\lib\webserver.jar\c:\tomcat\lib\jasper.jar;c:\tomcat\lib\xml.jar;c:\tomcat\lib\servlet.jar;c:\jdk1.3.0_02\tools.jar;c:\tomcat\lib\jasper-run time.jar;c:\tomcat\lib\namingfactory.jar
Here's the output in my DOS session:
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\>dir/s servlet.jar
Volume in drive C has no label.
Volume Serial Number is 40CA-A82F
Directory of C:\J2EE\jdk1.2\bin\jakarta-tomcat\lib
04/18/2000 04:56p 40,809 servlet.jar
1 File(s) 40,809 bytes
Directory of C:\Tomcat\common\lib
04/02/2001 06:37p 74,964 servlet.jar
1 File(s) 74,964 bytes
Total Files Listed:
2 File(s) 115,773 bytes
0 Dir(s) 8,731,459,584 bytes free
C:\>set CLASSPATH=c:\tomcat\lib\ext\servlet.jar
C:\>set | more
classpath=c:\tomcat\lib\ext\servlet.jar
C:\>
------------------------------------------------------------
I have just posted the value of the classpath variable. Looks like I have multiple servlet.jar versions in different directories. Do you think this is causing the compilation problem. Also, I have JDK1.2 as well as JDK1.3.0_2. In addition, I also have J2EE. However, in my path and JAVA_HOME variables, I only point to JDK1.3.0_2.
Thanks,
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your tomcat directory is Tomcat
so open dos window, set CLASSPATH=c:\Tomcat\common\lib\servlet.jar and then javac your servlet.. You should be all set.
A more permanent solution would be to rename Tomcat directory to tomcat. But whast the common directory doin there ?
I suggest you go solution 1 first, compile and run your servlet and be happy.. Then you can square away your direcoty name/structure and classpaths
You should be all set !

[This message has been edited by Mak Bhandari (edited May 02, 2001).]
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mak, you've made my day, well almost! Thanks a ton for helping me successfully compile this servlet. Now, all that I need is to run it from the browser. Can you tell me how? Also proves that being an SCJP does not mean much!
Thanks,
Sanjeev
 
Maky Chopra
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gr888888888888888888
Now that you have compiled SimpleServlet.java into SimpleServlet.class, just copy the SimpleServlet.class into c:\Tomcat\webapps\sandeep\web-inf\classes\SimpleServlet.class
(hope you have the Tomcat\webapps directory already - the rest can be created by your)
Then start tomcat (thru the bin\startup.bat file) and acess tomcat by http://localhost:8080 This should show you the tomcat index page Then go to http://localhost:8080/sandeep/servlet/SimpleServlet and you see it being executed.
Best of luck.
 
Sanjeev Arora
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot to all those who helped me, in particular, Mak. Of course, my servlet was still not working this morning. So, I decided to utilize whatever little brains God gave me. I changed some configuration in the server.xml file and everything started working fine.
Thanks again,
Sanjeev
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mak,
Do you have any experience with RMI on Servlets?
 
rubbery bacon. rubbery tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic