1.准备工作
org.eclipse.jetty jetty-maven-plugin 9.2.11.v20150529
jdk 1.7
maven 3.1
2.采用maven管理多项目的方式
1> pom工程nemo-pom的pom.xml,这里packaging要声明成pom以使用管理web modules.
<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>river</groupId>
<artifactId>nemo-pom</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>nemo-pom</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.3.1.RELEASE</spring.version>
<jetty_version>9.2.11.v20150529</jetty_version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty_version}</version>
<exclusions>
<exclusion>
<artifactId>apache-jsp</artifactId>
<groupId>org.mortbay.jasper</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty_version}</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<reload>automatic</reload>
<webApp>
<contextPath>/</contextPath>
</webApp>
<httpConnector>
<port>8180</port>
</httpConnector>
<contextHandlers>
<contextHandler
implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<contextPath>/sample</contextPath>
<resourceBase>${basedir}/../sample/target/sample-${project.version}</resourceBase>
</contextHandler>
<contextHandler
implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<contextPath>/samplefront</contextPath>
<resourceBase>${basedir}/../samplefront/target/samplefront-${project.version}</resourceBase>
</contextHandler>
</contextHandlers>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../sample</module>
<module>../samplefront</module>
</modules>
</project>
2>web项目sample的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>river</groupId>
<artifactId>nemo-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../nemo-pom/pom.xml</relativePath>
</parent>
<artifactId>sample</artifactId>
<packaging>war</packaging>
<name>sample</name>
<properties>
<spring.version>4.3.1.RELEASE</spring.version>
</properties>
<dependencies>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</project>
3>web项目samplefront的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>river</groupId>
<artifactId>nemo-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../nemo-pom/pom.xml</relativePath>
</parent>
<artifactId>samplefront</artifactId>
<packaging>war</packaging>
<name>samplefront</name>
<properties>
<spring.version>4.3.1.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
</project>
4>cd进入 pom工程nemo-pom下,执行mvn clean package
现在可以在sample和samplefront两个web modules 的target目录里分别看到sample-0.0.1-SNAPSHOT.war和samplefront-0.0.1-SNAPSHOT.war两上包已经生成.
5>接着执行mvn jetty:run 如下:
可以看到server已经启动,测试地址如下:
http://localhost:8180/sample/index.jsp
http://localhost:8180/samplefront/index.jsp