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保持了一致。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM