Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » trouble running servlet on tomcat server in eclipse
trouble running servlet on tomcat server in eclipse [message #192828] Fri, 18 May 2007 19:05 Go to next message
Eclipse User
Originally posted by: starkweatherd.cox.net

Hi,

I am having trouble running a servlet created in a Dynamic Web Project using
the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I can run a
relatively simple servlet just fine, as soon as I try to do some
initialization that depends on external lib jar files and my own class
files, I get the NoClassDefFoundError message. When looking in the browser
at http://localhost:8080/servletname, I get the http status error 500. This
seems to be special to servlets, since I can create a class with a static
main() method and it works just fine. If anyone has any ideas, I would be
forever in your debt. If not, could anyone point me to a tutorial that
involves creating a servlet that depends on initialization or external
library files? thanks.


Here is the stack trace that I get. This not only comes up when I try to
run the servlet by right-clicking on it, but also when I start the server.

May 18, 2007 2:51:02 PM org.apache.catalina.core.AprLifecycleListener
lifecycleEvent

INFO: The Apache Tomcat Native library which allows optimal performance in
production environments was not found on the java.library.path: F:\Program
Files\Java\jre1.5.0_10\bin;.;F:\WINDOWS\system32;F:\WINDOWS; F:\texmf\miktex\bin;F:\WINDOWS\system32;F:\WINDOWS;F:\WINDOW S\System32\Wbem;f:\matlab_sv13\bin\win32;g:\matlab_sv13\bin\ win32;F:\Program
Files\Microsoft SQL Server\90\Tools\binn\;G:\Sun\AppServer\bin;f:\Program
Files\MySQL Server 5.0\bin

May 18, 2007 2:51:03 PM org.apache.coyote.http11.Http11BaseProtocol init

INFO: Initializing Coyote HTTP/1.1 on http-9080

May 18, 2007 2:51:03 PM org.apache.catalina.startup.Catalina load

INFO: Initialization processed in 1438 ms

May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardService start

INFO: Starting service Catalina

May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardEngine start

INFO: Starting Servlet Engine: Apache Tomcat/5.5.23

May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardHost start

INFO: XML validation disabled

May 18, 2007 2:51:05 PM org.apache.catalina.core.ApplicationContext log

SEVERE: StandardWrapper.Throwable

java.lang.NoClassDefFoundError:
com/topcoder/util/config/UnknownNamespaceException

at
com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)

at javax.servlet.GenericServlet.init(GenericServlet.java:212)

at
org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)

at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)

at
org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)

at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)

at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)

at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)

at org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)

at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)

at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)

May 18, 2007 2:51:05 PM org.apache.catalina.core.StandardContext
loadOnStartup

SEVERE: Servlet /ContactFormWebProject threw load() exception

java.lang.NoClassDefFoundError:
com/topcoder/util/config/UnknownNamespaceException

at
com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)

at javax.servlet.GenericServlet.init(GenericServlet.java:212)

at
org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)

at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)

at
org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)

at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)

at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)

at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)

at org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)

at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)

at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)

May 18, 2007 2:51:06 PM org.apache.coyote.http11.Http11BaseProtocol start

INFO: Starting Coyote HTTP/1.1 on http-9080

May 18, 2007 2:51:06 PM org.apache.jk.common.ChannelSocket init

INFO: JK: ajp13 listening on /0.0.0.0:9009

May 18, 2007 2:51:06 PM org.apache.jk.server.JkMain start

INFO: Jk running ID=0 time=0/78 config=null

May 18, 2007 2:51:06 PM org.apache.catalina.storeconfig.StoreLoader load

INFO: Find registry server-registry.xml at classpath resource

May 18, 2007 2:51:06 PM org.apache.catalina.startup.Catalina start

INFO: Server startup in 3172 ms
Re: trouble running servlet on tomcat server in eclipse [message #192852 is a reply to message #192828] Fri, 18 May 2007 19:56 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1305
Registered: July 2009
Senior Member
Any external jars your project needs and won't be provided by the server
(i.e. isn't in common/lib or similar directory) will need to be included
on the J2EE Module Dependencies page of the Properties dialog for the
project. Use the "Add Jars..." button if the jar is somewhere in your
workspace and the "Add External Jars..." button if it is outside of your
workspace.

Cheers,
Larry

David Starkweather wrote:
> Hi,
>
> I am having trouble running a servlet created in a Dynamic Web Project using
> the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I can run a
> relatively simple servlet just fine, as soon as I try to do some
> initialization that depends on external lib jar files and my own class
> files, I get the NoClassDefFoundError message. When looking in the browser
> at http://localhost:8080/servletname, I get the http status error 500. This
> seems to be special to servlets, since I can create a class with a static
> main() method and it works just fine. If anyone has any ideas, I would be
> forever in your debt. If not, could anyone point me to a tutorial that
> involves creating a servlet that depends on initialization or external
> library files? thanks.
>
>
> Here is the stack trace that I get. This not only comes up when I try to
> run the servlet by right-clicking on it, but also when I start the server.
>
> May 18, 2007 2:51:02 PM org.apache.catalina.core.AprLifecycleListener
> lifecycleEvent
>
> INFO: The Apache Tomcat Native library which allows optimal performance in
> production environments was not found on the java.library.path: F:\Program
> Files\Java\jre1.5.0_10\bin;.;F:\WINDOWS\system32;F:\WINDOWS; F:\texmf\miktex\bin;F:\WINDOWS\system32;F:\WINDOWS;F:\WINDOW S\System32\Wbem;f:\matlab_sv13\bin\win32;g:\matlab_sv13\bin\ win32;F:\Program
> Files\Microsoft SQL Server\90\Tools\binn\;G:\Sun\AppServer\bin;f:\Program
> Files\MySQL Server 5.0\bin
>
> May 18, 2007 2:51:03 PM org.apache.coyote.http11.Http11BaseProtocol init
>
> INFO: Initializing Coyote HTTP/1.1 on http-9080
>
> May 18, 2007 2:51:03 PM org.apache.catalina.startup.Catalina load
>
> INFO: Initialization processed in 1438 ms
>
> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardService start
>
> INFO: Starting service Catalina
>
> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardEngine start
>
> INFO: Starting Servlet Engine: Apache Tomcat/5.5.23
>
> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardHost start
>
> INFO: XML validation disabled
>
> May 18, 2007 2:51:05 PM org.apache.catalina.core.ApplicationContext log
>
> SEVERE: StandardWrapper.Throwable
>
> java.lang.NoClassDefFoundError:
> com/topcoder/util/config/UnknownNamespaceException
>
> at
> com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)
>
> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
>
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)
>
> at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)
>
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)
>
> at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)
>
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>
> at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)
>
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>
> at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)
>
> at org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)
>
> at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)
>
> at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>
> at java.lang.reflect.Method.invoke(Unknown Source)
>
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)
>
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)
>
> May 18, 2007 2:51:05 PM org.apache.catalina.core.StandardContext
> loadOnStartup
>
> SEVERE: Servlet /ContactFormWebProject threw load() exception
>
> java.lang.NoClassDefFoundError:
> com/topcoder/util/config/UnknownNamespaceException
>
> at
> com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)
>
> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
>
> at
> org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)
>
> at org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)
>
> at
> org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)
>
> at org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)
>
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>
> at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)
>
> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>
> at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)
>
> at org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)
>
> at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)
>
> at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>
> at java.lang.reflect.Method.invoke(Unknown Source)
>
> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)
>
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)
>
> May 18, 2007 2:51:06 PM org.apache.coyote.http11.Http11BaseProtocol start
>
> INFO: Starting Coyote HTTP/1.1 on http-9080
>
> May 18, 2007 2:51:06 PM org.apache.jk.common.ChannelSocket init
>
> INFO: JK: ajp13 listening on /0.0.0.0:9009
>
> May 18, 2007 2:51:06 PM org.apache.jk.server.JkMain start
>
> INFO: Jk running ID=0 time=0/78 config=null
>
> May 18, 2007 2:51:06 PM org.apache.catalina.storeconfig.StoreLoader load
>
> INFO: Find registry server-registry.xml at classpath resource
>
> May 18, 2007 2:51:06 PM org.apache.catalina.startup.Catalina start
>
> INFO: Server startup in 3172 ms
>
>
Re: trouble running servlet on tomcat server in eclipse [message #192868 is a reply to message #192828] Fri, 18 May 2007 20:25 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. Keyser
Messages: 878
Registered: July 2009
Senior Member
David Starkweather wrote:
> Hi,
>
> I am having trouble running a servlet created in a Dynamic Web Project using
> the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I can run a
> relatively simple servlet just fine,

Any chance you could post that code? I cannot even get a simple servlet to do anything at all: see
thread "newbie question: how to find who's using a port?". Did you use the way-out-of-date tutorial?
Or some other starting point? If the latter, a pointer would be appreciated. (I'm also using Eclipse
3.2, and have Tomcat 5.5 installed -- not clear if I am strictly-speaking "using" Tomcat 5.5, since
nothing happens ...)

thanks,
Paul
Re: trouble running servlet on tomcat server in eclipse [message #192876 is a reply to message #192852] Fri, 18 May 2007 20:32 Go to previous messageGo to next message
Eclipse User
Originally posted by: starkweatherd.cox.net

Thank you very much! I had included the files as part of the Buildpath, but
had neglected the J2EE module dependencies on the Project's Properties
window. Works like a charm now.

Warm Regards,
David.

"Larry Isaacs" <Larry.Isaacs@sas.com> wrote in message
news:f2l0e9$1og$1@build.eclipse.org...
> Any external jars your project needs and won't be provided by the server
> (i.e. isn't in common/lib or similar directory) will need to be included
> on the J2EE Module Dependencies page of the Properties dialog for the
> project. Use the "Add Jars..." button if the jar is somewhere in your
> workspace and the "Add External Jars..." button if it is outside of your
> workspace.
>
> Cheers,
> Larry
>
> David Starkweather wrote:
>> Hi,
>>
>> I am having trouble running a servlet created in a Dynamic Web Project
>> using the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I
>> can run a relatively simple servlet just fine, as soon as I try to do
>> some initialization that depends on external lib jar files and my own
>> class files, I get the NoClassDefFoundError message. When looking in
>> the browser at http://localhost:8080/servletname, I get the http status
>> error 500. This seems to be special to servlets, since I can create a
>> class with a static main() method and it works just fine. If anyone has
>> any ideas, I would be forever in your debt. If not, could anyone point
>> me to a tutorial that involves creating a servlet that depends on
>> initialization or external library files? thanks.
>>
>>
>> Here is the stack trace that I get. This not only comes up when I try to
>> run the servlet by right-clicking on it, but also when I start the
>> server.
>>
>> May 18, 2007 2:51:02 PM org.apache.catalina.core.AprLifecycleListener
>> lifecycleEvent
>>
>> INFO: The Apache Tomcat Native library which allows optimal performance
>> in production environments was not found on the java.library.path:
>> F:\Program
>> Files\Java\jre1.5.0_10\bin;.;F:\WINDOWS\system32;F:\WINDOWS; F:\texmf\miktex\bin;F:\WINDOWS\system32;F:\WINDOWS;F:\WINDOW S\System32\Wbem;f:\matlab_sv13\bin\win32;g:\matlab_sv13\bin\ win32;F:\Program
>> Files\Microsoft SQL Server\90\Tools\binn\;G:\Sun\AppServer\bin;f:\Program
>> Files\MySQL Server 5.0\bin
>>
>> May 18, 2007 2:51:03 PM org.apache.coyote.http11.Http11BaseProtocol init
>>
>> INFO: Initializing Coyote HTTP/1.1 on http-9080
>>
>> May 18, 2007 2:51:03 PM org.apache.catalina.startup.Catalina load
>>
>> INFO: Initialization processed in 1438 ms
>>
>> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardService start
>>
>> INFO: Starting service Catalina
>>
>> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardEngine start
>>
>> INFO: Starting Servlet Engine: Apache Tomcat/5.5.23
>>
>> May 18, 2007 2:51:04 PM org.apache.catalina.core.StandardHost start
>>
>> INFO: XML validation disabled
>>
>> May 18, 2007 2:51:05 PM org.apache.catalina.core.ApplicationContext log
>>
>> SEVERE: StandardWrapper.Throwable
>>
>> java.lang.NoClassDefFoundError:
>> com/topcoder/util/config/UnknownNamespaceException
>>
>> at
>> com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)
>>
>> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
>>
>> at
>> org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)
>>
>> at
>> org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)
>>
>> at
>> org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)
>>
>> at
>> org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)
>>
>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>>
>> at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)
>>
>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>>
>> at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)
>>
>> at
>> org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)
>>
>> at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)
>>
>> at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>
>> at java.lang.reflect.Method.invoke(Unknown Source)
>>
>> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)
>>
>> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)
>>
>> May 18, 2007 2:51:05 PM org.apache.catalina.core.StandardContext
>> loadOnStartup
>>
>> SEVERE: Servlet /ContactFormWebProject threw load() exception
>>
>> java.lang.NoClassDefFoundError:
>> com/topcoder/util/config/UnknownNamespaceException
>>
>> at
>> com.designblast.questionform.ContactFormServlet.init(Contact FormServlet.java:59)
>>
>> at javax.servlet.GenericServlet.init(GenericServlet.java:212)
>>
>> at
>> org.apache.catalina.core.StandardWrapper.loadServlet(Standar dWrapper.java:1139)
>>
>> at
>> org.apache.catalina.core.StandardWrapper.load(StandardWrappe r.java:966)
>>
>> at
>> org.apache.catalina.core.StandardContext.loadOnStartup(Stand ardContext.java:3956)
>>
>> at
>> org.apache.catalina.core.StandardContext.start(StandardConte xt.java:4230)
>>
>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>>
>> at org.apache.catalina.core.StandardHost.start(StandardHost.jav a:736)
>>
>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.j ava:1014)
>>
>> at org.apache.catalina.core.StandardEngine.start(StandardEngine .java:443)
>>
>> at
>> org.apache.catalina.core.StandardService.start(StandardServi ce.java:448)
>>
>> at org.apache.catalina.core.StandardServer.start(StandardServer .java:700)
>>
>> at org.apache.catalina.startup.Catalina.start(Catalina.java:552 )
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>
>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>
>> at java.lang.reflect.Method.invoke(Unknown Source)
>>
>> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:2 95)
>>
>> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:43 3)
>>
>> May 18, 2007 2:51:06 PM org.apache.coyote.http11.Http11BaseProtocol start
>>
>> INFO: Starting Coyote HTTP/1.1 on http-9080
>>
>> May 18, 2007 2:51:06 PM org.apache.jk.common.ChannelSocket init
>>
>> INFO: JK: ajp13 listening on /0.0.0.0:9009
>>
>> May 18, 2007 2:51:06 PM org.apache.jk.server.JkMain start
>>
>> INFO: Jk running ID=0 time=0/78 config=null
>>
>> May 18, 2007 2:51:06 PM org.apache.catalina.storeconfig.StoreLoader load
>>
>> INFO: Find registry server-registry.xml at classpath resource
>>
>> May 18, 2007 2:51:06 PM org.apache.catalina.startup.Catalina start
>>
>> INFO: Server startup in 3172 ms
>>
Re: trouble running servlet on tomcat server in eclipse [message #192884 is a reply to message #192868] Sat, 19 May 2007 01:00 Go to previous messageGo to next message
Eclipse User
Originally posted by: starkweatherd.cox.net

Sure, I'll post the code. But it is just a basic servlet. The trouble I
had was mostly with getting the settings right in eclipse. A few pointers
that helped me:


1. Define a new server (new->other->server->server) and follow the wizard
to point to the tomcat installation. I am using tomcat 5.5 and installed it
as windows service, which is the easiest way. I tried putting it on linux.
While the tomcat server works in linux, the eclipse I have on my debian
linux machine could not read the conf file of the tomcat installation. I
tried fiddling with the server.xml file but to no avail.

2. Create a Dynamic web app and settings on properties tab: (right click on
project->properties)

Set the server runtime. A list should appear there of all servers
that you created.
Set the buildpath for the source folders, libraries, etc. to be able to
compile
the project.
Set the J2EE module dependencies. This is the step i missed for
external jar file dependencies. Important for running
the servlet.

Make sure to put your source files in the source package folder. Your
servlet files must be in their source package folders which get compiled to
the build/classes folder. Without the the server that you defined in steps
1 and 2, do not expect the project to recognize the servlet api, because all
the jar files for the J2EE spec come with the servlet container.

Be sure to start the server in the server window. Apparently when you
start it in eclipse, it starts its own instance of the server,
"independent" of whether or not you run it in the windows service.

I hope this helps. If I missed something that does not make any sense, just
let me know again, and i'll try to clarify. This is what I found to work.

Good luck,
David.


"Paul Keyser" <rolarenfan@earthlink.net> wrote in message
news:f2l235$g4b$1@build.eclipse.org...
> David Starkweather wrote:
>> Hi,
>>
>> I am having trouble running a servlet created in a Dynamic Web Project
>> using the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I
>> can run a relatively simple servlet just fine,
>
> Any chance you could post that code? I cannot even get a simple servlet to
> do anything at all: see thread "newbie question: how to find who's using a
> port?". Did you use the way-out-of-date tutorial? Or some other starting
> point? If the latter, a pointer would be appreciated. (I'm also using
> Eclipse 3.2, and have Tomcat 5.5 installed -- not clear if I am
> strictly-speaking "using" Tomcat 5.5, since nothing happens ...)
>
> thanks,
> Paul
Re: trouble running servlet on tomcat server in eclipse [message #192892 is a reply to message #192884] Sat, 19 May 2007 01:04 Go to previous messageGo to next message
Eclipse User
Originally posted by: starkweatherd.cox.net

oops, i forgot the code for the servlet. Here's the code I used to test it
first.

<code>

package com.designblast.questionform;


import java.io.PrintWriter;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


/**

* Servlet implementation class for Servlet: ContactFormServlet

*/

public class ContactFormServlet extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet {

private String header = "This is my header!";


public ContactFormServlet() {

super();

}


public void destroy() {

// TODO Auto-generated method stub

super.destroy();

}


protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

// TODO Auto-generated method stub

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.print("<HTML>");

out.println("<HEAD><TITLE>Hello ...</TITLE></HEAD>");

out.println("<BODY>" + header + "</BODY>");

out.println("</HTML>");

out.close();


}


protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {

// TODO Auto-generated method stub

}


public void init() throws ServletException {

// TODO Auto-generated method stub

super.init();



}

}

"David Starkweather" <starkweatherd@cox.net> wrote in message
news:f2li77$v0b$1@build.eclipse.org...
> Sure, I'll post the code. But it is just a basic servlet. The trouble I
> had was mostly with getting the settings right in eclipse. A few pointers
> that helped me:
>
>
> 1. Define a new server (new->other->server->server) and follow the wizard
> to point to the tomcat installation. I am using tomcat 5.5 and installed
> it as windows service, which is the easiest way. I tried putting it on
> linux. While the tomcat server works in linux, the eclipse I have on my
> debian linux machine could not read the conf file of the tomcat
> installation. I tried fiddling with the server.xml file but to no avail.
>
> 2. Create a Dynamic web app and settings on properties tab: (right click
> on project->properties)
>
> Set the server runtime. A list should appear there of all servers
> that you created.
> Set the buildpath for the source folders, libraries, etc. to be able to
> compile the project.
> Set the J2EE module dependencies. This is the step i missed for
> external jar file dependencies. Important for running
> the servlet.
>
> Make sure to put your source files in the source package folder. Your
> servlet files must be in their source package folders which get compiled
> to the build/classes folder. Without the the server that you defined in
> steps 1 and 2, do not expect the project to recognize the servlet api,
> because all the jar files for the J2EE spec come with the servlet
> container.
>
> Be sure to start the server in the server window. Apparently when you
> start it in eclipse, it starts its own instance of the server,
> "independent" of whether or not you run it in the windows service.
>
> I hope this helps. If I missed something that does not make any sense,
> just let me know again, and i'll try to clarify. This is what I found
> to work.
>
> Good luck,
> David.
>
>
> "Paul Keyser" <rolarenfan@earthlink.net> wrote in message
> news:f2l235$g4b$1@build.eclipse.org...
>> David Starkweather wrote:
>>> Hi,
>>>
>>> I am having trouble running a servlet created in a Dynamic Web Project
>>> using the Apache Tomcat 5.5 server. (I am using Eclipse 3.2) While I
>>> can run a relatively simple servlet just fine,
>>
>> Any chance you could post that code? I cannot even get a simple servlet
>> to do anything at all: see thread "newbie question: how to find who's
>> using a port?". Did you use the way-out-of-date tutorial? Or some other
>> starting point? If the latter, a pointer would be appreciated. (I'm also
>> using Eclipse 3.2, and have Tomcat 5.5 installed -- not clear if I am
>> strictly-speaking "using" Tomcat 5.5, since nothing happens ...)
>>
>> thanks,
>> Paul
>
>
Re: trouble running servlet on tomcat server in eclipse [message #192907 is a reply to message #192884] Mon, 21 May 2007 15:32 Go to previous messageGo to next message
Paul E. Keyser is currently offline Paul E. Keyser
Messages: 878
Registered: July 2009
Senior Member
Thanks, but ...

> 1. Define a new server (new->other->server->server) and follow the wizard
> to point to the tomcat installation. I am using tomcat 5.5 and installed it
> as windows service, which is the easiest way.

That was, as far as I can recall, exactly what I did, except that I have no recollection of whether
I installed Tomcat as a service or not -- any way to find out? (It is on WinXP.)

BTW, somehow or other, Eclipse created for me a "Servers" project -- what's that about? (I can see
that it contains some sort of stuff for the Tomcat 5.5, but what is its function/ purpose/ use?)

> 2. Create a Dynamic web app and settings on properties tab: (right click on
> project->properties)
>

There are four kinds of "new Web project" wizards in my Eclipse, and I don't recall which one I used
(the wizard specified in the tutorial, "J2EE Web Project", is not available to me); probably it
matters, so now I try again, using "Dyn. Web" as you say, and am offered a choice of
"Configurations", either "<custom>" or "Web project with XDoclet authoring support" (googling
XDoclet does not tell me much); I choose the "XDoclet", but when the project is created, I get: "The
preferences for the xdoclet runtime does not point to a valid installation." Since I have no clue
how to fix that, I delete and try "<custom>", which seems simply to be the same thing less the
mysterious XDoclet; at least it compiles. This whole wizard looks unfamiliar, so I guess I used
something else before.

> Set the server runtime. A list should appear there of all servers
> that you created.

I guess in "Project properties", same as I did before? Anyway, there I do it.

> Set the buildpath for the source folders, libraries, etc. to be able to
> compile the project.

Um, that wasn't part of the tutorial, and I didn't do it (usually I work with PDE, where I don't
need to set this sort of thing explicitly), so here I am not sure: what do I need to add and do I
just do it in the Project Properties -> Java Build Path? (In PDE, I add dependencies to the
manifest.mf, using that editor, but here the Manifest.mf is abroken little fragment.)

> Set the J2EE module dependencies. This is the step i missed for
> external jar file dependencies. Important for running the servlet.
>

Ditto ...

> Make sure to put your source files in the source package folder. Your
> servlet files must be in their source package folders which get compiled to
> the build/classes folder. Without the the server that you defined in steps
> 1 and 2, do not expect the project to recognize the servlet api, because all
> the jar files for the J2EE spec come with the servlet container.
>

Yep, that's where I had my source files in the non-functional project; also, since there was no
package structure whatsoever, I created the usual PDE-style nested set of packages under the src
folder, i.e. in this current case, "dyn.web.proj"; the class I created extended HttpServlet. Now I
paste in your sample code (also thanks!) and it all compiles -- so maybe somehow I didn't need to
add anything to the project properties -> build path?

> Be sure to start the server in the server window. Apparently when you
> start it in eclipse, it starts its own instance of the server,
> "independent" of whether or not you run it in the windows service.
>

Yes, this is very puzzling to me; I repeatedly but not invariably got "port in use" errors, no
matter what I did. I have long since set the ports on the server known to Eclipse to be 18080,
18005, 18009.

Anyway, when I start my server, Eclispe claims all well; when I try putting
http://localhost:18080/ContactFormServlet OR http://localhost:18080/dyn.web.proj.ContactFormServlet
into a browser, I get the same 404 "service not available".

Paul
Re: trouble running servlet on tomcat server in eclipse [message #193023 is a reply to message #192907] Wed, 23 May 2007 15:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: starkweatherd.cox.net

To see if it's installed as a service, just go to control panel->admin
tools->services and apache should appear on the list of services. You can
start/stop/restart from here. When you create a new server in eclipse, you
can see it in the projects view as a project. Apparently, eclipse views the
servers as a project against which your webapp is compiled against.

I used the xdoclet option when setting up dynamic web app. you have to
download the xdoclet and point eclipse to it.
(windows->preferences->xdoclet). I do not know what xdoclet does yet, but
the tutorial I used told me to do it that way. (I think I used some
tutorial on eclipse.org, the one with the snoopservlet.) xdoclet is a
project on sourceforge.net.
(http://xdoclet.sourceforge.net/xdoclet/install.html).

In setting the build path, click on the source tab and add your source
folders that are in the project, and the library folder for adding your jar
and external library jars.

With regard to the last step, I have gotten that last message with regards
to the port numbers ("ports in use") whenever I had the tomcat server
running as a windows service and i tried to start the server in eclipse at
the same time. This happened even when I would try stopping the main
server. Apparently, WindowsXP doesnt "give back" those port numbers.
(There must be some sort of tool to manage port numbers, like netstat in
linux.) Try rebooting your system, make sure the tomcat doesnt start
automatically on system startup (There's some configuration in tomcat to do
that.), then start the server within eclipse.

David


"Paul Keyser" <rolarenfan@earthlink.net> wrote in message
news:f2se23$5ov$1@build.eclipse.org...
>
> Thanks, but ...
>
>> 1. Define a new server (new->other->server->server) and follow the
>> wizard to point to the tomcat installation. I am using tomcat 5.5 and
>> installed it as windows service, which is the easiest way.
>
> That was, as far as I can recall, exactly what I did, except that I have
> no recollection of whether I installed Tomcat as a service or not -- any
> way to find out? (It is on WinXP.)
>
> BTW, somehow or other, Eclipse created for me a "Servers" project --
> what's that about? (I can see that it contains some sort of stuff for the
> Tomcat 5.5, but what is its function/ purpose/ use?)
>
>> 2. Create a Dynamic web app and settings on properties tab: (right click
>> on project->properties)
>>
>
> There are four kinds of "new Web project" wizards in my Eclipse, and I
> don't recall which one I used (the wizard specified in the tutorial, "J2EE
> Web Project", is not available to me); probably it matters, so now I try
> again, using "Dyn. Web" as you say, and am offered a choice of
> "Configurations", either "<custom>" or "Web project with XDoclet authoring
> support" (googling XDoclet does not tell me much); I choose the "XDoclet",
> but when the project is created, I get: "The preferences for the xdoclet
> runtime does not point to a valid installation." Since I have no clue how
> to fix that, I delete and try "<custom>", which seems simply to be the
> same thing less the mysterious XDoclet; at least it compiles. This whole
> wizard looks unfamiliar, so I guess I used something else before.
>
>> Set the server runtime. A list should appear there of all servers
>> that you created.
>
> I guess in "Project properties", same as I did before? Anyway, there I do
> it.
>
>> Set the buildpath for the source folders, libraries, etc. to be able
>> to compile the project.
>
> Um, that wasn't part of the tutorial, and I didn't do it (usually I work
> with PDE, where I don't need to set this sort of thing explicitly), so
> here I am not sure: what do I need to add and do I just do it in the
> Project Properties -> Java Build Path? (In PDE, I add dependencies to the
> manifest.mf, using that editor, but here the Manifest.mf is abroken little
> fragment.)
>
>> Set the J2EE module dependencies. This is the step i missed for
>> external jar file dependencies. Important for running the servlet.
>>
>
> Ditto ...
>
>> Make sure to put your source files in the source package folder. Your
>> servlet files must be in their source package folders which get compiled
>> to the build/classes folder. Without the the server that you defined in
>> steps 1 and 2, do not expect the project to recognize the servlet api,
>> because all the jar files for the J2EE spec come with the servlet
>> container.
>>
>
> Yep, that's where I had my source files in the non-functional project;
> also, since there was no package structure whatsoever, I created the usual
> PDE-style nested set of packages under the src folder, i.e. in this
> current case, "dyn.web.proj"; the class I created extended HttpServlet.
> Now I paste in your sample code (also thanks!) and it all compiles -- so
> maybe somehow I didn't need to add anything to the project properties ->
> build path?
>
>> Be sure to start the server in the server window. Apparently when you
>> start it in eclipse, it starts its own instance of the server,
>> "independent" of whether or not you run it in the windows service.
>>
>
> Yes, this is very puzzling to me; I repeatedly but not invariably got
> "port in use" errors, no matter what I did. I have long since set the
> ports on the server known to Eclipse to be 18080, 18005, 18009.
>
> Anyway, when I start my server, Eclispe claims all well; when I try
> putting http://localhost:18080/ContactFormServlet OR
> http://localhost:18080/dyn.web.proj.ContactFormServlet into a browser, I
> get the same 404 "service not available".
>
> Paul
Re: trouble running servlet on tomcat server in eclipse [message #193032 is a reply to message #193023] Wed, 23 May 2007 17:19 Go to previous message
Larry Isaacs is currently offline Larry Isaacs
Messages: 1305
Registered: July 2009
Senior Member
David Starkweather wrote:
> To see if it's installed as a service, just go to control panel->admin
> tools->services and apache should appear on the list of services. You can
> start/stop/restart from here.

I think Paul's Tomcat server in Eclipse has "1" pre-pended to the port
numbers, so they don't conflict with the service. This should make them
fully independent, though they both use the same Tomcat installation for
the jars that constitute the Tomcat server.

When you create a new server in eclipse, you
> can see it in the projects view as a project. Apparently, eclipse views the
> servers as a project against which your webapp is compiled against.

See: http://www.eclipse.org/webtools/faq/TomcatServerFAQ.php#info _06

>
> I used the xdoclet option when setting up dynamic web app. you have to
> download the xdoclet and point eclipse to it.
> (windows->preferences->xdoclet). I do not know what xdoclet does yet, but
> the tutorial I used told me to do it that way. (I think I used some
> tutorial on eclipse.org, the one with the snoopservlet.) xdoclet is a
> project on sourceforge.net.
> (http://xdoclet.sourceforge.net/xdoclet/install.html).

XDoclet is tool to build a web.xml from annotations found in your
servlets and other javax.servlet type classes. XDoclet will completely
rewrite the web.xml each time its builder runs, so you can't manually
make modifications to the file and expect them not to disappear. You
have to place custom content in separate files which will get merged
into the web.xml when it builds. None of the WTP wizards which might
make changes to your web.xml know how to do this, so they aren't going
to work as desired with XDoclet enabled. I would recommend not using it
unless you have a specific need.

>
> In setting the build path, click on the source tab and add your source
> folders that are in the project, and the library folder for adding your jar
> and external library jars.

For Dynamic Web Projects, it is better to add external library jars
using the J2EE Module Dependencies page (assuming they aren't already
provided by the server). That way they are automatically added to the
build path and will be included in the WEB-INF/lib when the project is
published to a server or exported as a war file.

>
> With regard to the last step, I have gotten that last message with regards
> to the port numbers ("ports in use") whenever I had the tomcat server
> running as a windows service and i tried to start the server in eclipse at
> the same time. This happened even when I would try stopping the main
> server. Apparently, WindowsXP doesnt "give back" those port numbers.
> (There must be some sort of tool to manage port numbers, like netstat in
> linux.) Try rebooting your system, make sure the tomcat doesnt start
> automatically on system startup (There's some configuration in tomcat to do
> that.), then start the server within eclipse.

Changing the port numbers on one of the servers can allow both to run
simultaneously. The gotcha is that if you often manually enter the
URL's with the port, you have to be sure to enter the right one or your
request goes to the wrong server. :(

Cheers,
Larry

>
> David
>
>
> "Paul Keyser" <rolarenfan@earthlink.net> wrote in message
> news:f2se23$5ov$1@build.eclipse.org...
>> Thanks, but ...
>>
>>> 1. Define a new server (new->other->server->server) and follow the
>>> wizard to point to the tomcat installation. I am using tomcat 5.5 and
>>> installed it as windows service, which is the easiest way.
>> That was, as far as I can recall, exactly what I did, except that I have
>> no recollection of whether I installed Tomcat as a service or not -- any
>> way to find out? (It is on WinXP.)
>>
>> BTW, somehow or other, Eclipse created for me a "Servers" project --
>> what's that about? (I can see that it contains some sort of stuff for the
>> Tomcat 5.5, but what is its function/ purpose/ use?)
>>
>>> 2. Create a Dynamic web app and settings on properties tab: (right click
>>> on project->properties)
>>>
>> There are four kinds of "new Web project" wizards in my Eclipse, and I
>> don't recall which one I used (the wizard specified in the tutorial, "J2EE
>> Web Project", is not available to me); probably it matters, so now I try
>> again, using "Dyn. Web" as you say, and am offered a choice of
>> "Configurations", either "<custom>" or "Web project with XDoclet authoring
>> support" (googling XDoclet does not tell me much); I choose the "XDoclet",
>> but when the project is created, I get: "The preferences for the xdoclet
>> runtime does not point to a valid installation." Since I have no clue how
>> to fix that, I delete and try "<custom>", which seems simply to be the
>> same thing less the mysterious XDoclet; at least it compiles. This whole
>> wizard looks unfamiliar, so I guess I used something else before.
>>
>>> Set the server runtime. A list should appear there of all servers
>>> that you created.
>> I guess in "Project properties", same as I did before? Anyway, there I do
>> it.
>>
>>> Set the buildpath for the source folders, libraries, etc. to be able
>>> to compile the project.
>> Um, that wasn't part of the tutorial, and I didn't do it (usually I work
>> with PDE, where I don't need to set this sort of thing explicitly), so
>> here I am not sure: what do I need to add and do I just do it in the
>> Project Properties -> Java Build Path? (In PDE, I add dependencies to the
>> manifest.mf, using that editor, but here the Manifest.mf is abroken little
>> fragment.)
>>
>>> Set the J2EE module dependencies. This is the step i missed for
>>> external jar file dependencies. Important for running the servlet.
>>>
>> Ditto ...
>>
>>> Make sure to put your source files in the source package folder. Your
>>> servlet files must be in their source package folders which get compiled
>>> to the build/classes folder. Without the the server that you defined in
>>> steps 1 and 2, do not expect the project to recognize the servlet api,
>>> because all the jar files for the J2EE spec come with the servlet
>>> container.
>>>
>> Yep, that's where I had my source files in the non-functional project;
>> also, since there was no package structure whatsoever, I created the usual
>> PDE-style nested set of packages under the src folder, i.e. in this
>> current case, "dyn.web.proj"; the class I created extended HttpServlet.
>> Now I paste in your sample code (also thanks!) and it all compiles -- so
>> maybe somehow I didn't need to add anything to the project properties ->
>> build path?
>>
>>> Be sure to start the server in the server window. Apparently when you
>>> start it in eclipse, it starts its own instance of the server,
>>> "independent" of whether or not you run it in the windows service.
>>>
>> Yes, this is very puzzling to me; I repeatedly but not invariably got
>> "port in use" errors, no matter what I did. I have long since set the
>> ports on the server known to Eclipse to be 18080, 18005, 18009.
>>
>> Anyway, when I start my server, Eclispe claims all well; when I try
>> putting http://localhost:18080/ContactFormServlet OR
>> http://localhost:18080/dyn.web.proj.ContactFormServlet into a browser, I
>> get the same 404 "service not available".
>>
>> Paul
>
>
Previous Topic:Dependent Projects
Next Topic:Workaround for Web-Tools falure to run JSP's
Goto Forum:
  


Current Time: Sun Sep 21 18:16:00 GMT 2014

Powered by FUDForum. Page generated in 0.02848 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software