Reputation: 141
Could anybody suggest me an solution with the following exception. I am going to create a multi-module project.
Parent project name is projectW
and child project names are projectA
, projectD
and projectUtil
.
I need to have war file of projectW
which should contain projectA
, projectD
and projectUtil
. jar file.
But maven must pom for packaging in parent project. How can I create a project like this?
Upvotes: 0
Views: 2351
Reputation: 7950
Have a parent pom
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>example</name>
<modules>
<module>projectW</module>
<module>projectA</module>
<module>projectD</module>
<module>projectUtil</module>
</modules>
</project>
Then projectW pom looks something like this
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>projectW</artifactId>
<packaging>war</packaging>
<name>projectW</name>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>projectA</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>projectD</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>projectUtil</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Then your projectA, projectD and projectUtil will looks something like this
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>projectA</artifactId>
<packaging>jar</packaging>
<dependencies>
</dependencies>
</project>
When you build the parent, the war you want will be projectW/target/projectW-1.0-SNAPSHOT.war
Upvotes: 3