zoukankan      html  css  js  c++  java
  • Maven配置tomcat和jetty插件来运行项目

    针对eclipse中的Run on Server有些情况下并不是那么好操作,比如配置maven下的springmvc插件,如果使用此方法运行会很容易出现组件缺少导致错误出现一大堆的问题。

    那么针对这种情况,maven下的容器插件tomcat和jetty做了很好的支持。比如在maven下配置了这两个组件:

    <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">
        ...
        <build>
            <finalName>testmvchelloworld</finalName>
            <plugins>
                <!-- Config: Maven Tomcat Plugin -->
                <!-- http://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat7-maven-plugin -->
                <!-- http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/plugin-info.html -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <!-- Config: contextPath and Port (Default:8080) -->
                    <!-- 
                    <configuration> 
                        <path>/</path> 
                        <port>8899</port> 
                    </configuration>
                     -->
                </plugin>
                <!-- Config: Maven Jetty Plugin -->
                <!-- http://mvnrepository.com/artifact/org.mortbay.jetty/jetty-maven-plugin -->
                <!-- http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html -->
                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>9.4.3.v20170317</version>
                    <!-- Config: contextPath and Port (Default:8080) -->
                    <!--             
                    <configuration>
                        <httpConnector>
                            <port>8899</port>
                        </httpConnector>
                        <webAppConfig>
                            <contextPath>/</contextPath>
                        </webAppConfig>
                    </configuration>
                     -->
                </plugin>
            </plugins>
        </build>
    </project>

    提示:如果想要带上引用名,可以在<contextPath>标签上加上/${project.artifactId}

    那么在调试运行项目时,可以直接使用maven的命令直接进行:

    //tomcat7
    mvn tomcat7:run
    //jetty
    mvn jetty:run

    其中控制台上输出的信息和本身Run on Server保持了一致。

  • 相关阅读:
    PV、UV、VV,CV的含义
    JS动态修改页面EasyUI datebox不生效、EasyUI动态添加Class、EasyUI动态渲染解析解决方案
    JavaScript Object.defineProperty()方法详解
    jquery on()方法绑定多个选择器,多个事件
    jQuery自定义事件
    jquery插件开发快速入门
    JavaScript日期处理
    js原生函数bind
    使用jquery.pjax实现SPA单页面应用
    PushState+Ajax实现简单的单页面应用SPA
  • 原文地址:https://www.cnblogs.com/EasonJim/p/6687272.html
Copyright © 2011-2022 走看看