1. 在 pom 中默認的源代碼目錄是:java
sourceDirectory 來配置,因此只能配置一個源代碼目錄,maven
而對於資源目錄則能夠經過如下方式來配置多個。ui
1 <resources> 2 <resource> 3 <directory>src/main/java</directory> 4 <includes> 5 <include>**/*.properties</include> 6 <include>**/*.xml</include> 7 <include>**/*.tld</include> 8 <include>**/*.txt</include> 9 </includes> 10 <filtering>false</filtering> 11 </resource> 12 13 <resource> 14 <directory>src/main/resource</directory> 15 </resource> 16 </resources>
上面的配置其實就是對源代碼目錄中的一些配置文件,例如 *.properties, *.xml. *.txt 等加入到編譯以後的目錄中。不然運行時會報錯。spa
2. sourceDirectory 只能配置一個,因此要藉助插件來完成額外的源碼目錄的配置。插件
1 <plugin> 2 <groupId>org.codehaus.mojo</groupId> 3 <artifactId>build-helper-maven-plugin</artifactId> 4 <version>1.10</version> 5 <executions> 6 <execution> 7 <id>add-source</id> 8 <phase>generate-sources</phase> 9 <goals> 10 <goal>add-source</goal> 11 </goals> 12 <configuration> 13 <sources> 14 <source>${project.basedir}/src/jave/othersource</source> 15 </sources> 16 </configuration> 17 </execution> 18 </executions> 19 </plugin>