Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting parent directory of ${basedir} from maven

Tags:

java

maven

Is there way to get parent directory for ${basedir} in my pom.xml? Currently I have

<earSourceDirectory>${basedir}/EAR/src/main/resources</earSourceDirectory> 

but I need to access parent directory of basedir as my resources lies in different maven project.

How can I get the parent folder of ${basedir}?

like image 999
Surendran Duraisamy Avatar asked Oct 22 '13 07:10

Surendran Duraisamy


People also ask

What is ${ project Basedir in POM xml?

project. basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom.

What is base directory in Maven?

It's a directory where the pom. xml is stored (in the root of the project).

What is Maven parent?

A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.

What is Maven inheritance?

All Maven POMs inherit values from a parent POM. If a POM does not specify a direct parent using the parent element, that POM will inherit values from the Super POM. Project Inheritance shows the parent element of project-a which inherits the POM defined by the a-parent project. Project Inheritance.


2 Answers

${project.basedir}/../

However, access resources in a different module is something I try to avoid. I'd suggest using the unpack goal of the maven-dependency-plugin.

like image 110
diegomtassis Avatar answered Sep 17 '22 12:09

diegomtassis


In the children:

<properties>
    <main.basedir>${project.parent.basedir}</main.basedir>
</properties>

In the grandchildren:

<properties>
    <main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>
like image 30
Ashish Avatar answered Sep 19 '22 12:09

Ashish