Friday, January 8, 2010

Traversing Maven Dependencies

  1. Scenario 1:
    You can't compile because some arbitrary jar file is missing ... which is really a part of some bigger jar file or package ... so you can't find it on any maven repository.
    As an example, let's take the case of servlet.jar Well what do you do?
    1. Cases like this exist because the jar will be present in the Application Server (Tomcat, Jboss etc.) at run-time for your code to use. So you really shouldn't look for the servlet.jar but instead you should be looking out for servlet-api.jar file, which will let you compile your source code.
    2. Anyway a simple search on google couldn't hurt. Start with:
      1. the name of your favorite maven repository host,
      2. the generic name of the file you are looking for,
      3. the keyword maven
      Searching for ibiblio servlet maven quickly yields a link to "Index of /pub/mirrors/maven2/javax/servlet/servlet-api/2.3" which is exactly what the doctor prescribed.
    3. Some more clues: http://stackoverflow.com/questions/1979957/maven-dependency-for-servlet-3-0-api
      <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>javax.servlet-api</artifactId>
              <version>3.0.1</version>
              <scope>provided</scope>
      </dependency>
    Hopefully this example will help you resolve similar issues with other such dependencies.
  2. Scenario 2:
    An arbitrary class file is missing, which you know nothing about!

    For example, let's take the case of PersistenceCapable, just a file that I don't expect anyone to know off the top of their heads but which can pop-up in a failed build.

    Well what do you do?

    1. I prefer starting my search on http://www.findjar.com but if you search on google, it will probably show you a crawled result from that site anyway.

    2. My search through google led me to findjar which told me:
      Information on class javax.jdo.annotations.PersistenceCapable:
      Containing JAR files:
      [MAVEN] jdo2-api-2.1.jar
      [MAVEN] jpox-java5-1.2.0-beta-2.jar

      1. Notice the [MAVEN] tag next to the search results, this means that not only was the jar containing this file found but there is also a known maven repository location available!

    Hopefully this example will help you resolve similar issues with other such dependencies.

  3. Scenario 3:
    You can't compile because the build failed to resolve some arbitrary artifact, which you know nothing about.

    For example, let's take the case of javax.transaction:transaction-api:jar:1.1, which I ran into.

    Even when you search for it, you realize that you have two equally unpleasant issues to tackle:

    1. the artifact being asked for is present in a Maven 2 Repository but with another ArtifactID

      I found out that JTA 1.1 is in the Maven 2 Repository over at iBiblio with another ArtifactID: ("jta" instead of "transaction-api")

      Well what do you do?

      1. Google results led me to: http://www.jpox.org/servlet/forum/viewthread_thread,5393#29563 but I'll try to summarize it in the following bullets...

      2. You can add the correct artifact as a dependency and explicitly exclude it from the artifact which is trying to use the incorrect label/location/version

  4. the artifact is available in a maven1.x repo instead of a maven2.x repo

    I found out that a maven1.x repository had what I needed: http://download.java.net/maven/1/javax.transaction/jars/transaction-api-1.1.jar

    Well what do you do?
    1. http://maven.apache.org/guides/mini/guide-using-m1-repos-with-m2.html

0 comments:

Post a Comment