Maven配置覆蓋內嵌tomcat虛擬映射路徑

Maven配置覆蓋內嵌tomcat虛擬映射路徑

  • 直接配置報錯,錯誤提示如下:

     Caused by: java.lang.IllegalArgumentException: addChild: Child name '/store' is not unique
    • 原因分析:pom.xml的配置並沒有覆蓋tomcat/conf/server.xml中的配置,導致配置中存在多個相同配置

解決方案

比如我的本地倉庫在:D:\M2REPO\org\apache\tomcat\maven\tomcat7-maven-plugin\2.2下,那麼我們只需要解壓並此目錄下的
tomcat7-maven-plugin-2.2.jar覆蓋此文件就ok.

pom.xml配置
<plugins>
    <!-- 指定jdk1.7編譯,否則maven update 可能調整jdk -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
    <!-- tomcat7插件。使用方式:tomcat7:run -->
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <update>true</update>
            <port>8080</port>
            <uriEncoding>UTF-8</uriEncoding>
            <server>tomcat7</server>
            <!-- tomcat虛擬映射路徑 -->
            <staticContextPath>/store</staticContextPath>
            <staticContextDocbase>d:/file/store/</staticContextDocbase>
            <contextReloadable>false</contextReloadable>
            <useTestClasspath>true</useTestClasspath>
        </configuration>
    </plugin>
</plugins>

參考地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章