5 Replies Latest reply on May 2, 2011 9:36 AM by Srinivasan Thoyyeti

    Problem deploying Servlets in jboss-5.1.0.GA

    Jeremy Goodell Newbie

      I recently installed jboss for a web project I'm working on. The other day I created a simple image servlet and  attempted to deploy it. I am getting an error on JBoss startup, and then  further errors on trying to invoke the servlet.

      I've spent about 12 hours searching the web for answers and  trying different scenarios. I posted this same question on stackoverflow, but got no answers.

       

      The servlet is com.controller.images.MyImageServlet, and looks like this:

       

      package com.controller.images;

      import javax.servlet.http.*;

      /**
      * Servlet implementation class MyImageServlet
      */
      public class MyImageServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;

          public MyImageServlet() {
              super();
          }

          // Process the HTTP Get request
            public void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
                   /* ... */
          }
      }


      The tags I've added to web.xml looks like this:

       

        <servlet>
          <servlet-name>ImageServlet</servlet-name>
          <servlet-class>com.controller.images.MyImageServlet</servlet-class>
        </servlet>
        <servlet-mapping>
          <servlet-name>ImageServlet</servlet-name>
          <url-pattern>/CERTIMAGE/*</url-pattern>
        </servlet-mapping>


      On server startup, this is the only indication in the log that  something is amiss:

       

      01:59:25,328 WARN  [JAXWSDeployerHookPreJSE] Cannot load servlet class: com.controller.images.MyImageServlet

       

      When I try the URL pattern (http://localhost:9980/CERTIMAGE/1), I get  the following stack trace in the log (and in the Browser):

       

      01:59:39,640 INFO  [[/]] Marking servlet ImageServlet as unavailable
      01:59:39,640 ERROR [[ImageServlet]] Allocate exception for servlet ImageServlet
      java.lang.ClassNotFoundException: com.controller.images.MyImageServlet
          at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
          at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:262)
          at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)
          at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1006)
          at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:777)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
          at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
          at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
          at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
          at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
          at java.lang.Thread.run(Thread.java:619)

      If I try the URL pattern again, I get the following message in the  log:

       

      09:33:32,390 INFO  [[ImageServlet]] Servlet ImageServlet is currently unavailable

      I have verified that MyImageServlet.class is in the WAR at  WEB-INF/classes/com/controller/images. As a matter of fact, I even added some  code to one of my JSPs to attempt to instantiate the Servlet and call  the doGet method. This actually works and outputs the correct debug  sequences to the log indicating that the Servlet constructor and doGet  methods were called.

       

      I also tried following some instructions for creating/deploying a  very simple HelloWorld servlet, and that has exactly the same problem.  Note that web.xml already contained a servlet put there by JBoss:  org.jboss.web.tomcat.service.StatusServlet -- that Servlet does not give  any errors in the log. As an experiment, I removed ".web" from that  path and ended up getting exactly the same error as I'm getting on my  Servlet. So it would appear that JBoss is not able to locate my Servlet  given the specified path. Just for kicks, I've tried all sorts of other  paths, like just plain MyImageServlet, controller.MyImageServlet, and  more. Also, the servlet was originally named ImageServlet, but I  attempted the name change thinking maybe there was some conflict with an  existing ImageServlet. In all cases, the behavior is the same.

       

      After all of my research, I would say that this appears to  be a problem with the JBoss servlet container, and I also learned that  JBoss 5.1.0.GA should come bundled with a tomcat servlet container. I  installed JBoss on my PC (Windows XP) myself less than 2 months ago  (from jboss.org) and used it pretty much as is. Note that I am running  on JDK 1.6, so I did use the jboss-jdk6 installation version. I am  running on Windows, but I also deploy to a Linux virtual dedicated  server. I deployed the current version of my program, including the  servlet to the Linux box, but I get the exact same errors. I'm reluctant  to just try reinstalling JBoss, since it's hard to place the blame on  the JBoss installation when I get the same errors on two completely  different installations.

       

      I am a bit suspicious of the bundled tomcat servlet container,  because using eclipse, I haven't been able to locate any indication that  there is a tomcat bundled into JBoss. I did locate servlet-api.jar in  the JBoss common/lib directory. This is on the eclipse build path.

       

      One possibly useful note: I had previously used a standalone tomcat  server for other projects using the same eclipse, so maybe it's some  sort of eclipse issue? But, as I said, I do get the same errors when I  deploy to the Linux server, and that deployment process just involves  ftping files to the server and then putting them into the deployed war  package and restarting JBoss.

       

      As an added note, I also recreated my app on top of a plain tomcat (no JBoss) installation and the servlet works with the given configuration. If I can't get resolution on this issue, I'll probably just switch to tomcat and not use JBoss. I'm not sure I have any need for the added functionality JBoss provides, although I do like the way it seems to more seamlessly integrate into eclipse with the JBoss tools. I was also considering making this into a Seam app, but that's probably not going to happen.

       

      Thanks for any help you can provide.

      Jeremy
        • 1. Re: Problem deploying Servlets in jboss-5.1.0.GA
          Peter Johnson Master

          Jeremy, welcome to the JBoss forums!

           

          According to the error message, the class file is not where you think it is. Unfortunately, I don't know enough about your setup to say what the exact problem is; the answers to the following questions should help:

           

          1) What is the full path for your JBoss AS installation?

          2) What is the full path for the WAR that was deployed into JBoss AS?

          3) Are you deploying manually, or are you using Eclipse to deploy?

          4) Please post the full contents of your deployed WAR. If the WAR is deployed as a file, use "jar -tf xxx.war", if deployed as an exploded directory, cd to that directory and enter "dir /b/s".

          1 of 1 people found this helpful
          • 2. Re: Problem deploying Servlets in jboss-5.1.0.GA
            Jeremy Goodell Newbie

            Thanks for the response. Unfortunately for some reason, I can no longer open the WEB-INF folder within my exploded war in the deploy directory. I can't delete it either, some sort of permission issues that are not obvious by looking at it. So it's basically completely unusable at the moment.

             

            Add to that the fact that I have this working great using a simple tomcat server, and I have decided to scrap jboss. It's just a lot of extra overhead that isn't providing me with any value at this point (not to mention this servlet problem). My tomcat server starts up in about one thirtieth the amount of time.

             

            To answer your question, the servlet class file was exactly where it was supposed to be in the exploded war in the jboss deploy area. Like I said, I was able to import it and utilize it from a jsp, so it really didn't seem to be a "location" issue.

             

            Thanks for trying,

            Jeremy

            • 3. Re: Problem deploying Servlets in jboss-5.1.0.GA
              Peter Johnson Master

              If you change your mind and decide to pursue this, just let me know. I have been fairly successfull with helping others over the forum to overcome strange problems such as this where very basic things that work for everyone else just do not seem to work. I suspect that if I sat at your PC for a minute or two I could identify the problem right away. Let me just say that I have deployed dozens, if not hundreds, of different applications (WARs, EARs, others) onto JBoss AS. The only time I got the error you described has been either the class file was not where I thought it was, or there was a typo somewhere.

               

              However, if you don't need the additional services that JBoss AS offers above what a servlet container such as Tomcat provides, then you really don't need JBoss AS (though I know that some of the JBoss engineers would disagree with me). Also, the 'web' configuration of JBoss AS provides just a servlet container plus JCA/JPA support, and it starts up much faster than the 'default' configuration; I have started ot use the 'web' configuration quite often.

              • 4. Problem deploying Servlets in jboss-5.1.0.GA
                Srinivasan Thoyyeti Newbie

                Hello Peter,

                 

                I have ran into same problem with Jboss 5.1.

                 

                In my case

                <servlet>

                      <servlet-name>GraphicsRouter</servlet-name>

                      <servlet-class>com.personal.appl.session.GraphicsRouter</servlet-class>

                  </servlet>

                  <servlet-mapping>

                      <servlet-name>GraphicsRouter</servlet-name>

                      <url-pattern>/graphics/</url-pattern>

                  </servlet-mapping>

                 

                 

                I have two different modules to be deployed into same application but has to be identified with different URLs.

                URL1: http://localhost:8080/ApplicationContext/   --- goes to welcome page and we route to module-1 home page

                 

                URL2: http://localhost:8080/ApplicationContext/graphics/ --  pattern matched but servlet failed to load.

                 

                Do I have to configure something for this possible ClassLoader Issue?

                Shall I have to define a RequestDispatcher?

                • 5. Problem deploying Servlets in jboss-5.1.0.GA
                  Srinivasan Thoyyeti Newbie

                  I have solved the issue ...

                  Seam src folders make diffrence in finding a servlet.

                   

                  Solution: Moved Servlet from "src/hot"  to "src/main"