我一直在使用 mvn tomcat7-maven-plugin:run -am -pl :foo
在 Tomcat like is shown here 中一次成功地运行一个项目.现在我想让多个模块在同一个端口但不同的上下文下运行。例如,我想要:
/ => foo.war
/bar => bar.war
这是我一直在使用的示例 pom.xml 片段:
<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.org/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.net.BindException:地址已经在使用:8080”。
最佳答案
正如已经建议的那样,使用 <webapps>
插件配置部分,但添加附加参数<asWebapp>true</asWebapp>
对于每个 webapp,即:
<webapps>
<webapp>
<groupId>com.company</groupId>
<artifactId>mywebapp</artifactId>
<version>1.0</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
<webapp>
<groupId>com.company</groupId>
<artifactId>mywebapp2</artifactId>
<version>2.0</version>
<type>war</type>
<asWebapp>true</asWebapp>
</webapp>
</webapps>
这些额外的 web 应用程序使用 ${artifactId}
进行部署默认情况下的上下文路径。
看起来如果没有这个参数,当你运行类似 mvn tomcat7:run
的东西时,额外的 webapps 会被默默地丢弃。 (在稳定版本 2.0 上尝试过)。 Related Jira issue告诉它是为了“向后兼容性”而完成的。
关于java - 如何使用maven插件tomcat7 :run with multiple contexts (WARs)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11959975/