Fork me on GitHub

在Maven上配置tomcat的虚拟路径

在Maven上配置tomcat的虚拟路径(通过tomcat7-maven-plugin坐标)

一、引入坐标

      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <!-- tomcat虚拟映射路径 -->
          <staticContextPath>/rgimg</staticContextPath>
          <!-- 设置本地存放图片的路径-->
          <staticContextDocbase>D:/Java6722/16JavaWs6722/upImg/</staticContextDocbase>
          <contextReloadable>true</contextReloadable>
          <useTestClasspath>true</useTestClasspath>
        </configuration>
      </plugin>

二、测试

在测试的途中报错Child name ‘/xxx‘ is not unique

Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run (default-cli) on project engineer_center_web: Execution default-cli of goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:run failed: addChild:  Child name '/rgimg' is not unique -> [Help 1]

大概意思路径不唯一,于是开启了我的百度之路,了解了报错的大概原因,是由于tomcat7-maven-plugin的插件内部的问题,但用到/upload标签的时候,tomcat会自动创建两个"/upload",所以会产生路径不唯一的问题。

解决方式:

  • 查看tomcat7-maven-plugin的源码,手动修改问题代码
  • 替换大佬们修改好的jar包,下载tomcat7-maven-plugin-2.2替换maven仓库中的jar就好

三、测试结果

将上传的图片在虚拟路径中显示出来

posted @ 2022-09-13 22:48  嘻瓜沁  阅读(354)  评论(0)    收藏  举报