7 Replies Latest reply on Nov 3, 2008 3:06 AM by prpo

    packaging log4j.properties with a server jar

    prpo

      Hello All,

      I have a wrapper class around log4j which needs to be packaged with an ejb.
      How do I package the log4j.properties?
      I do not want to modify the server/conf/jboss-log4j.xml file as that would mean changes to every deployment.
      I am using EJB3 and do not have any deployment descriptors for the MDB.

      Thanks for your suggestions.

        • 1. Re: packaging log4j.properties with a server jar
          jaikiran

          Which version of JBoss do you use? You mention about jboss-log4j.xml so i guess it's JBoss-4.2.x. See this http://www.jboss.com/index.html?module=bb&op=viewtopic&t=128979#4125416 on how to package your lo4j.properties in your application.

          • 2. Re: packaging log4j.properties with a server jar
            prpo

            Thank you for your reply. I've looked at the post you've mentioned.
            My version of JBoss is 4.2.3GA

            The issue I have is that, I have a shared library which uses log4j with its own log4j.xml

            This shared library can possibly be used by any client (an ejb, war or EAR files).

            The clients will include this jar file in the classpath to get access to the classes.

            1) Where do I put the shared-library.jar file (/server/default/lib?)
            2) Should the clients *package* this library with their deployable (war,ejb,ear?)

            I've tried this by setting java2ParentDelegation=false as well as leaving it to default in the client. Ideally, I do not want the clients to set anything.

            The results I've noticed are that, when I place the shared-libary.jar file in server/default/lib, the clients(ejb,etc) are able to find the logger on jboss server restart but not if I hot deploy the ejb by placing the ejb.jar in deploy directory.

            What am I missing here?

            Thanks

            • 3. Re: packaging log4j.properties with a server jar
              jaikiran

               

              2) Should the clients *package* this library with their deployable (war,ejb,ear?)


              Yes.

              Ideally, I do not want the clients to set anything.


              When you say clients, i am assuming you are talking about client applications (EAR or WAR) which require this library. So if they require this library, it would be best to package it in each client application.



              • 4. Re: packaging log4j.properties with a server jar
                prpo

                jaikiran,

                When I mean clients, yes I meant ejb, war,ear etc.
                When the shared-library.jar file is packaged with the ejb, I do not want them to set java2ParentDelegation=false

                However, the problem I am running into with this scenario when shared-library.jar is not placed on /server/default/lib is that the ejb cannot find log4j.properties (or xml) when it just packaged with ejb.jar

                Any insights?

                • 5. Re: packaging log4j.properties with a server jar
                  prpo

                  Just to clarify,

                  "prpo" wrote:
                  jaikiran,
                  When I mean clients, yes I meant ejb, war,ear etc.
                  When the shared-library.jar file is packaged with the ejb, I do not want them to set java2ParentDelegation=false


                  I do not want to expect that users will create their own jboss-app.xml and set java2ParentDelegation=false for this to work.

                  "prpo" wrote:

                  However, the problem I am running into with this scenario when shared-library.jar is not placed on /server/default/lib is that the ejb cannot find log4j.properties (or xml) when it just packaged with ejb.jar

                  There are so many combinations I could try here.
                  a) Just package the shared library with the ejb - no overriding of java2ParentDelegation - Does not locate the log4j.xml

                  Any insights?


                  • 6. Re: packaging log4j.properties with a server jar
                    jaikiran

                     

                    "prpo" wrote:

                    a) Just package the shared library with the ejb - no overriding of java2ParentDelegation - Does not locate the log4j.xml

                    Any insights?


                    In this scenario, where exactly is the log4j.xml placed? Is it inside the shared.jar or inside the ejb.jar? When you say you are packaging the shared jar with the ejb jar, how exactly are you doing this? Packaging one jar inside other? I think the reason why the log4j.xml is not being picked up is because of the singleton nature of the log4j Logger class. Unless a new instance of the Logger object is not created through the application specific classloader, the log4j properties/xml file initialization will not happen.


                    Furthermore, add the -log4j:debug parameter to the JAVA_OPTS in your run.bat of JBoss. This parameter will printout to the STDOUT (console) internal log4j messages which will help you understand where log4j is looking for the file.

                    Also, is the shared library code part of your applicaiton? And do you have rights to change the code (thinking of a last resort option).

                    • 7. Re: packaging log4j.properties with a server jar
                      prpo

                      Jai,

                      My shared library is say sharedLib.jar it uses JMSAppender in log4j to send messages to a topic.

                      The sharedlib.jar is used by war, ejb or ear files.

                      An MDB subscribes to the topic and polls messages.

                      In this case, where do I place my log4j.properties file?

                      thanks for all your help

                      -Pras