Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Error allocating a servlet instance. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Error allocating a servlet instance." Watch "Error allocating a servlet instance." New topic
Author

Error allocating a servlet instance.

Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
Hey.

I seem to be having some trouble telling my Web.xml file where a servlet is.

I have two java package on my server, one with a package of java classes and one with a package of servlets.

They live in these directories:

WEB-INF\classes\MNOPackage\MNO (Java class package)
WEB-INF\classes\MNOPackage\MNOServlet (Java servlets package)

The servlets in the MNOServlet folder call classes in the MNO class package, and I have tested they work.

However when I try and run the servlet I have I get this error:


exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)

root cause

java.lang.NoClassDefFoundError: MNOPackage/MNOServlet/GetCurrentUserSettings (wrong name: MNOServlet/GetCurrentUserSettings)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1815)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:869)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1322)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1201)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)


Here is my Web.xml file.

Can anyone suggest what I might be doing wrong?

The name of the servlet I am trying to run is called GetCurrentUserSettings.


<servlet>
<servlet-name>MNOGetCurrentUserSettings</servlet-name>
<servlet-class>MNOPackage.MNOServlet.GetCurrentUserSettings</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MNOGetCurrentUserSettings</servlet-name>
<url-pattern>/current</url-pattern>
</servlet-mapping>


Thank you.

Darren
Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
I have also tried:


<servlet>
<servlet-name>MNOGetCurrentUserSettings</servlet-name>
<servlet-class>MNOPackage.MNOServlet.MNOServlet.GetCurrentUserSettings</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MNOGetCurrentUserSettings</servlet-name>
<url-pattern>/current</url-pattern>
</servlet-mapping>


I wondered if it needed its package path too.

But when I try this i get this error:


exception

javax.servlet.ServletException: Wrapper cannot find servlet class MNOPackage.MNOServlet.MNOServlet.GetCurrentUserSettings or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)

root cause

java.lang.ClassNotFoundException: MNOPackage.MNOServlet.MNOServlet.GetCurrentUserSettings
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1355)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1201)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Thread.java:595)



Darren
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Does the package declaration in your Java source file match the package hierarchy under WEB-INF/classes?

A mismatch is usually the cause of such an error.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
Everything seems to be ok.

Its the fact that its inside a package that it does not like.

If I make the whole thing not in a package it work.

But as soon as I place the files into seperate packages it cannot find it.

Do you have to do something different if you have packages as opposed to just having servlets on their own?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61180
    
  66

Please show us the package statement.

It's poor practice to not package classes and can lead to problems in many cases.
Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
What do you mean by the package statement exactly?

Sorry if thats a really dumb question...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12778
    
    5
MNOPackage.MNOServlet.MNOServlet.GetCurrentUserSettings

That says it is looking for a class named GetCurrentUserSettings
in which the source code has the package line:

package MNOPackage.MNOServlet.MNOServlet ;

Now, everybody to their own taste, but I am betting that the package line is actually:

package MNOPackage.MNOServlet ;

Therefore you need to figure out why the servlet is looking for something else.

Bill
Darren Jackson
Ranch Hand

Joined: Jan 18, 2007
Posts: 42
Yes you are correct.

Ive got it working now.

Thank you very much for your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error allocating a servlet instance.