【问题标题】:Running mvn install with running tomcat plugin parallel运行 mvn install 并并行运行 tomcat 插件
【发布时间】:2013-11-22 02:23:21
【问题描述】:

项目中有单元测试和前端html测试需要运行webserver。 为了mvn install 顺利通过,我需要这两种测试都顺利通过。 我使用嵌入式 tomcat 服务器,它是通过 maven 的 tomcat 插件启动的:

mvn tomcat7:run

所以,我启动了 tomcat(我的前端 html 测试需要它), 然后尝试在命令行中启动:mvn install,但得到以下错误:

D:\PROJECTS\SpringMvcExample>mvn install
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:741]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)

同时,当tomcat启动时,我可以通过Intellij Idea插件为maven运行mvn install,它运行良好,没有任何错误。

我的问题是如何配置才能在命令行中启动maven?

这是一个maven多模块项目,这里是web模块的pom.xml:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 

http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.savdev</groupId>
    <artifactId>SpringMvcExample</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>SpringMvcExample Webapp</name>

<properties>
    <spring.version>3.2.4.RELEASE</spring.version>
    <selenium.version>2.37.1</selenium.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <!--modules dependency start-->
    <dependency>
        <groupId>com.savdev</groupId>
        <artifactId>model</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.savdev</groupId>
        <artifactId>service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <!--modules dependency end-->

    <!--web dependency start-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.2.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.2.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>runtime</scope>
    </dependency>
    <!--web dependency end-->

    <!--tests dependency-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>org.mockito</groupId>-->
        <!--<artifactId>mockito-all</artifactId>-->
        <!--<version>1.9.5</version>-->
        <!--<scope>test</scope>-->
    <!--</dependency>-->
    <dependency>
        <groupId>net.sourceforge.jwebunit</groupId>
        <artifactId>jwebunit-core</artifactId>
        <version>3.1</version>
        <scope>test</scope>
    </dependency>
    <!--<dependency>-->
        <!--<groupId>net.sourceforge.jwebunit</groupId>-->
        <!--<artifactId>jwebunit-htmlunit-plugin</artifactId>-->
        <!--<version>3.1</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>net.sourceforge.htmlunit</groupId>-->
        <!--<artifactId>htmlunit</artifactId>-->
        <!--<version>2.13</version>-->
    <!--</dependency>-->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-htmlunit-driver</artifactId>
        <version>${selenium.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <finalName>SpringMvcExample</finalName>
    <!--to run into debug mode set:-->
    <!--export MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n-->
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <path>/SpringMvcExample</path>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 请附上您的pom.xml

标签: java maven configuration embedded-tomcat-7


【解决方案1】:

尝试将tomcat run/shutdown绑定到合适的&lt;execution&gt;阶段:

<phase>pre-integration-test</phase>
<goals>
  <goal>run</goal>
</goals>

<phase>post-integration-test</phase>
<goals>
  <goal>shutdown</goal>
</goals>

这样配置你不应该手动启动tomcat(即mvn tomcat7:run)。它应该在测试之前自动运行并在测试之后关闭。

【讨论】:

    猜你喜欢
    • 2021-04-23
    • 2021-12-14
    • 2013-11-16
    • 2013-06-29
    • 2023-03-18
    • 1970-01-01
    • 2021-09-28
    • 2023-03-18
    • 2016-11-11
    相关资源
    最近更新 更多