问题描述
我一直在使用 mvn tomcat7-maven-plugin:run -am -pl :foo
成功地在 Tomcat 就像在这里显示.现在我想让多个模块在同一个端口但不同的上下文下运行.例如,我想要:
I've been using mvn tomcat7-maven-plugin:run -am -pl :foo
successfully to run just a single project at a time in Tomcat like is shown here. Now I'd like to have multiple modules run under the same port but different contexts. For instance, I'd like to have:
/ => foo.war
/bar => bar.war
这是我一直在使用的示例 pom.xml 片段:
Here's an example pom.xml snippet that I've been working with:
<project><!-- ... -->
<build><!-- ... -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<configuration>
<path>/</path>
<port>8080</port>
<addContextWarDependencies>true</addContextWarDependencies>
<addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
<warSourceDirectory>${project.build.directory}/${project.build.finalName}/</warSourceDirectory>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bar</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>tomcat</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshots</name>
<url>http://repository.apache/content/groups/snapshots-group/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
这可以通过 tomcat7-maven-plugin:run
插件实现吗?我正在努力寻找正确的语法来让它发挥良好的作用.当我运行 maven
命令来运行它时,它只运行它在项目层次结构中找到的第一个.如果我使用 <fork>true</fork>
或者显然是从不同的终端运行它们,那么我会得到java.BindException:地址已经在使用:8080".
Is this possible with the tomcat7-maven-plugin:run
plugin? I'm struggling to find the correct syntax to get it to play well. When I run the maven
command to run it, it only runs the first one it finds in the project hierarchy. And if I run them with the <fork>true</fork>
or obviously from different terminals then I get "java.BindException: Address already in use :8080".
推荐答案
正如已经建议的那样,使用插件配置的
部分,但添加额外的参数 ;true</asWebapp>
对于每个 webapp,即:
As it was already suggested, use <webapps>
section of plugin configuration, but add additional parameter <asWebapp>true</asWebapp>
for every webapp, i.e:
<webapps>
<webapp>
<groupId>company</groupId>
<artifactId>mywebapp</artifactId>
<version>1.0</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
<webapp>
<groupId>company</groupId>
<artifactId>mywebapp2</artifactId>
<version>2.0</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
</webapps>
默认情况下,这些额外的 web 应用程序使用 ${artifactId}
上下文路径进行部署.
These additional webapps are deployed with ${artifactId}
context path by default.
当您运行类似 mvn tomcat7:run
(在稳定版本 2.0 上尝试)时,看起来如果没有此参数,其他 web 应用程序会被悄悄丢弃.相关的 Jira 问题 表明它是为了向后兼容"而完成的.
It looks like without this parameter additional webapps get silently discarded when you run something like mvn tomcat7:run
(tried on stable version 2.0). Related Jira issue tells it was done for "backward compatibility".
这篇关于如何使用 maven 插件 tomcat7:run with multiple contexts (WARs)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论