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.

31 thoughts on “Maven2 Log4J and JMX dependencies

  1. 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. 🙂

  2. 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:

    <dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.15</version>
    	<exclusions>
    		<exclusion>
    			<groupId>javax.jms</groupId>
    			<artifactId>jms</artifactId>
    		</exclusion>
    		<exclusion>
    			<groupId>com.sun.jmx</groupId>
    			<artifactId>jmxri</artifactId>
    		</exclusion>
    		<exclusion>
    			<groupId>com.sun.jdmk</groupId>
    			<artifactId>jmxtools</artifactId>
    		</exclusion>
    	</exclusions>
    </dependency>
  3. 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,

  4. 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

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

    <dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.15</version>
    	<exclusions>
    		<exclusion>
    			<groupId>com.sun.jmx</groupId>
    			<artifactId>jmxri</artifactId>
    		</exclusion>
    		<exclusion>
    			<groupId>com.sun.jdmk</groupId>
    			<artifactId>jmxtools</artifactId>
    		</exclusion>
    	</exclusions>
    </dependency>
  6. 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.

  7. 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!

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

    <dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.15</version>
    	<exclusions>
    		<exclusion>
    			<groupId>com.sun.jmx</groupId>
    			<artifactId>jmxri</artifactId>
    		</exclusion>
    		<exclusion>
    			<groupId>com.sun.jdmk</groupId>
    			<artifactId>jmxtools</artifactId>
    		</exclusion>
    	</exclusions>
    </dependency>
  9. 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

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

  11. […] 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 […]

  12. <dependency>
    	<groupId>log4j</groupId>
    	<artifactId>log4j</artifactId>
    	<version>1.2.15</version>
    	<exclusions>
    		<exclusion>
    			<groupId>com.sun.jmx</groupId>
    			<artifactId>jmxri</artifactId>
    		</exclusion>
    		<exclusion>
    			<groupId>com.sun.jdmk</groupId>
    			<artifactId>jmxtools</artifactId>
    		</exclusion>
    	</exclusions>
    </dependency>
  13. Now that Oracle has assimilated Sun, where are we supposed to get these JMX management extensions? Its impossible to find things on Oracle’s site now.

  14. […] leave a comment » 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, whi … Read More […]

  15. A better solution would be to get other people to start hosting the JAR from their own Maven repositories. Having to manually fetch any dependency from anywhere largely defeats the purpose of using Maven in the first place.

  16. Spot on with this writeup, I actually believe this website needs a great deal more attention. Ill probably be returning to read through more, thanks for the info! dadcbedgaddk

Leave a reply to David Hergert Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.