虽然在这里得到了回答,但认为最好发布 xml 的外观:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/myPath</path>
<staticContextPath>/images</staticContextPath>
</configuration>
</plugin>
另一个答案使用staticContextDocbase而不是staticContextPath,我无法分辨两者之间的区别,但其中一个应该可以工作。不过,我自己还没有尝试过;)
Tomcat的这两个属性的文档:
静态上下文文档库:
静态上下文 docroot 基本完全限定路径
静态上下文路径:
静态上下文
可能fully qualified path与相对路径相反。
好吧,我深入研究了插件和 Apache 的代码,发现你需要两者 staticContextDocbase和staticContextPath.
staticContextDocbase是 Tomcat 应该从中检索静态上下文的路径。在您的情况下,它是C:/images.
staticContextPath是 URLhttp://<hostname>:<port>中应将静态上下文发送给客户端的部分。在您的情况下,它是/images.
Maven 应该这样配置:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/myPath</path>
<staticContextPath>/images</staticContextPath>
<staticContextDocbase>C:/images</staticContextDocbase>
</configuration>
</plugin>
另一个注意事项:
如此处所见,插件使用Tomcat.addContext(String contextPath, String baseDir)、staticContextPath传递为contextPath和staticContextDocbase传递为baseDir。的文档baseDir声明它Must exist, relative to the server home。
OTOH,baseDir按原样移动到Context.setBaseDir(String docBase). 该方法的文档baseDir说明This can be an absolute pathname, a relative pathname, or a URL..
然后尝试完整路径。如果它不起作用去亲戚;)。