Filip Nguyen
Filip Nguyen

Reputation: 1039

Transitive third party dependencies with Maven

I am developing application that uses Cassandra NoSQL database and I am adding web interface. I have 2 projects: cassandra-access (this project is DAL) and web (this project is web application).

Scenario is simple enaugh. Cassandra-access has dependencies on hector.jar which is not in maven repository. So I added this dependency to my local repository via mvn install:install-file and I list my repository in parent pom:

 <repositories>
      <repository>
        <id>loc</id>
        <url>file://${basedir}/../mvn-local-repository</url>
    </repository>
</repositories>

In Web projects pom I added dependency on Cassandra-access. But when i start the Web application with hello world read from database I am getting classNotFound exception as if the hector.jar isn't on class path. When I write mvn clean install the resulting war of web project doesn't include hector.jar in WEB-INF/lib. That further confirms my theory.

How to achieve that war get's all the transitive dependcies? I thought that all dependencies that are in scope compile (which is default) will get copied.

Web projects pom:

  <dependency>
      <groupId>net.product</groupId>
      <artifactId>cassandra-access</artifactId>
      <version>1.0-SNAPSHOT</version>
  </dependency>

Cassandra-access pom:

 <dependency>
   <groupId>me.prettyprint</groupId>
   <artifactId>hector</artifactId>
   <version>0.7.0</version>
 </dependency>

Upvotes: 6

Views: 1001

Answers (1)

aviad
aviad

Reputation: 8278

It maybe not the optimal solution but it works for me: put the hector jar in the lib directory of the cassandra access. add to the cassandra-access pom:

<dependency>    
    <groupId>%HECTOR_JAR_GROUP_ID%</groupId>  
    <artifactId>%HECTOR_JAR_ARTIFACT_ID%</artifactId>  
    <version>%HECTOR_JAR_VERSION%</version>  
    <scope>system</scope>  
        <systemPath>${basedir}/lib/%HECTOR_JAR_NAME%</systemPath>  
</dependency>  

then add the following plugin:

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-dependency-plugin</artifactId>  
    <executions>  
        <execution>  
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

Upvotes: 1

Related Questions