【问题标题】:How to execute the multiple java programs using pom.xml如何使用 pom.xml 执行多个 java 程序
【发布时间】:2013-07-25 04:57:19
【问题描述】:

我是 maven pom.xml 的新手

没有办法使用 pom.xml 执行 .java 文件 如果有 有什么事请发给我。

这个 java 文件有 selenium 代码(Junit 代码)

例如:

package com.mycompany.app; 

import com.thoughtworks.selenium.*; 
import org.junit.BeforeClass; import org.junit.Test; import
org.testng.annotations.AfterClass; import
org.testng.annotations.AfterGroups; import
org.testng.annotations.BeforeGroups;

public class App4 {

    @Test
    public void Login1() throws Exception {
        System.out.println("*******Love u mom*******");
    }

}

【问题讨论】:

    标签: maven maven-2 maven-3


    【解决方案1】:

    要运行 Junit 测试,您可以使用 Maven Surefire Plugin。只需将其添加到您的 pom 中:

    <build>
        ...
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
            </plugin>
        </plugins>
    </build>
    

    默认情况下,它会在${basedir}/target/surefire-reports 下生成两个文本和 xml 格式的报告。

    默认情况下,它希望在src/test/java(maven 约定)下找到您的测试。在那里找到的所有测试都将被执行。

    【讨论】:

    • 请告诉我如何运行 pom.xml
    • 运行 pom?我猜你的意思是执行maven?在命令行中,您可以简单地输入mvn test,这将执行直到并包括maven 构建lifecycle 的测试阶段的所有内容。如果您在 Eclipse 中运行,则右键单击 pom.xml 窗口编辑器 --> 运行方式 --> Maven 测试应该可以工作。
    【解决方案2】:

    最简单的解决方案是使用专门用于此目的的exec-maven-plugin。您可以像这样使用java 目标,或者您可能需要exec 目标。

    <project>
      ...
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
              <execution>
                ...
                <goals>
                  <goal>java</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <mainClass>com.example.Main</mainClass>
              <arguments>
                <argument>argument1</argument>
                ...
              </arguments>
              <systemProperties>
                <systemProperty>
                  <key>myproperty</key>
                  <value>myvalue</value>
                </systemProperty>
                ...
              </systemProperties>
            </configuration>
          </plugin>
        </plugins>
      </build>
       ...
    </project>
    

    【讨论】:

    • 感谢重播以及如何运行 pom.xml 右键单击​​ pom.xml 窗口编辑器 --> 运行方式 -->Maven 测试。我们可以在哪里找到这个 pom.xml 执行的输出。
    • 嗨,khmarbaise,请参阅上面提到的代码并告诉如何执行 pom.xml 也
    • 现在情况发生了变化,因为现在我们谈论的是完全不同的集成测试。您应该深入了解 maven-failsafe-plugin 以执行集成测试。 Take a detailed and deep look here.
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 2023-03-04
    • 2021-07-08
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 2011-04-08
    • 2013-07-09
    相关资源
    最近更新 更多