2012-09-16 47 views
4

這個問題是不一樣的MyBatis 3.0.5 and mappers loading problemHow to suppress Maven "Unable to find resource" messages?爲什麼Eclipse項目源目錄中的xml文件沒有複製到目標/ classes目錄?

我有XML文件中org.org.wpse.db.config.db.config包,但爲什麼我不能在目標/班找到這些XML文件/組織/ wpse/db/config /目錄,即使我運行mvn編譯。

這個錯誤導致了以下faillure當我使用的MyBatis:

Could not find resource 

從而導致這個錯誤的問題是,.xml文件不會被複制到build目錄,即使我當我用MVN明確編譯

+0

這哪裏是包 - 在'的src/main/java'或'的src/main/resources'? – Raghuram

回答

8

Maven默認在src/main/resources目錄下查找資源文件,即* .xml,* .properties等。建議將您的資源文件放在這裏。

然而,沒有什麼阻止你把資源文件在其他地方,例如,src/main/java/org/wpse/db/config/,因爲有些人喜歡把資源文件與類文件一起下特殊的包,你只需要在pom.xml中多了幾分配置:

<build> 
    <resources> 
    <resource> 
     <!-- This include everything else under src/main/java directory --> 
     <directory>${basedir}/src/main/java</directory> 
     <excludes> 
     <exclude>**/*.java</exclude> 
     </excludes> 
    </resource> 
    </resources> 

    ... ... 
</build> 

相關問題:how to customize maven to generate the .classpath that i want?

使用默認配置,運行mvn eclipse:eclipse當它產生以下.classpath文件:

<classpath> 
    <classpathentry kind="src" path="src/main/java" including="**/*.java"/> 
    ... ... 
</classpath> 
... ... 

當導入到Eclipse中,它給你以下的classpath(你不想要的東西):

enter image description here

使用上面的POM的配置,運行「MVN時日食:日食」它會生成以下.classpath文件:

<classpath> 
    <classpathentry kind="src" path="src/main/java"/> 
    ... ... 
</classpath> 
... ... 

當導入到Eclipse中,它給你follwing類路徑(你想要的):

enter image description here

相關問題