Tomcat 7 Maven插件多个上下文 [英] Tomcat 7 Maven Plugin multiple context
问题描述
在pom.xml的当前状态下,我拥有
In my current state of the pom.xml i have
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>/myPath</path>
</configuration>
</plugin>
这很好.我现在正在尝试为服务器上的图像添加额外的上下文,
以便将旧"上下文/myPath
定向到Webapp,并且/images
可用于寻址图像.
我试图添加一个上下文文件,但是当我这样做时,只会加载我的/images
上下文.
另外,我不想每次都构建WAR(如果我在两个上下文中使用两个context.xml文件,情况就是这样)
this is working fine. I now am trying to add an extra context for the images on the server,
so that the "old" context /myPath
is directing to the webapp and /images
can be used to address images.
I have tried to add a context file, but when I do this only my /images
context is loaded.
Also, I don't want to build the WAR each time (this would be the case if I used two context.xml files for the two contexts)
是否可以添加a)上下文(使用tomcat7:run AND的当前开发状态)b)仅指向本地文件夹的第二个上下文/images? 以及如何?
Is it possible to add a) the context as it is (the current state of development using tomcat7:run AND b) the second context /images that only points to a local folder? And how?
推荐答案
尽管它是在这里回答,最好发布xml的外观:
Although it's answered here, thought it would be good to post how the xml should look like:
<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>
另一个答案使用 staticContextPath ,我无法分辨两者之间的区别,但是其中之一应该可以工作.不过,我自己还没有尝试过;)
The other answer uses staticContextDocbase instead of staticContextPath, and I can't tell the difference between the two, but one of then should work. Haven't tried it myself, though ;)
Tomcat的以下两个属性的文档:
staticContextDocbase:
staticContextDocbase:
静态上下文docroot基本完全限定路径
The static context docroot base fully qualified path
staticContextPath:
staticContextPath:
静态上下文
The static context
可能是 fully qualified path
与相对路径相反.
Could be that fully qualified path
is in contrast to relative path.
好吧,我对插件和Apache的代码进行了深入研究,发现您同时需要 和staticContextDocbase
和staticContextPath
.
Well, I delved a bit into the plugin and Apache's code and found that you need both staticContextDocbase
and staticContextPath
.
staticContextDocbase
是Tomcat应该从中检索静态上下文的路径.您的情况是C:/images
.
staticContextDocbase
is the path from where the static context should be retrieved by Tomcat. In your case it is C:/images
.
staticContextPath
是URL中http://<hostname>:<port>
之后的部分,应将其静态上下文发送给客户端.您的情况是/images
.
staticContextPath
is the part in the URL after the http://<hostname>:<port>
for which the static context should be sent to client. In your case it is /images
.
Maven的配置应如下:
Maven should be configured like so:
<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>
另一个说明:
Another note:
Tomcat.addContext(String contextPath, String baseDir)
,staticContextPath
作为contextPath
传递,而staticContextDocbase
作为baseDir
传递. baseDir
的文档指出它为Must exist, relative to the server home
.
As seen here, the plugin uses Tomcat.addContext(String contextPath, String baseDir)
, staticContextPath
is passed as contextPath
and staticContextDocbase
is passed as baseDir
. The doc for baseDir
states that it Must exist, relative to the server home
.
OTOH, that baseDir
is moved as is to Context.setBaseDir(String docBase)
. The doc on that method for baseDir
states that This can be an absolute pathname, a relative pathname, or a URL.
.
然后尝试完整路径.如果不起作用,请找亲戚;).
Try the full path then. If it doesn't work go for the relative ;).
这篇关于Tomcat 7 Maven插件多个上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!