tomcat7-maven-plugin
允许将当前项目作为Web应用程序运行,并且可以指定另外的<webapps>
将同时加载到tomcat中。Tomcat - Maven插件:运行webapps但不是当前项目
我的项目不是一个Web应用程序,但它访问由webapps提供的服务。那么如何在不将项目本身作为Web应用程序运行的情况下部署多个Web应用程序?以下Maven代码片段导致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>
解决方法:
即使您的应用程序本身就不是一个web应用程序,你需要配置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输出的相关日志吗? – ben75 2013-03-18 16:26:17
因此,多米尼克,你在发布你的问题后一个多小时内得到答复,但你没有礼貌回应? – 2013-07-30 01:16:11
我添加了一个解决方法,它解决了这个问题。但我仍然希望有更好的方法来做到这一点...... – dokaspar 2013-07-31 07:00:12