在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的插件内部的问题,但用到
解决方式:
- 查看tomcat7-maven-plugin的源码,手动修改问题代码
- 替换大佬们修改好的jar包,下载tomcat7-maven-plugin-2.2替换maven仓库中的jar就好
三、测试结果
将上传的图片在虚拟路径中显示出来


浙公网安备 33010602011771号