在我的項目中,我有一個包含屬性和XML文件的資源目錄(src/main/resources
)。在Eclipse中導入Maven2項目時出現問題
我想過濾只有屬性文件,但不是任何其他類型的文件(例如XML)。因此,我在設置這個我pom.xml
:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
</build>
這是工作好,當我運行一個Maven 2包命令,XML和性質,即文件都包含在我的最後JAR,只有屬性文件已過濾。
但是,因爲我想將此項目包含在Eclipse中,所以當我運行命令mvn eclipse:eclipse
並導入該項目時,我遇到了在我的項目屬性中聲明的源代碼的問題。
在Eclipse的我的項目的「Java構建路徑」選項,在選項卡中的「源」,我看到了src/main/resources
目錄,但Eclipse還添加過濾器,這不能不排除所有Java文件(Excluded: **/*.java
)和包括只屬性文件(Included: **/*.properties
)。
中產生的.classpath
文件,我得到這一行:
<classpathentry kind="src" path="src/main/resources" including="**/*.properties" excluding="**/*.java"/>
這樣,通過Eclipse的生成JAR不正確的,因爲我所有的XML文件不在JAR。
我該如何解決這個問題?
編輯,對此page,我在添加了這個我pom.xml
:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.6</version>
<configuration>
<sourceIncludes>
<sourceInclude>**/*.xml</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
然而,生成不與足夠的信息修正後的.classpath ...
再次編輯。
我以前的編輯中的附加功能僅適用於Eclipse插件2.6.1及更高版本,不適用於2.6。所以,我已經嘗試過2.7版本。不過,我不知道如何強制Eclipse插件不定義包括屬性:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<configuration>
<sourceIncludes>
<sourceInclude>*</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
</plugins>
如果我運行mvn eclipse:eclipse
命令,我收到以下錯誤:
Request to merge when 'filtering' is not identical. Original=resource src/main/resources: output=target/classes, include=[**/*.properties], exclude=[**/*.java], test=false, filtering=true, merging with=resource src/main/resources: output=target/classes, include=[], exclude=[**/*.properties|**/*.java], test=false, filtering=false
我認爲你必須在你的代碼中的錯誤 - 你既包括和。排除'* .properties'文件? – 2009-10-20 15:46:18
這不是一個錯誤。我有兩個資源子集s:第一個只包含'properties'文件和* filter *它們。第二個只排除'properties'文件,*不會對它們進行過濾。這是我發現包含src/main/resources'中所有文件的唯一方法,並且只篩選其中的一部分... – romaintaz 2009-10-20 15:50:51
對,我現在明白了。 – 2009-10-20 15:52:19