Archive for January 2013

Creating dependencies between different maven projects   Leave a comment

In this post we shall see how we can create dependencies between different Maven projects using pom.xml. We shall use the project ‘GitTest’ we created and uploaded to our local maven repository in the last post. In this post, we shall create another Maven project called ‘jarproject’ and then use it to our project. We shall also define a parent pom where we shall lay out modules so that our ‘GitTest’ project automatically builds the corresponding library project.

1. Using Eclipse create another Maven project and name it ‘jarproject’. Give it a group id, artifactId etc. In this project introduce a new class com.jarproject.LibraryClass and put a method printLibraryLine() inside that class. We shall call the printLibraryLine() method from the ‘’ present in the ‘GitTest’ project. This is how your project will look in Eclipse.


2. Now in order to build ‘jarproject’ along with ‘GitTest’ we need a parent pom, one that will link both of these projects together. So go ahead and create another Maven project named ‘parent’ in Eclipse and in that pom enter both ‘GitTest’ and ‘jarproject’ as modules. The parent pom will now look something like this.

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

3. Add a dependency on the ‘jarproject’ module in ‘GitTest’ pom.


4. Now add a line of code in the file calling the LibraryClass.printLibraryLine() method so that ‘GitTest’ project now depends on ‘jarproject’. Note: In eclipse you will have to do a ‘Update Maven Dependencies’ in order to be able to get a reference to LibraryClass.

5. This is how your project structure will now look like. Execute maven deploy on the parent pom.xml either in eclipse or command line.



6. Next now go to your local maven repository hosted by Artifactory which we setup in the previous post by entering the URL ‘http://localhost:8081/artifactory/webapp/home.html‘ in the browser. Go to the ‘Artifacts’ tab and browse to the ‘libs-snapshot-local’ repo and expand it. You will see 3 projects ‘GitTest’, ‘jarproject’ and ‘parent’ in the repo.


Posted January 18, 2013 by salilsurendran in Technology

Tagged with