Reputation: 777
I created my project with structure same as in next snippet of code.
|-- modP
| |-- pom.xml
| |-- src
| | |-- main
| | `-- java
| | `-- com
| | `-- myorg
| | `-- myapp
| | `-- modP
| | `-- AppP.java
|-- modC1
| |-- pom.xml
| |-- src
| | |-- main
| | `-- java
| | `-- com
| | `-- myorg
| | `-- myapp
| | `-- modC
| | `-- AppM.java
|-- modC2
| |-- pom.xml
| |-- src
|-- main
`-- java
`-- com
`-- myorg
`-- myapp
`-- modC2
`-- AppN.java
My pom.xml for modP is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myorg.myapp</groupId>
<artifactId>modP</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>modP</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
My pom.xml for C1 is :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org /xsd/maven-4.0.0.xsd">
<parent>
<artifactId>modP</artifactId>
<groupId>com.myorg.myapp</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>.../modP/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myorg.myapp</groupId>
<artifactId>modC1</artifactId>
<packaging>jar</packaging>
<name>modC1</name>
<url>http://maven.apache.org</url>
</project>
And pom.xml for C2 is:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org /2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org /xsd/maven-4.0.0.xsd">
<parent>
<artifactId>modP</artifactId>
<groupId>com.myorg.myapp</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>.../modP/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myorg.myapp</groupId>
<artifactId>modC2</artifactId>
<packaging>jar</packaging>
<name>modC2</name>
<url>http://maven.apache.org</url>
</project>
My question is can I using such configuration reference AppP.java from ModP in AppC1.java and AppC2.java in ModC1 and ModC2.
I tried this and it looks like this doesn't works. Did I misunderstood meaning of parent tag in pom.xml? What I need to do in maven for such function?
I read a lot of documentation, but now I'm even more confused than before reading. :(
Every answer will be highly appreciated.
Thanks
Upvotes: 8
Views: 16800
Reputation: 115378
Typically maven projects hierarchy is stored in hierarchical file system. Child projects are stored under parent, i.e. in your terms:
modP
pom.xml
modC1
pom.xml
modC2
pom.xml
The sub projects may have their own children etc.
Each project except the higher-level one should contain definition like
<parent>
<groupId>com.company</groupId>
<artifactId>parent-artifact-id</artifactId>
<version>1.0</version>
</parent>
Each parent module should hold list of modules:
<modules>
<module>child1</module>
<module>child2</module>
<module>child3</module>
</modules>
As far as I understand in your case you hold all 3 projects in the same directory but one of them is parent. It is possible but I think that your reference to parent's pom is wrong. Number of dots is 3 while should be 1:
<relativePath>.../modP/pom.xml</relativePath>
try this one:
<relativePath>../modP/pom.xml</relativePath>
Upvotes: 12
Reputation: 38142
Since ModP is a pom (packaging) project, it should not contain any Java code.
Upvotes: 4