在maven项目中的pom.xml文件中对tomcat插件进行了虚拟目录的配置,如下
<configuration>
<update>true</update>
<server>tomcat7</server>
<port>8080</port>
<path>/</path>
// 下面两句便是配置虚拟目录
<staticContextPath>/file</staticContextPath>
<staticContextDocbase>D:/file</staticContextDocbase>
<uriEncoding>utf-8</uriEncoding>
<server>tomcat7</server>
</configuration>
启动后报了如下的错误
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 '/file' is not unique -> [Help 1]
意思是说在tomcat里的 '/file' 这个路径不为一,于是博主开始了漫长的查找之旅,百度里得不到结果,便上了谷歌,还真找到了,在 StackOverFlow 某一个帖子(忘记收藏了),大佬们说是tomcat7-maven-plugin:2.2这个插件内部的问题,用到 <staticContextPath>/file</staticContextPath> 这个配置后,启动时tomcat会自动创建两个“/file”,所以就报错child名字不唯一啦。
解决思路
- 自己去看好好看看tomcat7-maven-plugin:2.2这个jar包的源码,找出“/file”被创造多一次的原因,当然,这必然艰辛,但对个人的学习是非常有益的 (-__-)b。
- 更换掉maven仓库里的jar包,直接使用大佬们修整好的,下载 tomcat7-maven-plugin-2.2.jar.zip 。