2016-03-08 70 views
1

我試圖執行pom.xml其中提到的mainClass但它沒有被執行。無法從pom.xml執行mainClass

命令:mvn test -f "path_to_pom.xml\pom.xml"

輸出:

[INFO] Scanning for projects... 
[INFO] 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Project 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @Project --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, 
i.e. build is platform dependent! 
[INFO] Copying 3 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ Project --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Project --- 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, 
i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory D:\Personal\selenium\Project\src\test\resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @Project --- 
[INFO] Changes detected - recompiling the module! 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b 
uild is platform dependent! 
[INFO] Compiling 5 source files to D:\Personal\selenium\Project\target\test-classes 
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ Project --- 
[WARNING] useSystemClassloader setting has no effect when not forking 
[INFO] Surefire report directory: D:\Personal\selenium\Project\target\surefire-reports 
Running test.java.com.utilities.TestController 
Configuring TestNG with: TestNG652Configurator 
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.295 sec - in t 
est.java.com.utilities.TestController 

Results : 

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 3.138 s 
[INFO] Finished at: 2016-03-08T11:45:54+05:30 
[INFO] Final Memory: 20M/225M 
[INFO] ------------------------------------------------------------------------ 

我試圖從蝕IDE執行它,但沒有被從那裏太執行。

但是,在cmd的maven命令中指定-DmainClass="<className>",正在執行類。

下面是pom.xml的條目:

<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>test.java.com.utilities.TestController</mainClass> 
    </configuration> 
</plugin> 

我已經做MVN清潔和Maven>更新項目,但它並沒有幫助。

問題:可以做些什麼其他更改?

+0

請顯示完整的pom文件 – khmarbaise

+0

'-DmainClass'不應該工作,命令行屬性是'exec.mainClass',你確定嗎? –

回答

0

你想在你的testphase期間執行這個類,因此你應該將它添加到你的插件execution。此外,似乎你正在運行一個測試包中的一個類,它可能也需要test classpath才能正確執行。

我會然後採用下列更改您發佈的配置:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.2.1</version> 
    <executions> 
     <execution> 
      <phase>test</phase> <!-- ADDED --> 
      <goals> 
       <goal>java</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <mainClass>test.java.com.utilities.TestController</mainClass> 
     <classpathScope>test</classpathScope> <!-- ADDED --> 
    </configuration> 
</plugin> 

注意ADDED元素通過意見突出。

+0

謝謝。它確實像魔術一樣工作。謝謝哥們。 – Sagar