This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Cannot Compile Servlet with Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Cannot Compile Servlet with Tomcat" Watch "Cannot Compile Servlet with Tomcat" New topic
Author

Cannot Compile Servlet with Tomcat

Mickey Smith
Ranch Hand

Joined: Jun 26, 2006
Posts: 30
hi all,

I have written a servlet which resides in webapps/myApp/WEB-INF/classes/com/myappln/ in tomcat.

now whenever i invoke this servlet with the url http://localhost:8080/myApp/servlet/com.myappln.MyServlet.

Can this issue be related to the CLASSPATH VARIABLE.

Thanks in Advance....
[ July 12, 2006: Message edited by: Mickey Smith ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42362
    
  64
I think your question in missing half a sentence that describes what is actually happening...

If by "reside" you mean that that's the directory the servlet class is in, then it won't work. All classes need to be inside WEB-INF/classes or WEB-INF/lib.

It also looks like you might be using the invoker servlet - read this for why that's not such a good idea. You should properly map your servlets to URL patterns in the web.xml file.
[ July 12, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Mickey Smith
Ranch Hand

Joined: Jun 26, 2006
Posts: 30
i am sorry the full path is: webapps/myApp/WEB-INF/classes/com/myappln/

Do i need to comment the script which invokes invoker servlet inside conf/web.xml?
Mickey Smith
Ranch Hand

Joined: Jun 26, 2006
Posts: 30
I have disabled the invoker servlet even after that the problem is present. The main thing is that ClassLoader is unable to get the .class file because the servlet has not yet compiled. I have also set the CLASSPATH variable and all the settings are correct.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You have to compile the servlet yourself. The container won't do this for you.


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42362
    
  64
I don't understand how accessing the URL relates to compiling the servlets (servlets are not automatically compiled if they are accessed). The problem description is still missing something. Be aware that Tomcat does not use the CLASSPATH variable.

If you disable the invoker, then the URL will definitely not work (since it contains "/servlet/", which is what accesses the invoker servlet).
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As Satou has correctly noted, Tomcat does not compile Servlet code.
You need to do this yourself with Javac and place the .class file under WEB-INF/classes/{package structure}/{class files}

Moving to the Tomcat forum.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Consider Paul's rocket mass heater.
 
subject: Cannot Compile Servlet with Tomcat