2013-01-13 79 views
1

我有一個要求將我的構建輸出到不同的目錄到目標m2e忽略測試資源的testOutputDirectory

使用project.build.directory輸出testOutputDirectory性工作正常使用mvn clean install的命令行,但是當我從Eclipse構建它,如果我有一個src/test/resources目錄中創建一個空的target/test-classes目錄。

具有相同行爲的一個簡單的POM文件看起來像:

<project> 
    <groupId>com.example</groupId> 
    <version>1.0.0</version>  
    <modelVersion>4.0.0</modelVersion> 
    <artifactId>reproduce</artifactId> 
    <packaging>war</packaging> 
    <properties> 
     <project.build.directory>differentTarget</project.build.directory> 
     <project.build.outputDirectory>${project.build.directory}/classes</project.build.outputDirectory> 
     <project.build.testOutputDirectory>${project.build.directory}/different-test-classes</project.build.testOutputDirectory> 
    </properties> 

    <build> 
     <directory>${project.build.directory}</directory> 
     <outputDirectory>${project.build.outputDirectory}</outputDirectory> 
     <testOutputDirectory>${project.build.testOutputDirectory}</testOutputDirectory> 
    </build> 
</project> 

我的目錄結構如下:

|-src 
    |---main 
    |-----webapp 
    |-------WEB-INF 
    |---test 
    |-----resources 

我可以重現行爲的最簡單的方法是用所有的目錄空除了其中包含<web-app />的web.xml。

當我有實際的測試類時,它會在target/test-classes目錄內創建文件夾,但會將實際的類文件放入differentTarget/test-classes

我使用Eclipse的靛藍M2E 1.2.0Maven的集成WTP 0.15.3Debian的

編輯

如果我刪除properties和硬輸出代碼:

<build> 
    <directory>differentTarget</directory> 
    <outputDirectory>differentTarget/classes</outputDirectory> 
    <testOutputDirectory>differentTarget/different-test-classes</testOutputDirectory> 
</build> 

然後我得到正確的行爲,當我去的Maven>更新項目...,但我仍然得到不正確的目標文件夾,當我去項目>清潔或更重要的是有它自動構建

+0

您是否試過[this](http://www.youtube.com/watch?v=oHg5SJYRHA0)的方法? –

+1

我在其他幾個地方看到過,但在這種情況下沒有用處。 – n00begon

回答

2

嘗試檢查您的輸出文件夾是否爲您的Java構建路徑。 m2e插件可能無法更新所有輸出路徑:

右鍵單擊您的項目 - >構建路徑 - >配置構建路徑。

在「源」選項卡上展開每個條目,編輯「輸出文件夾」並將每個條目切換回項目默認值。

+0

構建項目時的錯誤行爲。它有'目標/測試類'作爲輸出文件夾 – n00begon

1

默認情況下,所有Maven POM都會繼承Super POM。如果你看看Maven Super POM,你可以看到testOutputDirectory被定義爲project/build下的一個元素。我不確定你是否打算將其設置爲財產。嘗試覆蓋元素<testOutputDirectory>直接在您的<版本>版塊

+0

如果我刪除屬性並直接使用** testOutputDirectory **,我會得到相同的行爲' differentTarget/different-test-classes' – n00begon

1

有時m2e不會收到更改。

所以選擇你的項目,用鼠標右鍵單擊 - > Maven - >更新項目

enter image description here

如果沒有幫助,刪除文件夾.settings,然後再試一次。

編輯:

也許它無法翻譯在構建部分使用的屬性。嘗試硬編碼:

<build> 
    <directory>differentTarget</directory> 
    <outputDirectory>differentTarget/classes</outputDirectory> 
    <testOutputDirectory>differentTarget/different-test-classes</testOutputDirectory> 
</build> 
+0

謝謝,我已經嘗試了這兩個,但仍然得到相同的結果。即使我只有web.xml以外的空目錄並將其作爲新項目導入,它也會產生相同的行爲。 – n00begon

+0

嘗試在編譯部分中使用硬編碼值(請參閱編輯) – asgoth

+0

我試過對@gerrytan的答案,不幸的是它仍然給出了創建目標文件夾的相同結果。 – n00begon