【问题标题】:Tomcat 7 Maven Plugin multiple contextTomcat 7 Maven 插件多上下文
【发布时间】:2013-07-16 10:46:12
【问题描述】:

在我当前的 pom.xml 状态中,我有

<plugin>  
  <groupId>org.apache.tomcat.maven</groupId>  
  <artifactId>tomcat7-maven-plugin</artifactId>  
  <version>2.0</version>  
  <configuration>  
    <path>/myPath</path>  
  </configuration>
</plugin>

这工作正常。我现在正在尝试为服务器上的图像添加额外的上下文, 以便“旧”上下文 /myPath 指向 web 应用程序,/images 可用于处理图像。
我试图添加一个上下文文件,但是当我这样做时,只加载了我的 /images 上下文。
另外,我不想每次都构建 WAR(如果我为两个上下文使用两个 context.xml 文件,就会出现这种情况)

是否可以添加 a) 上下文(使用 tomcat7:run 的当前开发状态​​和 b)仅指向本地文件夹的第二个上下文 /images? 怎么做?

【问题讨论】:

标签: tomcat7 maven-tomcat-plugin


【解决方案1】:

虽然是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 的代码,发现您需要两个 staticContextDocbasestaticContextPath

staticContextDocbase 是 Tomcat 应该从中检索静态上下文的路径。在您的情况下,它是C:/images

staticContextPath 是 URL 中 http://&lt;hostname&gt;:&lt;port&gt; 之后的部分,其静态上下文应发送到客户端。在您的情况下,它是/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)。关于baseDirthat 方法的文档指出This can be an absolute pathname, a relative pathname, or a URL.

然后尝试完整路径。如果它不工作去亲戚;)。

【讨论】:

  • 那么我怎样才能将本地文件夹链接到静态路径呢?
  • @MatthiasG 你叫什么local folder
  • 我想让我的上下文 ( /myPath ) 指向正在开发的 webapp,并且 localhost:8080/images 指向即 C:\data\images
  • @MatthiasG 所以尝试使用 staticContextDocbase(记录为静态上下文的完全限定路径)。
  • 这是 tomcat7-maven-plugin 中的一个错误,已在 2.3-SNAPSHOT 中修复。尝试使用 2.3-SNAPSHOT,它应该可以工作。
猜你喜欢
  • 2012-08-25
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 1970-01-01
  • 2013-11-21
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多