Copying resources to JBoss with Maven

In my project, we use Maven to compile, build, package and deploy our application to JBoss 4.3. Every works fine. But each time a new developer comes along, or when we need to install a new server, we always have to remember to deploy the datasource and copy the MySQL JDBC Driver to JBoss. Nothing too complicated, but we tend to forget it. The file myproject-ds.xml defining the datasource needs to be copied to JBOSS_HOME/server/default/deploy and the mysql-connector-java-5.1.6.jar file needs to be copied to JBOSS_HOME/server/default/lib. To do that, we had an Ant script but people didn’t like the idea of using both Maven and Ant. So, why not using Maven profiles and the maven-resources-plugin to copy these two files to JBoss. The idea is to use an Init profile to initialize JBoss (by typing mvn -PInit install). This will copy the files only once to JBoss. Then, the maven-resources-plugin can be used to copy the myproject-ds.xml (which is under the src\main\resources directory) and the MySQL driver (located in the local repository). So, with a bit of Maven knowledge, a little help from my friend Arnaud and a lot of trying, here is what I came with : pom.xml </project> ... <profiles> <profile> <id>Init</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>copy-datasource</id> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${env.JBOSS_HOME}/server/default/deploy</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>myproject-ds.xml</include> </includes> </resource> </resources> </configuration> </execution> <execution> <id>copy-mysql-driver</id> <phase>install</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${env.JBOSS_HOME}/server/default/lib</outputDirectory> <resources> <resource> <directory>${settings.localRepository}/mysql/mysql-connector-java/5.1.6</directory> <includes> […]

Read More →