2017-08-31 162 views
0

我有一個模擬服務器,我需要在運行我的自動化測試之前在Jenkins中啓動,然後在運行測試後停止模擬服務器。如何停止Maven執行

這個模擬服務器是一個maven項目,正在使用exec-maven-plugin。我可以通過運行命令mvn exec:java來啓動此服務器。但是我無法通過Jenkins阻止這個maven項目。我已經閱讀了它,大多數答案告訴找到這個Maven項目的進程ID,然後殺死它。有沒有更簡單更簡單的方法來阻止這個項目?

回答

0

您需要使用goals作爲maven生命週期的一部分來啓動和停止服務器。

this answer

<plugin> 
     <groupId>org.apache.tomcat.maven</groupId> 
     <artifactId>tomcat7-maven-plugin</artifactId> 
     <version>2.1</version> 
     <executions> 
      <execution> 
      <id>tomcat-run</id> 
      <goals> 
       <goal>run-war-only</goal> 
      </goals> 
      <phase>pre-integration-test</phase> 
       <configuration> 

        <fork>true</fork> 
       </configuration> 

      </execution> 
      <execution> 
      <id>tomcat-shutdown</id> 
      <goals> 
       <goal>shutdown</goal> 
      </goals> 
      <phase>post-integration-test</phase> 
      </execution> 
     </executions> 
     </plugin> 
0

的關鍵帶到這個問題的一個例子的確是你不知道的ProcessID。考慮使用exec:exec而不是async。你會發現asyncDestroyOnShutdown默認設置爲true,這意味着一旦Maven關閉,它將關閉。