是否有一种简单的方法可以在pom或命令行中为Tomcat指定备用端口.我想在同一台机器上运行几个项目.
Vin*_*ter 104
我知道这个帖子已经老了但是......
Greg提供的文档链接很有趣:
port:
The port to run the Tomcat server on.
Type: int
Required: No
Expression: ${maven.tomcat.port}
Default: 8080
Run Code Online (Sandbox Code Playgroud)
表达式是maven用来获取代码中的值的表达式.它可以来自配置文件,也可以来自命令行.
你可以跑
mvn -Dmaven.tomcat.port=8181 tomcat:run-war
Run Code Online (Sandbox Code Playgroud)
Gre*_*reg 28
使用tomcat-maven-plugin上给出的语法,您可以直接指定端口:
Run Code Online (Sandbox Code Playgroud)<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <configuration> <server>tomcat-development-server</server> <port>9966</port> </configuration> </plugin>
red*_*olo 28
当我有几个小servlet同时运行它们的集成测试阶段时,我遇到了类似的问题,因为那些配置为使用相同的端口而成为一个问题.但是由于build-helper-maven-plugin:reserve-network-port目标,可以获得可用的随机端口号.然后我可以创建一个包含http:// localhost:[port]/[servletname]的URL,该URL 被提供给 Java测试类.
检索随机端口:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<portNames>
<portName>tomcat.http.port</portName>
</portNames>
</configuration>
</execution>
</executions>
Run Code Online (Sandbox Code Playgroud)
用端口启动tomcat
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<configuration>
<port>${tomcat.http.port}</port>
<useTestClasspath>true</useTestClasspath>
</configuration>
....
</plugin>
Run Code Online (Sandbox Code Playgroud)
将URL提供给由failsafe插件运行的Java集成测试
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.3</version>
....
<configuration>
<systemPropertyVariables>
<integration-test.url>http://localhost:${tomcat.http.port}/${project.build.finalName}/</integration-test.url>
</systemPropertyVariables>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Java代码
public class DownloadAreaIT {
private static final String URL = System.getProperty("integration-test.url");
}
Run Code Online (Sandbox Code Playgroud)
以下为我工作:
<properties>
<maven.tomcat.port>9090</maven.tomcat.port>
</properties>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>${maven.tomcat.port}</port>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是maven tomcat插件,则可以通过在pom.xml中添加插件配置块来指定context.xml :
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<configuration>
<mode>both</mode>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
Run Code Online (Sandbox Code Playgroud)
使用的默认 context.xml 文件位于src/main/webapp/META-INF/context.xml
。
在那里设置不同的端口。
归档时间: |
|
查看次数: |
79148 次 |
最近记录: |