답변

0

당신은 MVN 시험과 TestNG를 실행하는 플러그인 받는다는을 사용한다

<build> 
     <!-- Source directory configuration --> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <!-- Following plugin executes the testng tests --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.14.1</version> 
       <configuration> 
        <!-- Suite testng xml file to consider for test execution --> 
        <suiteXmlFiles> 
         <suiteXmlFile>testng.xml</suiteXmlFile> 
         <suiteXmlFile>suites-test-testng.xml</suiteXmlFile> 
        </suiteXmlFiles> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

당신은 정말 당신은 그늘 플러그인 필요 (나는 당신이 생각하지 않는다) 실행 항아리를 원하는 경우 :

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.greg</groupId> 
    <artifactId>tester</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>tester</name> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
    .... 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-shade-plugin</artifactId> 
       <version>3.0.0</version> 
       <executions> 
        <execution> 
         <phase>package</phase> 
         <goals> 
          <goal>shade</goal> 
         </goals> 
         <configuration> 
          <transformers> 
           <transformer 
             implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> 
            <manifestEntries> 
             <Main-Class>com.greg.Application</Main-Class> 
            </manifestEntries> 
           </transformer> 
          </transformers> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 
    </build> 

</project> 
+0

에 섹스, 안녕하세요, "오류 : 주 클래스를 찾지 못했습니다."라는 오류 메시지가 나타납니다. 또한 main 메소드에서 testng.xml을 사용합니다. testng.xml이 응용 프로그램 외부에있을 때 어떻게 참조 할 수 있습니까? 또한 어떤 목표를 사용할지 알려주세요. –

0

1 간단한 방법은, 당신이 바로 일식 추적을 클릭하여 실행 항아리를 만들 수 있습니다 - https://www.mkyong.com/java/how-to-make-an-executable-jar-file/

그리고 호출합니다 1 개 자바 클래스를 생성 요 testNG XML 파일을 읽고 testNG.run()을 사용하여 실행하십시오.

공용 클래스 InvokeTestNGJava {

/** 
* @param args 
*/ 
public static void main(String[] args) throws Exception { 
    System.out.println("Started!"); 
    TestNG testng = new TestNG(); 
    List<String> suites = Lists.newArrayList(); 
    suites.add("src"+File.separator+"main"+File.separator+"resources"+File.separator+"stats-comparison.xml"); 
    testng.setTestSuites(suites); 
    testng.run(); 
} 

}

그리고 자바 클래스를 사용하여 실행됩니다 - 자바 -classpath yourjar.jar youpackage.InvokeTestNGJava. 간단하게 testng xml을 호출하고 실행합니다.

관련 문제