Log4j Dependency Pain and Suffering
If you're reading this blog entry, you're probably at wits end trying to figure out why maven is spitting out the following errors.
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact javax.jms:jms:jar:1.1:test
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact com.sun.jdmk:jmxtools:jar:1.2.1:test
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact com.sun.jmx:jmxri:jar:1.2.1:test
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact javax.transaction:jta:jar:1.0.1B:compile
The way I see it, you have two options:
- Start drinking heavily
- Follow the instructions below while silently cursing Sun for putting these jars behind a license agreement page.
The Problem
You probably have log4j included as a dependency in your projects' pom.xml
. Here's the relevant section from my pom.xml
:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>test</scope>
</dependency>
Now, here's the problem. Log4j's pom.xml
contains the following:
I'm not sure I understand why, but log4j needs to have jta, jms, jmxri, and jmxtools jars in order to be happy.
Unfortunately, maven is unable to download these jars directly from the default remote Maven repository (http://repo2.maven.org/maven2/), because of the way Sun chose to license the code. Instead, you must find each jar and download from Sun's website. Then manually add each to your local maven repository.
Fix jmxtools and jmxri
These steps should fix the following complaints from maven:10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact com.sun.jdmk:jmxtools:jar:1.2.1:test
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact com.sun.jmx:jmxri:jar:1.2.1:test
- Download jmxtools.jar and jmxri.jar from http://java.sun.com. At the time this was written, you can find these files under
Download Center -> Java SE -> Java Management Extensions
, choose downloadJMX 1.2.1 Reference Implementation
- Extract the zip and find jmxri.jar and jmxtools.jar.
- Add the jars to your local maven repository by running the following commands:
cd <directory containing jmxri.jar >
mvn install:install-file -Dfile=jmxri.jar -DgroupId=com.sun.jmx -DartifactId=jmxri -Dversion=1.2.1 -Dpackaging=jar
cd <directory containing jmxtools.jar >
mvn install:install-file -Dfile=jmxtools.jar -DgroupId=com.sun.jdmk -DartifactId=jmxtools -Dversion=1.2.1 -Dpackaging=jar
- Alternatively, just copy jmxri.jar into the appropriate folder inside your local repository:
"<home dir>/.m2/repository/com/sun/jmx/jmxri/1.2.1/jmxri-1.2.1.jar"
- And copy jmxtools.jar into
"<home dir>/.m2/repository/com/sun/jdmk/jmxtools/1.2.1/jmxtools-1.2.1.jar
Fix jta
These steps should fix the following complaints from maven:
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact javax.transaction:jta:jar:1.0.1B:compile
- Download jta.jar from http://java.sun.com. At the time this was written, you can find these files under Download center -> Java EE -> Java Transaction APIs, choose download classes for "Java Transaction API Specification 1.1 Maintenance Release".
- Extract the zip and you'll notice that there's no jta.jar, just a bunch of class files. For some reason, Sun likes to make it as inconvenient as possible to resolve this dependency.
- Change directories to the folder created by unzipping the zip file. Create jta.jar by running the following command in the same directory: jar cf ../jta-1.0.1B.jar *
- Add the jar to your local maven repository by running the following command cd
mvn install:install-file -Dfile=jta-1.0.1B.jar -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar - Alternatively, just copy jta.jar into the appropriate folder inside your local repository: "
/.m2/repository/javax/transaction/jta/1.0.1B/jta.jar"
Fix jms
These steps should fix the following complaints from maven:
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact javax.jms:jms:jar:1.1:test
- Download jms.jar from http://java.sun.com. At the time this was written, you can find these files under Download center -> Java EE -> Java Messaging Service, download "Download the version 1.1 API Documentation, Jar and Source".
- Extract the zip and find jms.jar.
- Add the jar to your local maven repository by running the following command cd
mvn install:install-file -Dfile=jms.jar -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar - Alternatively, just copy jms.jar into the appropriate folder inside your local repository: "
/.m2/repository/javax/jms/jms/1.1/jms.jar"
Fix javax.sql:jdbc-stdext
On Feb 24, 2009, I ran across another sun jar that has licensing problems, and thought it would be good to share how I fixed it. I ran into this problem when using the open source Java Cache System project which references mysql-connector-java-x-x-x.jar which references jdbc-stdext.
The steps below should fix the following complaints from maven:
10/30/08 1:17:15 PM EDT: Missing indirectly referenced artifact javax.sql:jdbc-stdext:jar:2.0:compile
- Download the "JDBC 2.0 Optional Package Binary", which, at the timeof this writing was available here
- Add the jar to your local maven repository by running the following command cd
mvn install:install-file -Dfile=jdbc2_0-stdext.jar -DgroupId=javax.sql -DartifactId=jdbc-stdext -Dversion=2.0 -Dpackaging=jar
Last Step
Continue development, or GOTO option (1) above "Start drinking heavily".