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

  • 相关阅读:
    升级MySQL5.7.22版本_总结记录
    初探分布式环境的指挥官ZooKeeper
    利用ROS工具从bag包中提取图片和.csv文件
    安装tensorflow出现的python-setuptools 20.7.0问题
    evo 评测工具修改背景颜色和线条等参数
    Ubuntu上下载百度网盘资料
    okvis 编译出现ceres-solver错误的解决办法
    opencv各个模块功能总结
    计算两幅图的单应矩阵,实现图像拼接
    特征提取与匹配、基础矩阵、单应矩阵、极限约束
  • 原文地址:https://www.cnblogs.com/river2005/p/5812133.html
Copyright © 2011-2022 走看看