Maven2 Log4J and JMX dependencies

Aarg!  What a nightmare.  I finally — fine, call me stupid — figured out where to/how to get the JMX dependencies for Log4J.
I am using Commons Logging, which in turn, likes to use Log4J.  So, I added this to my Maven project file (pom.xml):
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
</dependency>

However, log4j has a dependency on jmx, which maven dutifully brings to my attention.

And this is where it gets interesting, the Maven repositories all have a pom for these but NOT the jar’s.
It turns out you need to download the jars from Sun’s Download site (which you have to register for).  (To navigate there, go to http://www.sun.com/download, then search the download center for JMX, then select the Java Management Extensions Download Information, then select the JMX 1.2.1 Reference Implementation,then select the JMX RI 1.2.1 download.  Whew!)

After downloading, you need to rename the jars from jmx*.jar to jmx*-1.2.1.jar.  Then you can register them with Maven (I use Artifactory, which made this a lot easier.)  Be sure to change the GroupId as follows:
com.sun.jdmk:jmxtools
com.sun.jmx:jmxri

With the jars in the repository, the JMX dependencies now resolve properly.

19 Responses to “Maven2 Log4J and JMX dependencies”

  1. Glen Says:

    This solved my problem, thanks for taking the time to post this.

  2. skingaby Says:

    You’re welcome. And suddenly, it was worth it.

  3. Alex Polson Says:

    Kudos on this post. I ran into a similar problem and was getting really frustrated.

    While the instructions above described two of the dependencies I was missing I was still having trouble downloading jms-1.1.jar as it looks like Sun is about to release a new product which supersedes it. I ended up just doing an explicit Google search for jms-1.1.jar, found it, installed it and now I’m up and running again.

    Thanks again. :)

  4. Mathias Broekelmann Says:

    But one question is still unanswered: do we really need jmx or jms now to use log4j in any case? I belive not! So I gracefully exclude those dependencies in my master pom:

    log4j
    log4j
    1.2.15

    javax.jms
    jms

    com.sun.jdmk
    jmxtools

    com.sun.jmx
    jmxri

  5. Erik Cornelisse Says:

    I agree with Mathias.

    Those files are not required if your program doesn’t make use of JMS or JMX.

    Excluding them as dependency is the best way to deal with this problem.
    The dependency that Maven detects, are required for buidling the Log4J libraries.

    Here a example of excluding all indirect dependencies for Log4J in your pom.xml file:

    log4j
    log4j
    1.2.15
    compile

    com.sun.jdmk
    jmxtools

    com.sun.jmx
    jmxri

    javax.jms
    jms

    javax.mail
    mail

    javax.activation
    activation

    Be sure that you don’t need them !

    Kind regards,

  6. Erik Cornelisse Says:

    Excuse me, some how my paste action has failed.

    The right content of the pom.xml file should be:

    log4j
    log4j
    1.2.15
    compile

    com.sun.jdmk
    jmxtools

    com.sun.jmx
    jmxri

    javax.jms
    jms

    javax.mail
    mail

    javax.activation
    activation

  7. Mark Helmstetter Says:

    I agree, excluding is the way to go. To exclude, enter the following in your pom.xml

    log4j
    log4j
    1.2.15

    com.sun.jmx
    jmxri

    com.sun.jdmk
    jmxtools

    javax.jms
    jms

  8. Mark Helmstetter Says:

    Sorry, I guess I should have realized that this blog is stripping tags. How about this:

    gt;
    gt;log4jgt;
    gt;log4jgt;
    gt;1.2.15gt;
    gt;
    gt;
    gt;com.sun.jmxgt;
    gt;jmxrigt;
    gt;
    gt;
    gt;com.sun.jdmkgt;
    gt;jmxtoolsgt;
    gt;
    gt;
    gt;javax.jmsgt;
    gt;jmsgt;
    gt;
    gt;
    gt;

  9. Log4J 1.2.15 and maven dependencies « DoTaL Says:

    [...] post expands on this post from One Man Went to Mow… to add the jms and mail [...]

  10. Sundar Says:

    Thx for the details. I got the Log4J working now. Finding out the JMS and JMX took time, thx to Google for showing them on mouse click.

  11. Rolf Staflin Says:

    There is another easy way to get rid of the dependencies: Simply use the previous version of Log4j. Change the version number to 1.2.14 and you can cut out all the exclusions from your pom.xml!

  12. Marcus Says:

    Exclude it in your pom file if you do not need it, e.g.

    log4j
    log4j
    1.2.15

    com.sun.jdmk
    jmxtools

    com.sun.jmx
    jmxri

  13. nikhil Says:

    Excellent posts guys… but the question is… why in the world would the log4j depend on the jmxtools and jmxri files?

  14. Anna Skawińska Says:

    Hi, thanks for featuring this topic, it got me stuck for a while, too. I’ve just come out with another solution which doesn’t require excluding or installing anything manually. The Maven2 repository on JBoss contains the needed artifacts, just add the following repository to your Maven2 settings and Maven will find those: http://repository.jboss.com/maven2

  15. Ben Bruhl Says:

    I also ran into this problem. I also dropped the version back to 1.2.14 and maven built fine.
    Good tip from Rolf.

  16. toniBlog » Mavenized Says:

    [...] sometimes, with the xml, with some weird repositories publishing strange versions, or just with Log4J for example, depending on libraries not available on any repository, but hey, Maven downloaded for [...]

  17. Spring Web Service’s with JAXB, Maven & Eclipse « Jamesbnuzzo’s Blog Says:

    [...] One Man went to Mow [...]

  18. Resolving log4j 1.2.15 dependency problems in Maven using exclusions » unitstep.net Says:

    [...] could download and install these artifacts to the local repository, if we really needed them. But in most cases, they’re not needed and thus you won’t [...]

  19. Jim Barritt Says:

    Hey,

    I was just following the same problem. I found this link which might be of help:

    http://www.nabble.com/newbie:-why-does-log4j-pull-down-all-sorts-of-files–td21821665.html

    it mentions 2 repositories which may have the extra jars:
    http://download.java.net/maven/2/
    http://repository.jboss.org/maven2/

    Also talks about using transitive=”false” which should stop it downloading all the other deps.

    hope this is of use.

    Jim

Leave a Reply