【发布时间】:2013-03-18 15:13:18
【问题描述】:
tomcat7-maven-plugin 允许将当前项目作为 Web 应用程序运行,并且可以指定额外的 <webapps>,它们将同时加载到 tomcat 中。
我的项目不是 Web 应用程序,但它访问由 webapps 提供的服务。那么如何在不将项目本身作为 webapp 运行的情况下部署多个 webapps 呢?以下 Maven sn-p 导致 FileNotFoundExceptions,因为找不到 context.xml。
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>run-tomcat</id>
<phase>${tomcat.run.phase}</phase>
<goals><goal>run-war-only</goal></goals>
<configuration>
<webapps>
<webapp>
<contextPath>/my/app1</contextPath>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
... possibly more webapps ...
</webapps>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<phase>${tomcat.shutdown.phase}</phase>
<goals><goal>shutdown</goal></goals>
</execution>
</executions>
</plugin>
解决方法:
即使您的应用程序本身不是 webapp,您也需要为其配置 path 和 contextFile:
<configuration>
<path>/my/non/existing/webapp</path>
<contextFile>src/test/resources/context.xml</contextFile>
<webapps>
...
指定的context.xml 文件必须存在。以下对我有用,即使 web.xml 文件不存在:
<?xml version="1.0" encoding="utf-8"?>
<Context path="/my/non/existing/webapp">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
【问题讨论】:
-
能贴出maven输出的相关日志吗?
-
所以,Dominik,您在发布问题一个多小时后收到了回复,但您没有礼貌回复?
-
我添加了一个解决方法,可以解决问题。但我仍然希望有更好的方法来做到这一点......
-
Dominik,你在上下文文件中放了什么?当我使用上面的配置时,Tomcat7 会抛出错误“启动静态资源时出错”。你明白了吗?
-
我也需要能够做到这一点...寻找解决方案。您是否为此用例向 apache tomcat 团队提交了功能请求?
标签: maven web-applications tomcat7 maven-tomcat-plugin