2011-07-18 131 views
18

在我的代碼中,我已經設置爲在./目錄中創建一些文件,因爲當軟件將部署在安裝機器中時,所有配置文件將在./中創建(如果它是第一次運行Maven:更改執行測試的目錄

不幸的是,當我構建項目並且Maven執行測試時,所有文件都在項目目錄中創建。
我想要創建這些文件在target/test-run/
我該怎麼辦?

感謝

回答

29

如果您使用的是萬無一失的插件來執行測試(這是默認值),那麼你可以設置工作目錄是這樣的:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.7.2</version> 
      <configuration> 
       <workingDirectory>${java.io.tmpdir}</workingDirectory> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

參考:http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo.html

要設置爲問題中的具體目錄:

<workingDirectory>${project.build.directory}/test-run</workingDirectory> 
+0

Tha恩,你非常有幫助! – yelo3