Including Resource and Source Directories in Maven 2
It is not uncommon in Java projects to have contents of multiple directories to be included either in the default build or test-build. Examples include application configuration files, properties files and class files that are not part of the application (JAXB-generated classes comes to mind). Nevertheless, these files must be included as part of the build. If you run mvn test, often you're in for a rude shock - missing property files, and unresolved class dependencies errors can occur. To work around this, include these in the project's pom.xml:
1. Set build/test-build resource folders
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/resources</directory>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
</build>
2. Use the Build Helper Maven Plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/main/generated</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Sources: Maven POM reference and Chad's blog post
Busy week – crash course in Maven2 & AppFuse
Here's what I've been up to:
- Setup a development/source control/integration on the excellent Ubuntu Server Edition. Gotta hand it to these Debian distros, they're really easy to use. Ubuntu's community also makes it easy to solve problems or to get answer the many "How do I... " questions for Linux n00bs like me.
- Hook it up to DynDNS.org so that it's accessible online (the server's a VMWare virtual machine running in a desktop in my house). The Netgear wifi router has a support for DynDNS which allows it to automatically update whatever dynamic IP the server is currently using. Coupled that with port forwarding, I managed to host a cheap Tomcat server at home.
- Crash course in setting up AppFuse, and in the process learned how to use m2eclipse to quickly build Maven projects in Eclipse. This plugin makes Maven easy to use by allowing searches for Maven archtypes, dependencies and plugins. Highly recommended!
- Crash course in Spring Security (previously known as Acegi Security). I'm still cracking my head on this, but it seems too good to pass up.
- Getting an integration server running by using Hudson. Hudson has support for CVS and Maven projects; it has the ability to checkout source codes from CVS and then run Maven with the project's POM file to allow continuous build. I've yet to automate the deployment to Tomcat (using a simple bash script to copy to Tomcat's webapps dir for now) and the automated build every CVS commit, but I'm happy so far.
The busy week is far from over though. All this is a small part of a larger project work I'm working on.