zoukankan      html  css  js  c++  java
  • 使用jetty-maven-plugin运行maven多项目

    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

  • 相关阅读:
    怎样获取Web应用程序的路径
    如何取得Repeater控件选择的项目
    方法多种,选择随已定
    如何获取月份的天数
    ajaxToolkit:TextBoxWatermarkExtender演示与应用
    Accessing the GAL(Global Address List) from ASP.NET
    如何获取当前日期的最大时间值
    环境语言变换导致存储过程执行不正常
    流水号 Ver2
    使用JavaScript动态设置样式 Ver2
  • 原文地址:https://www.cnblogs.com/river2005/p/5812133.html
Copyright © 2011-2022 走看看