Archive for the 'Maven' Category

Oct 07 2009

How to find project dependencies in a Maven project

Published by michael under Java, Maven

cog-wheels
It’s very useful to be able to see what is included in your class path especially when you’re trying to track down a troublesome dependency. Recently I had an issue with a JDOM dependency; however I had not defined a JDOM dependency in my pom.xml file and I couldn’t quite figure out why this dependency existed. This is where Maven’s excellent dependency plugin comes to the rescue.

In a project you may have dependencies on libraries like Log4J or Freemarker. These libraries in their turn may have dependencies on other libraries, this is also known as transitive dependencies.

Using the following Maven command we’ll be able to see a list of these dependencies:

mvn dependency:resolve

For a nice tree view of the same information use:

mvn dependency:tree

If you want to see a full dependency trail that also show you artifacts that were rejected due to conflicts or other reasons then run maven with the debug flag enabled:

mvn install -X

For more information about the Maven dependency plugin go here: http://maven.apache.org/plugins/maven-dependency-plugin/

No responses yet

Sep 06 2009

Want to use Spring 3.0 milestone release from Maven?

Published by michael under Java, Maven, Spring

I wanted to add the Spring 3.0 M4 milestone early access release to a Maven project to test out some of the new features. However Spring  milestone releases are not readily available in the standard public Maven repositories, so what do you do?

For the full explanation check out the link to “Spring/Maven Repositories” link in the bottom. For a quick 1-2-3 step solution add this to the <repositories> section in your Maven pom.xml file so that Maven can find Spring’s early access milestone releases:

<repository>
  <id>spring-milestone</id>
  <name>Spring Portfolio Milestone Repository</name>
  <url>http://s3.amazonaws.com/maven.springframework.org/milestone</url>
</repository>
You can then add Spring 3.0 M4 as a dependency in your pom.xml file:
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <packaging>jar</packaging>
  <version>3.0.0.M4</version>
</dependency>
If you’re looking for other Spring artifacts you can browse them using this Spring Maven artifact URL

This Spring article has additional details on this topic e.g  how to access snapshot releases:

Spring/Maven Repositories

No responses yet

Aug 26 2009

Maven, Log4j and javax.jms

Published by michael under Java, Logging, Maven

Log4j version 1.2.15 added features which has new dependencies on sun and javax packages. When you try to build your project using Maven and log4j 1.2.15 you will see this:

[INFO] Unable to find resource 'com.sun.jmx:jmxri:jar:1.2.1' in repository central (http://repo1.maven.org/maven2)
[INFO] Unable to find resource 'com.sun.jdmk:jmxtools:jar:1.2.1' in repository central (http://repo1.maven.org/maven2)
[INFO] Unable to find resource 'javax.jms:jms:jar:1.1' in repository central (http://repo1.maven.org/maven2)

These packages are not in the Maven repositories due to licensing issues. There are two simple solutions to this problem. You can either modify your pom.xml file to use the previous version of log4j (log4j 1.2.14) which doesn’t depend on the JMX and JMS packages:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
</dependency>

Or you can exclude the dependencies with the caveat that some of the lo4gj appenders  that depend on these packages wont be available

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.15</version>
    <exclusions>
        <!--
        These packages are not in the Maven repository
        If you do this certain log4j appenders will not be available
        -->
        <exclusion>
            <groupId>javax.jms</groupId>
            <artifactId>jms</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.jdmk</groupId>
            <artifactId>jmxtools</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.jmx</groupId>
            <artifactId>jmxri</artifactId>
        </exclusion>
    </exclusions>
</dependency>

No responses yet

Aug 02 2009

Maven pom.xml structure

Published by michael under Maven

I wanted to see the full Maven pom.xml structure and I found the following page on the Maven web site that contains all the elements and descriptions.

http://maven.apache.org/ref/2.2.0/maven-model/maven.html

No responses yet