25 junho 2012

Maven Archetype: dynamic name for folders

Maven Archetypes are great! But some things lack documentation. If you are considering building your own archetypes, you may need this sooner or later.

I have a Maven Archetype to create modules for Apache Camel, and all of them will come up at the same ClassPath, but how to avoid conflicts when loading the Spring XML ApplicationContext? Put your XML files in different folders, or give them a different name.

I chose the first solution. If you want to give a folder a dynamic name, just call it __someProperty__ (yes, with double underscores). Think as you wanted to name the folder like ${artifactId}, but your operational system may not like this, so that's why Maven works with __artifactId__.

This is an example of my archetype.xml:


<?xml version="1.0" encoding="UTF-8"?>
<archetype>
 <id>module-archetype</id>
 <sources>
  <source>src/main/java/com/mycompany/myproject/Bootstrap.java</source>
 </sources>
 <resources>
  <resource>
    src/main/resources/META-INF/${artifactId}/applicationContext.xml
  </resource>
  <resource>
   src/main/resources/META-INF/${artifactId}/camelContext.xml
  </resource>
  <resource>
   src/main/resources/META-INF/jboss-deployment-structure.xml
  </resource>
 </resources>
</archetype>

And this is the project structure:



This is an archetype to load a Camel Context - with Spring - into JBoss 7.1.1 (as you may noticed from my previous posts) 

:-D

If you want to see more about this architecture, please let me know by +1 this post.

Nenhum comentário:

Contato

Email:bruno.borges(at)gmail.com

LinkedIn: www.linkedin.com/in/brunocborges
Twitter: www.twitter.com/brunoborges
Comprei e Não Vou
Rio de Janeiro, RJ Brasil
Oracle
São Paulo, SP Brasil