虽然是answered here,但我认为最好发布 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 是 URL 中 http://<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>
另一个说明:
As seen here,插件使用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 的that 方法的文档指出This can be an absolute pathname, a relative pathname, or a URL.。
然后尝试完整路径。如果它不工作去亲戚;)。