<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xebia Blog &#187; configuration</title>
	<atom:link href="http://blog.xebia.com/tag/configuration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.xebia.com</link>
	<description>Software development done right!</description>
	<lastBuildDate>Wed, 01 Feb 2012 00:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to use annotations for configuration</title>
		<link>http://blog.xebia.com/2011/04/15/how-to-use-annotations-for-configuration/</link>
		<comments>http://blog.xebia.com/2011/04/15/how-to-use-annotations-for-configuration/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 22:34:38 +0000</pubDate>
		<dc:creator>Maarten Winkels</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[jackson]]></category>
		<category><![CDATA[resteasy]]></category>
		<category><![CDATA[Seam]]></category>

	<!-- AutoMeta Start -->
	<category>objectmapper</category>
	<category>annotationintrospector</category>
	<category>ejbexception</category>
	<category>jackson</category>
	<category>customobjectmapper</category>
	<category>objectmapper</category>
	<category>annotationintrospector</category>
	<category>ejbexception</category>
	<category>jackson</category>
	<category>customobjectmapper</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=6460</guid>
		<description><![CDATA[In the java world we have been using and getting used to annotations since Java 1.5. Although there were some critical voices at first, I think most of us have come around and are using annotations now quite extensively. In my experience annotations are mostly used on POJO domain classes to configure frameworks like Hibernate, [...]]]></description>
			<content:encoded><![CDATA[<p>In the java world we have been using and getting used to annotations since Java 1.5. Although there were <a href="http://blog.xebia.com/2007/01/28/a-pojo-with-annotations-is-not-plain/">some</a> <a href="http://blog.xebia.com/2007/04/03/ejb-3-annotations-to-the-max/">critical</a> <a href="http://willcode4beer.blogspot.com/2007/12/annotations-good-bad-and-ugly.html">voices</a> at first, I think most of us have come around and are using annotations now quite extensively. In my experience annotations are mostly used on POJO domain classes to configure frameworks like <a href="http://www.hibernate.org/">Hibernate</a>, <a href="http://www.springsource.org/">Spring</a> and <a href="http://www.seamframework.org/">Seam</a> and <a href="http://xstream.codehaus.org/">many</a> <a href="http://jaxb.java.net/">other</a> <a href="http://www.testng.org/">frameworks</a> to be able to handle the custom objects correctly.</p>
<p>There are as many different approaches to this as there are implementations. In this blog I try to identify a few of the better approaches and a few of the poorer ones. The blog is not so much meant as a critique on the frameworks that the examples are taken from, but more as a guide to designing your own annotations whenever you might be faced with that task.<br />
<span id="more-6460"></span></p>
<h3>Prime examples: JPA annotations</h3>
<p>The best examples of using annotations for configuration &#8211; both good and bad &#8211;  can be found in JPA Entity classes.</p>
<pre class="brush: java; title: ; notranslate">
@Entity
@Table(name=&quot;person&quot;)
public class Person {

  @Id
  @GeneratedValue(strategy=SEQUENCE)
  @Column(name = &quot;personId&quot;)
  private Long id;

  @Valid @NotEmpty
  @OneToMany(cascade = CascadeType.ALL)
  @JoinColumn(name = &quot;personId&quot;, nullable = false)
  @org.hibernate.annotations.Cascade(CascadeType.DELETE_ORPHAN)
  @org.hibernate.annotations.IndexColumn(name = &quot;position&quot;)
  private List&lt;Address&gt; addresses = new ArrayList&lt;Address&gt;();
  ...
}
</pre>
<p>What a wealth of annotations! And in such a few lines of code. Anybody that has dealt with this type of code before however, will testify that this example is not overly complex at all. You&#8217;ll find this ind of code all over.</p>
<p>To start with, let&#8217;s say that I think this type of coding has been extremely successful. So regardless whether we find the usage of annotations in this example recommendable or not, if you work with Java code, you&#8217;ll be reading and writing a lot of code like this, so understanding it is imperative. However success is just one of the indicators for quality and it is always good to think about how things can be improved.</p>
<h3>A perfect annotation</h3>
<p>Of course there is no such thing as a perfect annotation. But as a general rule of thumb a good annotation should <i>describe</i> the annotated element and be meaningful <i>outside its intended context</i>. This last requirement is a little bit vague. I hope it will become more clear once we look at some examples.</p>
<p>Annotations are very often used as a convenient means of configuration. This type of usage breaks the above rule for &#8216;perfect annotations&#8217;, but they are very convenient and very widely used. Drawbacks of this type of usage are:</p>
<ol>
<li>To change the configuration the source code needs to be recompiled.</li>
<li>The annotations (and thus their containing packages and often all of the framework code) need to be on the classpath for compilation and running.</li>
<li>Only one configuration can (usually) be specified. Most frameworks allow for a different means of configuration to circumvent this.</li>
</ol>
<p>&#8230;but these drawbacks do not mean that this type of usage has been less successful in the wild. On the contrary! There are however ways to design frameworks so that they can be configured by annotations that are not impacted by these drawbacks.</p>
<p>Let&#8217;s look at the example above in the light of these </p>
<ol>
<li>The <span style="font-family: monospace">@Entity</span> annotation specifies that instances of this class should contains data that is to be persisted. It describes how the class is intended. It also allows several frameworks to operate on it.</li>
<li>The <span style="font-family: monospace">@Table</span> annotation is pure configuration. It does not describe anything about this class and is tightly bound to its context: Databases.</li>
<li>The <span style="font-family: monospace">@Valid</span> and <span style="font-family: monospace">@NotEmpty</span> annotations describe features of <i>valid</i> instances of this class. They are however quite tightly bound to their context: data validation.</i>
</ol>
<p>For each of the annotations in the example such a analysis can be made. It is interesting to think about how <i>useful</i> the annotations are in relation how <i>perfect</i> they are: The <span style="font-family: monospace">@Entity</span> annotation, although being almost perfect is, is actually superfluous, because it will never be used without the <span style="font-family: monospace">@Table</span> annotation. The <span style="font-family: monospace">@Valid</span> and <span style="font-family: monospace">@NotEmpty</span> annotations are much more useful: They allow very powerful cross-cutting concerns to be implemented with very little code, configuration or dependency of application code on framework code, making it easy to test and reuse this code.</p>
<h3>Configuration annotation patterns in the wild</h3>
<h4> The Worst</h4>
<p>All this dribble about perfect annotations is nice and dandy, but where does it lead us? Maybe it is better to look at the other end of the spectrum, where we find the very worst of annotations:</p>
<pre class="brush: java; title: ; notranslate">
  @XmlJavaTypeAdapter(CurrencyAdapter.class)
  private BigDecimal price;
</pre>
<p>This <a href="http://download.oracle.com/javaee/5/api/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html">JAXB annotation</a>, used to configure the way a value is represented in XML, ties the implementation of a framework interface to the field on the domain class we&#8217;re trying to configure the framework for. We could as well implement the interface in the class itself!</p>
<h4> Better&#8230; Level of indirection</h4>
<p>A better pattern can be found in the seam framework for <a href="http://docs.jboss.org/seam/latest/reference/en-US/html_single/#d0e5568">configuring interceptors</a>. The following code configures an interceptor around a business method to measure the time it takes to complete.</p>
<pre class="brush: java; title: ; notranslate">
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Interceptors(SeamTimingInterceptor.class)
public @interface MeasureCalls {}
</pre>
<pre class="brush: java; title: ; notranslate">
...
	@MeasureCalls
	public void someBusinessMethod() {
		...
	}
...
</pre>
<pre class="brush: java; title: ; notranslate">
@Interceptor(around = {
	BijectionInterceptor.class,
	...
	SeamInterceptor.class,
})
public class SeamTimingInterceptor {

	@AroundInvoke
	public Object timeCall(InvocationContext invocation) throws Exception {
		long t0 = System.nanoTime();
		try {
			return invocation.proceed();
		} finally {
			long dt = System.nanoTime() - t0;
			// Log time.
		}
	}
}
</pre>
<p>The first annotation just defines a cross-cutting feature that we would like to implement in our application. We can easily use it in our application as shown by the second fragment.</p>
<p>Coming to the last code fragment, the actual implementation of the interceptor, i feel that the framework designers went a little overboard and were too annotation-happy: The interceptor could have simply implemented an interface:</p>
<pre class="brush: java; title: ; notranslate">
public interface  AroundMethodInterceptor {
	Object aroundInvoke(InvocationContext invocation);
}
</pre>
<p>This would have made the contract for an interceptor much clearer.</p>
<p>It could also help solve the other problem with this implementation: Now, the business class needs the annotation to compile, the annotation needs the interceptor and the interceptor needs the framework classes. From this perspective, the extra level of indirection has not helped a bit.</p>
<h4>Best&#8230; Classpath scanning and interfaces</h4>
<p>Another approach that is quite elegant is the JAX-RS approach to extending the framework through <a href="http://jackson.codehaus.org/javadoc/jax-rs/1.0/javax/ws/rs/ext/Provider.html">Provider</a>s and the <a href="http://www.jboss.org/resteasy">RESTEasy</a> implementation for it. The code below automatically registers an exception mapper, which integrates with the framework and is used to handle EJB exceptions coming from resource methods.</p>
<pre class="brush: java; title: ; notranslate">
@Provider
public class EJBExceptionMapper implements ExceptionMapper&lt;EJBException&gt; {

	@Context
	private Providers providers;

	@Override
	public Response toResponse(EJBException exception) {
		while (exception.getCause() != null
				&amp;&amp; exception.getCause() instanceof EJBException) {
			exception = (EJBException) exception.getCause();
		}
		Exception cause = exception.getCausedByException();
		ExceptionMapper delegate = providers.getExceptionMapper(cause.getClass());
		if (delegate != null) {
			return delegate.toResponse(cause);
		} else {
			return ExceptionUtil.serverError(cause.getMessage());
		}
	}
}
</pre>
<p>The good thing here is that the framework will scan for the annotation and then register the class according to its interface it implements.</p>
<p>Another interesting aspect is the <span style="font-family: monospace">@Context</span> annotation, that basically works as an injector point.</p>
<h4>Extensions for custom annotations</h4>
<p>This mechanism can be used to configure the RESTEasy framework to handle custom annotations for custom serialization. <a href="http://jackson.codehaus.org/">Jackson</a> has a similar mechanism like JAXB for configuring the way a field is seriaized with the <a href="http://jackson.codehaus.org/1.7.0/javadoc/org/codehaus/jackson/map/annotate/JsonSerialize.html">@JsonSerializer</a> annotation. Unfortunately this has the same drawbacks. A better approach can be implemented using the Provider mechanism on the Jackson framework itself.</p>
<pre class="brush: java; title: ; notranslate">
@Provider
public class ObjectMapperResolver implements ContextResolver&lt;ObjectMapper&gt; {

	private AnnotationIntrospector annotationIntrospector;

	public ObjectMapper getContext(Class&lt;?&gt; type) {
		return new CustomObjectMapper();
	}

	class CustomObjectMapper extends ObjectMapper {

		/**
		 * Constructor.
		 */
		public CustomObjectMapper() {
			super(null, null, null,
					new SerializationConfig(
						DEFAULT_INTROSPECTOR,
						pair(annotationIntrospector,DEFAULT_ANNOTATION_INTROSPECTOR),
						STD_VISIBILITY_CHECKER, null),
					new DeserializationConfig(DEFAULT_INTROSPECTOR,
						pair(annotationIntrospector,DEFAULT_ANNOTATION_INTROSPECTOR),
						STD_VISIBILITY_CHECKER, null)
					);
		}
	}
}
</pre>
<p>The above class &#8216;provides&#8217; the Jackson framework with a custom <span style="font-family: monospace">ObjectMapper</span>. This is done automatically, because the class is annotated with <span style="font-family: monospace">@Provider</span> and implements <span style="font-family: monospace">ContextResolver&lt;ObjectMapper></span>. Now the RESTEasy framework recognizes this as a part of the framework that will provide a <span style="font-family: monospace">ObjectMapper</span> to inject into a <span style="font-family: monospace">@Context</span> injection point. The Jackson framework uses the same injection point to find a <span style="font-family: monospace">ObjectMapper</span> to use for serialization.</p>
<p>Now how do we get it to recognize our own annotations? The answer is given by the code below, which is used in the custom <span style="font-family: monospace">ObjectMapper</span>.</p>
<pre class="brush: java; title: ; notranslate">
public class CustomAnnotationInspector extends NopAnnotationIntrospector {

	private Map&lt;Class&lt;? extends Annotation&gt;, String&gt; serializerComponents =
		new HashMap&lt;Class&lt;? extends Annotation&gt;, String&gt;();

	@Override
	public Object findSerializer(Annotated am, BeanProperty bp) {
		if (property != null) {
			for (Annotation annotation : bp.getMember().getAnnotated().getAnnotations()) {
				String name = serializerComponents.get(annotation.annotationType());
				if (name != null) {
					return Component.getInstance(name);
				}
			}
		}
		return super.findSerializer(am, bp);
	}
}
</pre>
<p>This can be used as shown below, when a serializer for the <span style="font-family: monospace">@Currency</span> is configured in the <span style="font-family: monospace">seriliazerComponents</span> map. (We use this in combination with the Seam framework for configuration).</p>
<pre class="brush: java; title: ; notranslate">
@Target({FIELD, METHOD})
@Retention(RUNTIME)
public @interface Currency {}

...
	@Currency
	BigInteger price;
...
</pre>
<h3>Conclusion</h3>
<p>In this blog I&#8217;ve shown a number of patterns for configuring frameworks using annotations. I&#8217;ve also shown some useful classes for extending the RESTEasy and Jackson  frameworks with support for custom annotations. I hope these examples will inspire you to write your own perfect and useful annotations.</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2011/04/15/how-to-use-annotations-for-configuration/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2011%2F04%2F15%2Fhow-to-use-annotations-for-configuration%2F&amp;title=How%20to%20use%20annotations%20for%20configuration" id="wpa2a_2"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2011/04/15/how-to-use-annotations-for-configuration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configuring a Seam EJB project for development with Maven and JBoss Tools</title>
		<link>http://blog.xebia.com/2009/06/06/configuring-a-seam-ejb-project-for-development-with-maven-and-jboss-tools/</link>
		<comments>http://blog.xebia.com/2009/06/06/configuring-a-seam-ejb-project-for-development-with-maven-and-jboss-tools/#comments</comments>
		<pubDate>Sat, 06 Jun 2009 16:23:19 +0000</pubDate>
		<dc:creator>Maarten Winkels</dc:creator>
		<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/blog.xebia.com/www/wp-content/plugins/autometa/autometa.php</b> on line <b>303</b><br />
		<category><![CDATA[General]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[eclipse:eclipse]]></category>
		<category><![CDATA[eclipse:m2eclipse]]></category>
		<category><![CDATA[jboss tools]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Maven archetype]]></category>
		<category><![CDATA[maven-eclipse-plugin]]></category>
		<category><![CDATA[Seam]]></category>

	<!-- AutoMeta Start -->
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://blog.xebia.com/?p=1288</guid>
		<description><![CDATA[Say you want to build a web application and you want to use Seam for integrating standard technologies like JSF and EJB. Furthermore, you want to use the power of Maven to build your project for different environments, on different systems (like you continuous build system) and use its&#8217; rich reporting features to get an [...]]]></description>
			<content:encoded><![CDATA[<p>Say you want to build a web application and you want to use Seam for integrating standard technologies like JSF and EJB. Furthermore, you want to use the power of Maven to build your project for different environments, on different systems (like you continuous build system) and use its&#8217; rich reporting features to get an overview of the code quality of your project. And of course you want to use a good IDE, like Eclipse with JBoss tools to aid you in development. How does one go about setting up all these things?<br />
<span id="more-1288"></span><br />
<b>Maven &#8211; Project structure</b><br />
<span style="float:right"><a href="http://blog.xebia.com/wp-content/uploads/2009/04/module-dependencies.png"><img src="http://blog.xebia.com/wp-content/uploads/2009/04/module-dependencies-237x300.png" alt="module-dependencies" title="module-dependencies" width="237" height="300" class="alignright size-medium wp-image-1290" /></a></span>The first thing to realize is how to setup the maven project structure for this project. To develop a Seam project that uses EJBs (and JSF), we need an ejb-archive and a web-archive. These should be combined in an ear-archive. For maven this means we need at least three projects, one for each artifact, and preferably one more to easily build the others.<br />
The picture hows how these projects are related:</p>
<ol>
<li>The BLD (build) project is the parent project of all the other projects, that in turn are modules of the BLD project. The main purpose of this project is to provide a place for common configuration and a common build for all modules.</li>
<li>The WAR project depends on the EJB project, because it will use some of the services.</li>
<li>The EAR project depends on both the WAR and the EJB project, because these should be packaged in the ear.</li>
</ol>
<p><b>Maven &#8211; Dependencies</b><br />
Maven is all about dependencies. Luckily Seam libraries are available in the repositories, both the special repositories hosted by JBoss and the central repository. And there is more: Seam provides a very useful maven project, that can be used as the parent for our own project: org.jboss.seam:root. This project contains the JBoss repositories and a dependency management section that will ensure that compatible versions of all libraries are referenced. So the first step is to make our BLD project a child of the org.jboss.seam:root project.<br />
Then we have to add the necessary dependencies for Seam.</p>
<ul>
<li>The EJB project depends on org.jboss.seam:jboss-seam:ejb and on org.hibernate:hibernate-entitymanager, since we&#8217;re gonig to use hibernate for persistence.</li>
<li>The WAR project depends on org.jboss.seam:jboss-seam-ui. Now depending on your preference of front end technology, other dependencies will need to e added, but we will come to that later.</li>
</ul>
<p>The good thing is that since we&#8217;re using the org.jboss.seam:root as parent, we don&#8217;t need to specify versions, this is handled by dependency management.<br />
The Maven structure and dependencies (and some more support files like web.xml and ejb-jar.xml) can be packaged in a Maven archetype. Attached to this blog, you can find the one we are building right now. It can also be found in <a href="http://os.xebia.com/repository/">Xebias Opensource Maven repository</a> or the <a href="http://os.xebia.com/snapshot-repo/">snapshot repository</a>.</p>
<p><b>Eclipse</b><br />
<span style="float:left; margin: 10px;"><a href="http://blog.xebia.com/wp-content/uploads/2009/04/jboss-project.png"><img src="http://blog.xebia.com/wp-content/uploads/2009/04/jboss-project-181x300.png" alt="jboss-project" title="jboss-project" width="181" height="300" class="alignleft size-medium wp-image-1309" /></a></span>Now, after handling Maven, let&#8217;s turn our attention to this Eclipse beast. We would like to have an easy path from the Maven project to the Eclipse development environment. Eventually we would like to have JBoss Tools running out-of-the-box starting from the simple Maven project. First let&#8217;s take a look at a JBoss Tools Seam project.<br />
The image on the left shows the outline of a Seam project as created by JBoss Tools. There are 4 projects: test (WAR), test-ejb, test-ear and test-test. The last contains the tests, which in a maven project will be part of the same project, so we will not discuss it further. The other three projects are WTP enabled projects. looking at the configuration files (.settings/org.eclipse.wst.common.component in each project), we find that it is using WTP version 1.5.<br />
Now we&#8217;ll try to build a similar configuration starting from the maven project.</p>
<p><b>Eclipse &#8211; WTP support</b><br />
Maven has a maven-eclipse-plugin, that has as sole purpose to transform a maven project into a working eclipse project configuration. Unfortunately, it&#8217;s WTP support is seriously broken. To configure the plugin, we use this XML snipped, taken from <a href="http://maven.apache.org/plugins/maven-eclipse-plugin/examples/multi-module-projects.html">the official documentation</a>.</p>
<pre lang="xml">
<plugins>
<plugin>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <downloadSources>true</downloadSources>
          <wtpmanifest>true</wtpmanifest>
          <wtpapplicationxml>true</wtpapplicationxml>
          <wtpversion>1.5</wtpversion>
          <manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>
        </configuration>
      </plugin>
    </plugins></pre>
<p>This snipped should be placed in the pom.xml of the BLD project, so it is applied to all projects. </p>
<p>Now, running the eclipse:eclipse maven goal on the BLD project will generate the eclipse configuration (.project, .classpath and WTP files) for all projects. The version of the JEE specifications will be inferred by the maven-eclipse-plugin by looking at the maven dependencies for the respective specifications. To make sure the plugin generates the correct WTP configuration, we need to add the javax.ejb:ejb-api:3.0 dependency to the EJB project and the javax.serlet:servlet-api:2.5 to the WAR project. With this, the configuration for these two projects is working fine. Unfortunately, the EAR project is not working and cannot be deployed. For some reason WTP does not recognize the modules for this project and when trying to deploy it, some ClassCastException is thrown. So much for maven-eclipse-plugin&#8230;</p>
<p><b>eclipse:m2eclipse</b><br />
&#8230;or not? The plugin features another goal, that could be useful here: eclipse:m2eclipse. This will generate the eclipse configuration in the same manner, but it will add the <a hre"http://m2eclipse.sonatype.org/">M2Eclipse plugin</a> to the projects. This plugin has a lot of useful features: It makes synchronizing the eclipse configuration with the maven configuration a breeze. It will, for example, add the maven dependencies to the eclipse classpath, but it will also synchronize other properties, like the java version. Furthermore adding dependencies and changing the POM in general becomes really easy and, finally, creating new Maven project or modules from within eclipse becomes really easy.<br />
This way of setting up the eclipse project is rather different from the previous one: In stead of generating all the configuration files correctly, the M2Eclipse plugin works from within eclipse to synchronize the eclipse and WTP configuration. The eclipse:m2eclipse goal does not work well with the configuration given above for the eclipse:eclipse goal, especially for EAR projects. It is better to remove all configuration from the maven-eclipse-plugin configuration and let the plugin do it&#8217;s work. This means that after generating the eclipse project files, you&#8217;ll have to open the Eclipse workspace and kick-off the synchronization process manually. More about this can be found on the <a href="http://os.xebia.com/seam-jboss-tools-archetype/">Maven site for the archetype</a>.</p>
<p><b>JBoss Tools support</b><br />
JBoss tools is a Eclipse feature, that can be enabled on a project by adding some configuration (JSF and Seam facets, the SeamBuilder and SeamNature) to the eclipse project. JBoss Tools will manage two projects: the WAR and the EJB project, but the WAR project will be the main source of configuration. By adding the necessary items to the maven-eclipse-plugin configuration for this project and also adding a special Seam configuration file to the .settings directory, JBoss tools will recognize the project correctly.<br />
For some reason, JBoss tools also stores some configuration in the workspace configuration. This can not be configured from the Maven Archetype and thus the JBoss Tools configuration is not complete. Because of this, the link between the WAR and EJB project will not be found by JBoss Tools from the EJB project. When a new Seam Artifact (Action, Entity, Form or Conversation) is added from the EJB project context meny, the configurations made in the WAR project are not picked up. When adding from the WAR project they are picked up and some sources will also be written in the EJB projects, as required.</p>
<p><b>JBoss Tools &#8211; JSF templates</b><br />
JBoss Tools will generate Java sources and JSF pages when a new component is added. The JSF pages expect certain templates to exist in the Seam project and wont work correctly if they are not found. Adding these files to the Maven Archetype makes the generated JBoss Tools project work correctly. Also the Maven projects needs additional dependencies on RichFaces and Facelets in a certain configuration (some jars should go in the WEB-INF/lib, some in the EAR/lib) to make the deployed application work correctly.<br />
The JBoss Tools project generated by the (current version of the) archetype will be exactly the same as a project created from within JBoss Tools, except for the security configuration.</p>
<p><b>Deploying on JBoss &#8211; application.xml troubles</b><br />
One last problem arises when trying to deploy the generated application on JBoss AS 4.2: It will complain about the missing META-INF/application.xml. As per latest JEE spec, the application.xml is no longer mandatory, but JBoss AS 4.2 doesn&#8217;t handle this correctly. To make it work with WTP on JBoss and also with the Maven created artifacts, we have to apply a few tricks to make it all work:</p>
<ol>
<li><i>We need to add an &#8216;empty&#8217; application.xml file in the META-INF directory in src/main/application of the EAR project.</i><br />This file is changed by the M2Eclipse plugin and used by WTP to make the deployment work on JBoss AS.</li>
<li><i>We let Maven generate an application.xml file during the build by setting the property generateApplicationXml on the ear plugin.</i><br />The file is generated in the normal bulid directory and not the same as the previous.</li>
<li><i>We exclude the first file from the maven-bulid EAR file using the property earSourceExcludes on the ear plugin (value:META-INF/application.xml).</i><br /> this way the first file is ignored and the second is used in the maven build.</li>
</ol>
<p>Et voila! At this point we have reached our goal of building a Seam project with Maven while still being able to use JBoss Tools, Eclipse and WTP for development.</p>
<p>Happy Coding!</p>
<div name="googleone_share_1" style="position:relative;z-index:5;float: right; margin-left: 10px;"><g:plusone size="small" count="1" href="http://blog.xebia.com/2009/06/06/configuring-a-seam-ejb-project-for-development-with-maven-and-jboss-tools/"></g:plusone></div><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.xebia.com%2F2009%2F06%2F06%2Fconfiguring-a-seam-ejb-project-for-development-with-maven-and-jboss-tools%2F&amp;title=Configuring%20a%20Seam%20EJB%20project%20for%20development%20with%20Maven%20and%20JBoss%20Tools" id="wpa2a_4"><img src="http://blog.xebia.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.xebia.com/2009/06/06/configuring-a-seam-ejb-project-for-development-with-maven-and-jboss-tools/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  blog.xebia.com/tag/configuration/feed/ ) in 0.52777 seconds, on Feb 9th, 2012 at 4:57 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 9th, 2012 at 5:57 pm UTC -->
