• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error allocating a servlet instance.

 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darren Jackson
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64720
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are correct.

Ive got it working now.

Thank you very much for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic