9 Replies Latest reply on Mar 7, 2013 1:29 PM by jamezp

    ClassNotFoundException: org.apache.commons.logging.LogSource

    flp05

      Hi all,

       

      I'm having some problems configuring logging on Jboss AS 7.1.1.Final.

      I already read a few discussions about this but, I still cant' solve my problem.

       

      I tried two solutions:

       

       

      1. My first approach was to disable Jboss logging module:

                I add log4j.jar to the lib folder and in my jboss-deployment-structure.xml, I add:

          

                     ...
                     <deployment>
                           <exclusions>
                                 <module name="org.apache.log4j" />
                           </exclusions> 
                       </deployment>
             
                   <sub-deployment name="SDAWeb.war">
                           <exclusions>
                              <module name="org.apache.log4j" />
                            </exclusions>
                  </sub-deployment>
                     ---
      

       

                    However, I was gettinh this error:

                    

                     14:12:20,293 ERROR [stderr] (MSC service thread 1-3) log4j:WARN No appenders could be found for logger (fr.framework.hibernate.HibernateMappingScanner).
      
                     14:12:20,293 ERROR [stderr] (MSC service thread 1-3) log4j:WARN Please initialize the log4j system properly.
      
                     14:12:20,293 ERROR [stderr] (MSC service thread 1-3) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      

       

       

      2. My second approach was to remove log4j and commons-logging from my lib folder, and add this to my jboss-deployment-structure.xml (which shouldn't be needed since they are core dependencies):

       

                     <module name="org.apache.commons.logging" />
                     <module name="org.apache.log4j" />
      

       

                     However, I'm getting this error, when I try to acess a class from commons-logging:

       

                     java.lang.ClassNotFoundException: org.apache.commons.logging.LogSource 
      

       

                     Can this has something to do with the fact that I'm trying to access logging from a Java project ( deployed to the lib folder). Can a .jar from the lib folder still access Jboss modules like logging?

       

       

      Thanks,

      Luís

        • 1. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
          jamezp

          Are you including a log4j configuration file in your deployment? If you're excluding the servers log4j you need to provide log4j in your deployment as well as a configuration file so log4j can be configured.

           

          --

          James R. Perkins

          1 of 1 people found this helpful
          • 2. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
            flp05

            Thanks James.

             

            I know that, but I have multiple deploys wich share the same logging configuration and are distributed between multiple environments.

             

            Concluding, I need to let the logging configuration on the server. Either on standalone.xml or in the server configuration folder. Is this possible?

             

            Thanks again

            • 3. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
              jamezp

              Yes that's not a problem at all. Using standalone.xml will work if you don't exclude any of the logging dependencies. In JBoss AS 7.1.1.Final and greater log4j and commons.logging are added to each deployment by default. FWIW jboss-logging and slf4j are added as well.

               

              --

              James R. Perkins

              • 4. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                flp05

                That's exactly the problem. When I do that, my code doesn't work as expected.

                 

                When I create new logging configurations on runtime (with multiple logging files), it doesn't do what it should, and write all to the same file.

                (This is tested code, which use a framework and used to work perfectly in Jboss 4, so it's not a code problem).

                 

                Also, I'm getting this error:

                     java.lang.ClassNotFoundException: org.apache.commons.logging.LogSource

                 

                Thanks again for the help.

                • 5. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                  jamezp

                  Ah. It's because we hand off commons-logging to org.sfl4j.jcl-over-slf4j. That class doesn't exist in jcl-over-slf4j. I think it's been deprecated in commons-logging since 2004.

                   

                  You could try excluding org.apache.commons.logging from your deployment and providing commons-logging in your deployment. I think that should work.

                   

                  --

                  James R. Perkins

                  • 6. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                    flp05

                    Ok, that  corrects the ClassNotFoundException.

                     

                    However, I'm still unable to create new loggers at runtime for writing the logs in diferent files.

                     

                    Maybe because common-loggings are in my deployment, and common-loggings is the responsible (I think) of creating new loggers, it's causing a conflict.

                     

                    Can't I change the module of Jboss to use common-loggings? It's  a very big and old application, so change the source code will be almost impossible.

                     

                     

                    Thanks again,

                    Luís

                    • 7. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                      jamezp

                      I think you could change the module. You would just need to put a commons-logging JAR in modules/org/apache/commons/logging/main and edit the module.xml.

                       

                      --

                      James R. Perkins

                      • 8. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                        flp05

                        Thanks James.

                         

                        I wasn't able to add commons-logging as resource or as a dependency.

                         

                        I thing that, maybe this is because /org/apache/commons/logging/ is a <module-alias> and not a <module>.

                         

                        Any ideas?

                         

                         

                        Best regards,

                        Luís

                        • 9. Re: ClassNotFoundException: org.apache.commons.logging.LogSource
                          jamezp

                          Yes. You would have to change it to a module instead of a module-alias.

                           

                          Something like:

                          <?xml version="1.0" encoding="UTF-8"?>
                          <module xmlns="urn:jboss:module:1.1" name="org.apache.commons.logging"> 
                          
                              <resources>
                                  <resource-root path="commons-logging.jar"/>
                              </resources>
                          </module>
                          

                           

                          Just replace the commons-logging.jar with the name of the JAR you have in modules/org/apache/commons/logging/main.

                           

                          --

                          James R. Perkins