Maven - Multi Module Sample Application!

Lets see!

This is the Directory Layout I have:

Lets start with pom.xml found on the top folder:
<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/maven-v4_0_0.xsd">
 
 <modelVersion>4.0.0</modelVersion>
 <groupId>biz.tugay</groupId>
 <artifactId>multi-module</artifactId>
 <packaging>pom</packaging>
 <version>1.0-SNAPSHOT</version>
 
 <modules>
  <module>multi-core</module>
  <module>multi-web</module>
 </modules>
 
</project>

Lets move on to multi-core module.
pom.xml
<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/maven-v4_0_0.xsd">
 
 <modelVersion>4.0.0</modelVersion>
 <artifactId>multi-core</artifactId>
 <packaging>jar</packaging>
 <version>1.0-SNAPSHOT</version>
 
 <name>multi-module-core</name>
 
 <parent>
  <groupId>biz.tugay</groupId>
  <artifactId>multi-module</artifactId>
  <version>1.0-SNAPSHOT</version>
 </parent>
 
 
 <build>
  <finalName>multi-core</finalName>
 </build>
 
</project>

and, CoreFoo.java
package biz.tugay.multicore;
 
/* User: koray@tugay.biz Date: 2016/07/18 */
 
public class CoreFoo {
    public String sayHello() {
        return "Hello world from Core module!!!";
    }
}

Lets move on to multi-web module...
pom.xml
<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/maven-v4_0_0.xsd">
 
    <modelVersion>4.0.0</modelVersion>
    <artifactId>multi-web</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
 
    <name>multi-module-web</name>
 
    <dependencies>
        <dependency>
            <groupId>biz.tugay</groupId>
            <artifactId>multi-core</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
 
    <parent>
        <groupId>biz.tugay</groupId>
        <artifactId>multi-module</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
 
    <build>
        <finalName>multi-module-web</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.1.v20140609</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/multimodule</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
 
    <servlet>
        <servlet-name>MultiWebServlet</servlet-name>
        <servlet-class>biz.tugay.multiweb.MultiWebServlet</servlet-class>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>MultiWebServlet</servlet-name>
        <url-pattern>/welcome</url-pattern>
    </servlet-mapping>
 
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 
</web-app>

MultiWebServlet.java
package biz.tugay.multiweb;
 
/* User: koray@tugay.biz Date: 2016/07/18 */
 
import biz.tugay.multicore.CoreFoo;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
 
public class MultiWebServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        final CoreFoo coreFoo = new CoreFoo();
        final String helloMessage = coreFoo.sayHello();
        req.setAttribute("helloMessage", helloMessage);
        req.getRequestDispatcher("WEB-INF/hello.jsp").forward(req, resp);
    }
}

index.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:redirect url="/welcome"/>

hello.jsp
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
</head>
<body>
${requestScope.helloMessage}
</body>
</html>

Time to test:
C:\Users\Koray Tugay\Development\_Projects\multi-module-project>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] multi-module
[INFO] multi-module-core
[INFO] multi-module-web
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building multi-module 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ multi-module ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ multi-module ---
[INFO] Installing C:\Users\Koray Tugay\Development\_Projects\multi-module-project\pom.xml to 
C:\Users\Koray Tugay\.m2\repository\biz\tugay\multi-module\1.0-SNAPSHOT\multi-module-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building multi-module-core 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ multi-core ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ multi-core ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ multi-core ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ multi-core ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ multi-core ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ multi-core ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ multi-core ---
[INFO] Building jar: C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\target\multi-core.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ multi-core ---
[INFO] Installing C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\target\multi-core.jar to C:\Users\Koray Tugay\.m2\repository\biz\tugay\multi-core\1.0-SNAPSHOT\multi-core-1.0-SNAPSHOT.jar
[INFO] Installing C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-core\pom.xml to C:\Users\Koray Tugay\.m2\repository\biz\tugay\multi-core\1.0-SNAPSHOT\multi-core-1.0-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building multi-module-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ multi-web ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ multi-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ multi-web ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ multi-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ multi-web ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ multi-web ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ multi-web ---
[INFO] Packaging webapp
[INFO] Assembling webapp [multi-web] in [C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\multi-module-web]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\src\main\webapp]
[INFO] Webapp assembled in [62 msecs]
[INFO] Building war: C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\multi-module-web.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ multi-web ---
[INFO] Installing C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\multi-module-web.war to C:\Users\Koray Tugay\.m2\repository\biz\tugay\multi-web\1.0-SNAPSHOT\multi-web-1.0-SNAPSHOT.war
[INFO] Installing C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\pom.xml 
to C:\Users\Koray Tugay\.m2\repository\biz\tugay\multi-web\1.0-SNAPSHOT\multi-web-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] multi-module ....................................... SUCCESS [  0.359 s]
[INFO] multi-module-core .................................. SUCCESS [  1.107 s]
[INFO] multi-module-web ................................... SUCCESS [  0.500 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.075 s
[INFO] Finished at: 2016-07-18T17:05:12+03:00
[INFO] Final Memory: 18M/226M
[INFO] ------------------------------------------------------------------------
 
C:\Users\Koray Tugay\Development\_Projects\multi-module-project>

and..
C:\Users\Koray Tugay\Development\_Projects\multi-module-project>cd multi-web
 
C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web>mvn jetty:start
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building multi-module-web 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> jetty-maven-plugin:9.2.1.v20140609:start (default-cli) > validate @ multi-web >>>
[INFO]
[INFO] <<< jetty-maven-plugin:9.2.1.v20140609:start (default-cli) < validate @ multi-web <<<
[INFO]
[INFO] --- jetty-maven-plugin:9.2.1.v20140609:start (default-cli) @ multi-web ---
[INFO] Logging initialized @1935ms
[INFO] Configuring Jetty for project: multi-module-web
[INFO] webAppSourceDirectory not set. Trying src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\classes
[INFO] Context path = /multimodule
[INFO] Tmp directory = C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/C:/Users/Koray%20Tugay/Development/_Projects/multi-module-project/multi-web/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = C:\Users\Koray Tugay\Development\_Projects\multi-module-project\multi-web\src\main\webapp
[INFO] jetty-9.2.1.v20140609
[INFO] Started o.e.j.m.p.JettyWebAppContext@2c6ff930{/multimodule,file:/C:/Users/Koray%20Tugay/Development/_Projects/multi-module-project/multi-web/src/main/webapp/,AVAILABLE}{file:/C:/Users/Koray%20Tugay/Development/_Projects/multi-module-project/multi-web/src/main/webapp/}
[WARNING] !RequestLog
[INFO] Started ServerConnector@2417af7e{HTTP/1.1}{0.0.0.0:8080}
[INFO] Started @2545ms
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 2 seconds.

Now visit localhost:8080/multimodule to see: