7 Replies Latest reply on Jul 3, 2014 8:07 AM by abhijeetayade

    Load a JBoss module (e.g. log4j) as a dependency in web apps

    Laura delli Paoli Master

      Hello everybody,

      I was trying to load log4j (but I'd like to do the same thing with hibernate and other libraries) as a dependency of my web application (app.war).

      As first attempt I create a file named jboss-deployment-structure.xml in the WebContent/WEB-INF folder of my Dynamic Web Project:

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

      <deployment>

        <dependencies>

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

        </dependencies>

      </deployment>

      </jboss-deployment-structure>

       

      but I got this error:

       

      11:27:19,036 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyApp]] (MSC service thread 1-8) Servlet /MyApp threw load() exception: java.lang.Error: Unresolved compilation problems:

        The import org.apache.log4j cannot be resolved

        Logger cannot be resolved

       

      Then I added log4j to the application server global modules:

      <subsystem xmlns="urn:jboss:domain:ee:1.0">

                  <global-modules>

                      <module name="org.apache.log4j" slot="main"/>

                  </global-modules>

              </subsystem>

      but the error was the same.

       

      My last attempt was adding it to MANIFEST.MF:

      Dependencies: org.apache.log4j

      with the same result

       

      Can anyone help Me?

       

      Laura

        • 1. Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
          Frank Langelage Master

          Laura, for access of module org.apache.log4j there is nothing to do, this dependency is always available.

          See Implicit module dependencies for deployments - JBoss AS 7.0 - Project Documentation Editor.

          No dependencies, not needed triggers.

          That's also my experience for all JBoss AS 7 and WildFly versions.

           

          May be it's best to get step back, omit jboss-deployment-structure.xml and any Dependency entries in manifest files, class-path entries, global modules etc.

          If problem persists, show us again what you get, the stacktrace, etc.

          • 2. Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
            Laura delli Paoli Master

            Hi Frank.

             

            Here's my trace:

             

            11:27:01,546 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem

            11:27:01,552 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem

            11:27:01,740 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem

            11:27:01,741 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension

            11:27:01,740 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.

            11:27:01,761 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem

            11:27:01,981 INFO  [org.jboss.as.security] (MSC service thread 1-4) JBAS013100: Current PicketBox version=4.0.7.Final

            11:27:03,057 INFO  [org.jboss.as.connector] (MSC service thread 1-3) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)

            11:27:11,059 INFO  [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service

            11:27:11,857 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-7) JBAS015400: Bound mail session [java:jboss/mail/Default]

            11:27:11,860 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.3)

            11:27:13,297 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080

            11:27:14,358 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-3) JBoss Web Services - Stack CXF Server 4.0.2.GA

            11:27:15,071 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/myDsDev]

            11:27:15,399 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-8) JBAS015012: Started FileSystemDeploymentService for directory C:\JBoss Application Server\jboss-as-7.1.1.Final\standalone\deployments

            11:27:15,413 INFO  [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on /127.0.0.1:4447

            11:27:15,413 INFO  [org.jboss.as.remoting] (MSC service thread 1-6) JBAS017100: Listening on /127.0.0.1:9999

            11:27:16,090 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015876: Starting deployment of "MyApp.war"

            11:27:17,999 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) JBAS018567: Deployment "deployment.MyApp.war" is using a private module ("org.apache.log4j:main") which may be changed or removed in future versions without notice.

            11:27:18,000 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) JBAS018567: Deployment "deployment.MyApp.war" is using a private module ("org.apache.log4j:main") which may be changed or removed in future versions without notice.

            11:27:18,071 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) JBAS018567: Deployment "deployment.MyApp.war" is using a private module ("org.apache.httpcomponents:main") which may be changed or removed in future versions without notice.

            11:27:18,076 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) JBAS018567: Deployment "deployment.MyApp.war" is using a private module ("org.apache.httpcomponents:main") which may be changed or removed in future versions without notice.

            11:27:18,079 WARN  [org.jboss.as.dependency.private] (MSC service thread 1-5) JBAS018567: Deployment "deployment.MyApp.war" is using a private module ("org.apache.log4j:main") which may be changed or removed in future versions without notice.

            11:27:19,032 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyApp]] (MSC service thread 1-8) Marking servlet StartupServlet as unavailable

            11:27:19,036 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyApp]] (MSC service thread 1-8) Servlet /MyApp threw load() exception: java.lang.Error: Unresolved compilation problems:

              The import org.apache.log4j cannot be resolved

              Logger cannot be resolved

             

             

              at org.test.myApp.applicationLayer.servlet.StartupServlet.<init>(StartupServlet.java:15) [classes:]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_23]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_23]

              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_23]

              at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_23]

              at org.jboss.msc.value.ConstructedValue.getValue(ConstructedValue.java:61)

              at org.jboss.as.naming.ValueManagedReferenceFactory.getReference(ValueManagedReferenceFactory.java:49)

              at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:90) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

              at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

              at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

              at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

              at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.deployment.component.WebComponentInstantiator$1.<init>(WebComponentInstantiator.java:57) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.deployment.component.WebComponentInstantiator.getReference(WebComponentInstantiator.java:55) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.deployment.WebInjectionContainer.instantiate(WebInjectionContainer.java:99) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:78) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.web.deployment.WebInjectionContainer.newInstance(WebInjectionContainer.java:72) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1156) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_23]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_23]

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]

             

             

            11:27:19,171 INFO  [org.jboss.web] (MSC service thread 1-8) JBAS018210: Registering web context: /MyApp

            11:27:19,178 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015951: Admin console listening on http://127.0.0.1:9990

            11:27:19,179 INFO  [org.jboss.as] (MSC service thread 1-3) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 32703ms - Started 181 of 259 services (76 services are passive or on-demand)

            11:27:19,316 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "MyApp.war"

            • 3. Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
              abhijeetayade Newbie

              Can you paste complete org.test.myApp.applicationLayer.servlet.StartupServlet.java file?

              • 4. Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
                Laura delli Paoli Master

                Here is my class:

                 

                package org.test.myApp.applicationLayer.servlet;

                 

                 

                import org.apache.log4j.Logger;

                public class StartupServlet extends HttpServlet {

                 

                  private static final long serialVersionUID = 8912623154134195707L;

                  private static Logger trace = Logger.getLogger(StartupServlet.class);

                 

                  public void init(ServletConfig config) throws ServletException {

                  trace.info("it works");

                  }

                }

                • 5. Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
                  Tomaz Cerar Master

                  can you attach your war, so we can try to reproduce it.

                   

                  either war, or some buildable sources (preferred on github)

                  of course remove everything that is unrelated to this problem.

                  • 7. Re: Re: Load a JBoss module (e.g. log4j) as a dependency in web apps
                    abhijeetayade Newbie

                    Hello,

                     

                    You might try org.jboss.logmanager.log4j instead of org.apache.log4j as a dependency.

                     

                    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

                    <deployment>

                      <dependencies>

                      <module name="org.jboss.logmanager.log4j"/>

                      </dependencies>

                    </deployment>

                    </jboss-deployment-structure>