Skip to content

Instantly share code, notes, and snippets.

@sourcerebels
Created December 18, 2010 09:55
Show Gist options
  • Save sourcerebels/746361 to your computer and use it in GitHub Desktop.
Save sourcerebels/746361 to your computer and use it in GitHub Desktop.
Multi-module Maven project
<?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>
<artifactId>test-multimodule</artifactId>
<groupId>com.sourcerebels</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.sourcerebels.framework</groupId>
<artifactId>framework-core</artifactId>
<version>1.0-SNAPSHOT</version>
<name>framework-core</name>
<url>http://www.sourcerebels.com</url>
<packaging>jar</packaging>
<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>
<?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.sourcerebels</groupId>
<artifactId>test-multimodule</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-multimodule</name>
<url>http://www.sourcerebels.com</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>
<modules>
<module>framework-core</module>
<module>testapp</module>
</modules>
</project>
<?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>
<artifactId>test-multimodule</artifactId>
<groupId>com.sourcerebels</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.sourcerebels.framework</groupId>
<artifactId>testapp</artifactId>
<version>1.0-SNAPSHOT</version>
<name>testapp</name>
<url>http://www.sourcerebels.com</url>
<packaging>war</packaging>
<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>
<build>
<finalName>testApp</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@sourcerebels
Copy link
Author

Based on Erick Camacho Screencast [Tutorial de Maven 3 por Erick Camacho javaHispano] [1].

parent-pom.xml This is the main module. This is just a POM file to group common project dependencies, and manage all modules of a enterprise projects at same time. Important points:

  • There is a project named parent-project just to encapsulate all modules of an enterprise application.
  • "packaging" section of parent-pom.xml is setted just to "pom". This is the main project.
  • "packaging" section of framework-core-pom.xml is setted to "jar". This means, that results of building framework-core is just a collection of compiled classes and resources.
  • "packaging" section of testapp-pom.xml is setted to "war". This means, that results of building testapp is just a website or a web application.
  • In both, framework-core-pom.xml and testapp-pom.xml, there is a section "parent" to tell Maven from which POM is inheriting its properties.
  • testapp-pom.xml has a "plugin" section for the plugin maven_jetty_plugin. You can run your webapp just by typing next command on your webapp's project path:
mvn jetty:run

And then, if all is ok, pointing your web browser to:

http://localhost:8080/testapp/
  • Resulting project folder structure:
parent-project/
    framework-core/
        src/main/
            java/
            resources/
        src/test/
            java/
            resources/
        framework-core-pom.xml
    testapp/
        src/main/webapp/
                    WEB-INF/web.xml
                    index.jsp
        testapp-pom.xml
    parent-pom.xml

[1] : http://vimeo.com/17531468 "Tutorial de Maven 3 por Erick Camacho javaHispano"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment