File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven: Gettng theParent folder of ${basedir} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven: Gettng theParent folder of ${basedir} " Watch "Maven: Gettng theParent folder of ${basedir} " New topic

Maven: Gettng theParent folder of ${basedir}

Ishu Saxena

Joined: Jun 24, 2008
Posts: 25
Hello Ranchers,

We have a project structure similar to the one listed below:

The requirement here is to trigger the entire build process using the pom.xml of project2. What this basically means is that we need to run a single command that builds project 2, Project1-child1 and Project1-child2.

I have tried to define modules in my parent pom.

This does not seem to work. Is there a way we can get the parent directory of teh current directory in maven.
Would really appreciate any inputs here.


--<br />SCJP 5.0
E Armitage

Joined: Mar 17, 2012
Posts: 989
The child projects should declare their parents using
Peter Johnson

Joined: May 14, 2008
Posts: 5852

I'm sorry, but I do not understand your project hierarchy (even after adding code tags!). Could you post the full paths (or relative paths starting from a common folder) for each project's pom.xml file?

Usually, for my multi-module projects, I use this structure:


This structure makes it easy to store the projects in Subversion, and also makes it easy to check out all of the projects form Subversion (I select all projects and do a check-out).

My master.project/pom.xml uses this to pull in the subprojects:

By the way, I always try to convince the developers I work with to never do this! Using a master POM in this way to sequentially rebuild modules is not always the best idea. Instead, you should be using a continuous integration server, such as Hudson, and have it manage the builds, rebuilding things as necessary. Hudson understands the Maven dependencies and will rebuild modules as required. Of course, there are times that a master/submodule pattern is the only viable alternative.

JBoss In Action
I agree. Here's the link:
subject: Maven: Gettng theParent folder of ${basedir}
It's not a secret anymore!