13 Replies Latest reply on Jul 29, 2010 1:57 PM by ssilvert

    JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f

    marcos_aps

      Hello, everybody!

       

      I've just migrated my application that was working in JBoss 6.0.0.M3 to JBoss 6.0.0.M4. I changed nothing in the application. But now I'm getting this error when I try to log in in the application:

       

      2010-07-29 10:23:28,000 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/solicitacoes].[Faces Servlet]] (http-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f{vfs:///C:/jboss-6.0.0.20100721-M4/server/default/conf/jboss-service.xml}

      at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.Alpha7]

      at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_20]

      at br.urca.web.jsf.UtilsJSF.getSessao(UtilsJSF.java:21) [:]

      at br.urca.solicitacoes.web.FuncionarioAutenticado.getInstancia(FuncionarioAutenticado.java:24) [:]

      at br.urca.solicitacoes.web.ControladorAcessoPagina.controlarAcessoPagina(ControladorAcessoPagina.java:28) [:]

      at br.urca.solicitacoes.web.SolicitacoesPhaseListener.afterPhase(SolicitacoesPhaseListener.java:47) [:]

      at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189) [:2.0.2-FCS]

      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107) [:2.0.2-FCS]

      at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110) [:2.0.2-FCS]

      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [:2.0.2-FCS]

      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312) [:2.0.2-FCS]

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.20100721-M4]

      at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:63) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.20100721-M4]

      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.20100721-M4]

      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:593) [:6.0.0.20100721-M4]

      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.CR3]

      at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.CR3]

      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.20100721-M4]

      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:93) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.20100721-M4]

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.20100721-M4]

      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.20100721-M4]

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.20100721-M4]

      at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.20100721-M4]

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.20100721-M4]

      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.20100721-M4]

      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [:6.0.0.20100721-M4]

      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.20100721-M4]

      at java.lang.Thread.run(Thread.java:619) [:1.6.0_20]

       

      What could it be?

       

      Thank you in advance.

       

      Marcos

        • 1. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
          ssilvert

          Are you bundling JSF with your WAR?

           

          We made big changes to JSF classloading in M4.  Here are the details:

          JSF on JBoss AS6

           

          Stan

          • 2. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
            marcos_aps

            Stan Silvert wrote:

             

            Are you bundling JSF with your WAR?

             

            We made big changes to JSF classloading in M4.  Here are the details:

            http://community.jboss.org/wiki/JSFonJBossAS6

             

            Stan

             

            No, I'm not bundling JSF with my WAR. I've never done that, even in my applications that runs on JBoss 4.2.3.GA. It seems that JSF is not being added to the WAR, but it is interesting that the login page loads correctly, but when I try to login I get the error.

             

            Marcos

            • 3. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
              jaikiran

              Looking at that stacktrace, it appears that the war specific classloader is not being used during that flow (don't know why). It looks like the server level classloader is being used instead.

              • 4. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                marcos_aps

                If it helps, I've attached the boot.log file.

                 

                Marcos

                • 5. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                  ssilvert

                  JSF is certainly being loaded because there are JSF classes in the stack trace.

                   

                  It looks to me like during login there is some call out to another class that can't find JSF.  This would be a class loaded outside of the WAR.  As jaikiran points out, it's using the server level classloader.

                   

                  There is code in the JSF Deployer that will add the JSF jars to all parent deployments of a WAR.  So for instance, if you package your WAR inside an EAR then JSF jars will be available at the EAR level.  However, if you are making a call to a sibling deployment or another deployment unit you could run into this kind of problem.

                   

                  To be honest, I haven't thought a lot about whether sibling deployments should share JSF in the same classloading space.  My inclination is that the answer is "no, they shouldn't", but this is a subtle change in behavior from past JBoss AS implementations.

                   

                  Stan

                  • 6. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                    marcos_aps

                    Stan Silvert wrote:

                     

                    ...


                    There is code in the JSF Deployer that will add the JSF jars to all parent deployments of a WAR.  So for instance, if you package your WAR inside an EAR then JSF jars will be available at the EAR level.  However, if you are making a call to a sibling deployment or another deployment unit you could run into this kind of problem.

                     

                    ...

                     

                    Stan

                     

                    I'm not making class to outside the WAR.

                     

                    I'm making the application available for you to see the problem for yourself.

                     

                    I'm using:
                    ----------

                    - JBoss 6.0.0.M4
                    - JDK 6 Update 20
                    - Windows XP SP3

                     

                    Instructions:
                    -------------
                    - Create the directory 'C:\Projeto\Java\Solicitacoes3' and unzip the zip file there.

                      You can use another directory, but you'll have to change the ant build file.

                     

                    - Place the jars located in 'C:\Projeto\Java\Solicitacoes3\additional-jars' in
                      <JBOSS_HOME>\common\lib.

                     

                    - Add this entry to <JBOSS_HOME>\server\default\conf\login-config.xml:
                      <application-policy name="solicitacoes">
                         <authentication>
                            <login-module code="br.urca.solicitacoes.ejb.seguranca.ModuloLogin"
                               flag="required" />
                         </authentication>
                      </application-policy>

                     

                    - I've also placed a datasouce (solicitacoes-ear-ds.xml) and a script.sql files.
                      You can change the datasource and use the database you want. I'm using MS SQL Server 2000.
                      Maybe you won't even need to use a database to see the problem.

                     

                    - Use the ant build.xml file located in 'C:\Projeto\Java\Solicitacoes3\solicitacoes-web'
                      to build and deploy the EAR file.

                     

                    Marcos

                     

                    Message was edited by: Marcos Antonio I removed the zip file, since the issue is already solved.

                    • 7. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                      ssilvert

                      Thanks Marcos.  I'll try it out this afternoon.

                      • 8. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                        ssilvert

                        Marcos Antonio wrote:

                         

                        2010-07-29 10:23:28,000 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/solicitacoes].[Faces Servlet]] (http-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f{vfs:///C:/jboss-6.0.0.20100721-M4/server/default/conf/jboss-service.xml}

                        at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.Alpha7]

                        at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_20]

                        at br.urca.web.jsf.UtilsJSF.getSessao(UtilsJSF.java:21) [:]

                        at br.urca.solicitacoes.web.FuncionarioAutenticado.getInstancia(FuncionarioAutenticado.java:24) [:]


                         

                        Can you tell me which class is being loaded on line 21 of UtilsJSF.getSessao()?  I think it will save a lot of time if I know this.

                         

                        Stan

                        • 9. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                          marcos_aps

                          Stan Silvert wrote:

                           

                          Marcos Antonio wrote:

                           

                           

                          2010-07-29 10:23:28,000 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/solicitacoes].[Faces Servlet]] (http-127.0.0.1-8080-1) Servlet.service() for servlet Faces Servlet threw exception: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f{vfs:///C:/jboss-6.0.0.20100721-M4/server/default/conf/jboss-service.xml}

                          at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:480) [jboss-classloader.jar:2.2.0.Alpha7]

                          at java.lang.ClassLoader.loadClass(ClassLoader.java:248) [:1.6.0_20]

                          at br.urca.web.jsf.UtilsJSF.getSessao(UtilsJSF.java:21) [:]

                          at br.urca.solicitacoes.web.FuncionarioAutenticado.getInstancia(FuncionarioAutenticado.java:24) [:]


                           

                          Can you tell me which class is being loaded on line 21 of UtilsJSF.getSessao()?  I think it will save a lot of time if I know this.

                           

                          Stan

                           

                          Yes, here is the code for the entire UtilsJSF class:

                           

                          /**
                          * @autor Marcos Antonio Pereira Silva
                          */

                           

                          package br.urca.web.jsf;

                           

                          import java.util.Map;

                           

                          import javax.faces.component.UIComponent;
                          import javax.faces.component.UIForm;
                          import javax.faces.context.FacesContext;

                           

                          public final class UtilsJSF
                          {
                          private UtilsJSF()
                          {
                          }

                          public static Map<String, Object> getSessao()
                          {
                            return FacesContext.getCurrentInstance().getExternalContext().

                                getSessionMap();
                          }

                          public static Map<String, Object> getRequisicao()
                          {
                            return FacesContext.getCurrentInstance().getExternalContext().

                                getRequestMap();
                          }

                          public static String obterIdFormulario(
                            FacesContext contexto, UIComponent componente)
                          {
                            UIComponent formulario = componente;
                            while (!(formulario instanceof UIForm))
                            {
                             formulario = formulario.getParent();
                            }
                            return formulario.getClientId(contexto);
                          }
                          }

                           

                          The getSessao() method is just one line of code (line 21), as you can see.

                           

                          Marcos

                          • 10. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                            ssilvert

                            Marcos Antonio wrote:

                             


                            - Place the jars located in 'C:\Projeto\Java\Solicitacoes3\additional-jars' in
                              <JBOSS_HOME>\common\lib.

                             

                            I see the problem now.  UtilsJSF is in common\lib.  So, it is loaded from outside of the WAR classloader.  With M4, JSF is only available in JSF WAR deployments and in ancestors of JSF deployments.  Since JSF is a web teir technology it should not be available from outside the web teir.  This is more restrictive than in the past, but it allows you to run different JSF implementations in different WARs.

                             

                            In general, you should not place jars in common\lib.  Those "additioinal-jars" should go in WEB-INF/lib or another location inside an EAR.

                             

                            Stan

                            • 11. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                              marcos_aps

                              Stan Silvert wrote:

                               

                              Marcos Antonio wrote:

                               


                              - Place the jars located in 'C:\Projeto\Java\Solicitacoes3\additional-jars' in
                                <JBOSS_HOME>\common\lib.

                               

                              I see the problem now.  UtilsJSF is in common\lib.  So, it is loaded from outside of the WAR classloader.  With M4, JSF is only available in JSF WAR deployments and in ancestors of JSF deployments.  Since JSF is a web teir technology it should not be available from outside the web teir.  This is more restrictive than in the past, but it allows you to run different JSF implementations in different WARs.

                               

                              In general, you should not place jars in common\lib.  Those "additioinal-jars" should go in WEB-INF/lib or another location inside an EAR.

                               

                              Stan

                               

                              Oh, very subtle issue. I'm going to test this, but the jar where is the UtilsJSF class (urca.jar) is a kinda of util jar that is (could be) used for every module in the EAR module. That's why I didn't place it in the WEB-INF/lib, for example. So I think I'll have to refector it and place everything that references JSF in another place. I'll tell you the results later.

                               

                              Marcos

                              • 12. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                                marcos_aps

                                Ok, I've just changed and tested it. I copied that UtilsJSF class to the web module, made everything reference it and it worked. The error is gone. Thank you, Stan!

                                 

                                Marcos

                                • 13. Re: JBoss 6.0.0.M4: java.lang.ClassNotFoundException: javax.faces.context.FacesContext from BaseClassLoader@def14f
                                  ssilvert

                                  Glad it's working.  If you want to package at the EAR level then you can put everything in <ear_root>/lib.

                                   

                                  Stan