<?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>public static final &#187; JavaEE</title>
	<atom:link href="http://www.publicstaticfinal.de/category/javaee/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.publicstaticfinal.de</link>
	<description>the constant Java blog</description>
	<lastBuildDate>Fri, 25 Feb 2011 14:48:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>JavaEE 6 has been approved</title>
		<link>http://www.publicstaticfinal.de/2009/12/02/javaee-6-has-been-approved/</link>
		<comments>http://www.publicstaticfinal.de/2009/12/02/javaee-6-has-been-approved/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 08:32:54 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JavaEE 6]]></category>
		<category><![CDATA[Web Profile]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=114</guid>
		<description><![CDATA[On Monday the final votes for &#8220;JSR 316: Java Platform, Enterprise Edition 6 (Java EE 6) Specification&#8221; have been submitted and with little surprise it has been approved. JavaEE6 marks a major milestone in enterprise Java with the arrival of subspecs such as CDI, JPA2, EJB 3.1 (with EJB Lite) or Servlet 3.0. But the [...]]]></description>
				<content:encoded><![CDATA[<p>On Monday the final votes for &#8220;JSR 316: Java Platform, Enterprise Edition 6 (Java EE 6) Specification&#8221; have been submitted and with little surprise it has been approved.</p>
<p>JavaEE6 marks a major milestone in enterprise Java with the arrival of subspecs such as CDI, JPA2, EJB 3.1 (with EJB Lite) or Servlet 3.0. But the most important part for me is the new web profile which was really overdue.<span id="more-114"></span>JavaEE5 left web developers somewhere between all or nothing. POSCs (Plain Old Servlet Containers) proveded not all of the JEE stack that might be needed while full blown application servers like JBoss were too heavy (although JBoss did a&lt; good job with the different profiles).</p>
<p>Integrating different Frameworks into POSCs can be really a pain in the ass. Take JPA for example. JPA in a POSC is nothing more than a JavaSE usage of the JPA. Which means there are no manged transactions no container managed persistence contexts etc. Everything had to be custom made which is not the desired way.</p>
<p>With the new web profile you only get what you really need: Servlets, JPA2, JTA, CDI, EJB Lite which makes web development a lot easier. But not only the developer benefits but also the vendors since they don&#8217;t have to implement the full stack.</p>
<p>Hopefully vendors will jump on the JEE6 train and there will be a vibrant market of implementations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/12/02/javaee-6-has-been-approved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>It&#8217;s /WEB-INF/classes/META-INF</title>
		<link>http://www.publicstaticfinal.de/2009/11/10/its-web-infclassesmeta-inf/</link>
		<comments>http://www.publicstaticfinal.de/2009/11/10/its-web-infclassesmeta-inf/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 09:42:54 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=110</guid>
		<description><![CDATA[Note to myself (which might help others): In a web application always put the stuff (which is not packaged a single JARs)  in /WEB-INF/classes/META-INF (e.g. persistence.xml or service files) and not in /META-INF. Otherwise the various applications will not be able to locate them.]]></description>
				<content:encoded><![CDATA[<p>Note to myself (which might help others):</p>
<p>In a web application always put the stuff (which is not packaged a single JARs)  in <strong>/WEB-INF/classes/META-INF</strong> (e.g. persistence.xml or service files) and not in /META-INF. Otherwise the various applications will not be able to locate them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/11/10/its-web-infclassesmeta-inf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weld tutorial &#8211; Part 3</title>
		<link>http://www.publicstaticfinal.de/2009/11/04/weld-tutorial-part-3/</link>
		<comments>http://www.publicstaticfinal.de/2009/11/04/weld-tutorial-part-3/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 15:52:55 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JavaEE 6]]></category>
		<category><![CDATA[jsr-299]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=103</guid>
		<description><![CDATA[In part 1 and part 2 of this series of articles I talked about how to use the simple injection provided by Weld. What I&#8217;ve done so far was to inject full blown beans which get instanciated by its constructor. But there is another way: a producer-consumer-relationship. With this way of injection it is possible [...]]]></description>
				<content:encoded><![CDATA[<p>In part 1 and part 2 of this series of articles I talked about how to use the simple injection provided by Weld. What I&#8217;ve done so far was to inject full blown beans which get instanciated by its constructor. But there is another way: a producer-consumer-relationship.</p>
<p>With this way of injection it is possible to really inject everything. POJOs, DB resoures like ResultSets even primitives can be injected.<span id="more-103"></span></p>
<p>The following two code listings show how to produce and how to consume. I&#8217;m going to explain what&#8217;s really happening here afterwards:</p>
<pre class="brush: java; title: ; notranslate">
@Produces @Random int next() {
 return getRandom().nextInt(maxNumber);
}
</pre>
<pre class="brush: java; title: ; notranslate">
@Inject @Random
private int number;
</pre>
<p>Okay, as promised here are some explanations:</p>
<p>@Produces tells Weld that something that might get injected somewhere is being produced here. What is specified by the next annotation. Although @Random might look like a built-in annotation it is not. I named it Random to point out that the int is generated (pseudo) randomly. This is a socalled qualifier annotation which tells the dependency injection framework where to look for the producer.</p>
<pre class="brush: java; title: ; notranslate">
@Target( { TYPE, METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Documented
@Qualifier
public @interface Random
{
}
</pre>
<p>The only new thing is the @Qualifier annotation which is contained in the javax.inject package and defines qualifier annotations. As you can see in the samples above it is really possible to inject everything. There thousands of scenarios in which this might be useful. Just imagine a producer which generates a unique ID fo every instance.</p>
<p><strong>Event / Observer concept</strong></p>
<p>So far I just talked about the DI features of JSR-299. Althought the official name of this JRS-299 might say otherwise Weld is not limited to dependecy injection. One thing I really love is the event &#8220;bus&#8221; which basically an implementation of the observer pattern with lots of tuning and simplification.</p>
<p>The greatest simplification ist that there is no need to explicitly register an observer and the observable knows nothing about its observers. If you look a the &#8220;standard&#8221; observer pattern used in Swing you&#8217;ll find a method JButton.addActionListener(ActionListener l). It&#8217;s clear what&#8217;s happening here: an ActionListener is explicitly registered at one button. That means that the Button knows its listeners and the listener knows exactly to what component he or she is listening to.</p>
<p>The following annotation defines an observable (Standard Java: implements Observable):</p>
<pre class="brush: java; title: ; notranslate">
@Qualifier
@Target( { PARAMETER })
@Retention(RUNTIME)
public @interface Event {
 String source();
}
</pre>
<p>The next part might seem a litte strange since it implements an annotation but later it will be clear why this is done.</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;
import javax.enterprise.inject.AnnotationLiteral;
public abstract class EventImpl extends AnnotationLiteral&lt;Event&gt; implements Event
{
}
</pre>
<p>Next we declare the concrete event we&#8217;re listening to. This is just a simple POJO. IF you look at the Java API this Event is equivalent to the second argument of Observer.update(Oberservable o, Object argument). For better clarification I name it HelloWeldEvent.</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;
public class HelloWeldEvent
{
 private String source;

 public HelloWeldEvent(String source)
 {
 this.source = source;
 }

 public String getSource()
 {
 return source;
 }
}
</pre>
<p>A simple event which contains the name of its source. What&#8217;s left is the event listener itself but that&#8217;s not that many code:</p>
<pre class="brush: java; title: ; notranslate">
public void handleEvent(@Observes @Any HelloWeldEvent hwe)
{
 System.out.println(hwe.getSource());
}
</pre>
<p>@Observes is the annotations which tells Weld that this method listens to ALL (@Any) HelloWeldEvent which are raised in this application. This might be useful in some circumstances (imagine a logging facility which gets called every time a button is clicked) but on other occasions this is to bloated. Therefore I added the &#8220;method&#8221; source() to the Event annotation. With that it is possible to just listen to a special HelloWeldEvent.</p>
<pre class="brush: java; title: ; notranslate">
public void handleEvent(@Observes @Event(&quot;button1&quot;) HelloWeldEvent hwe)
{
 System.out.println(hwe.getSource());
}
</pre>
<p>This observer method just gets called when the raised event&#8217;s source is &#8220;button1&#8243;. So far so good but how do you raise an event? The famous BeanManager provides a method for doing this: public void fireEvent(Object event, Annotation&#8230; bindings).</p>
<p>The first argument is the event itself. It is of type Object since there is no special interface an event has to implement which means that every Object could be an event. The next arguments are the anootation bindings which are used to resolve the listeners. In this tutorial&#8217;s case this would be Event. And now it might be clear why we need an implementation if Event. I used @Event(&#8220;button1&#8243;) to specify on which concrete event the listener should be called. Weld needs a mechanism to read this information and to decide whether the method should be called or not.</p>
<p>Written in Java it looks like this:</p>
<pre class="brush: java; title: ; notranslate">
private void fireEvent(){
 beanManager.fireEvent(new HelloWeldEvent(&quot;Test&quot;), new EventImpl(){
 public String source()
 {
 return &quot;button1&quot;;
 }});
 }
</pre>
<p>When calling fireEvent a concrete implementation of Event is provided and Weld can use the source() method to retrieve the source. After an check whith equals to the value of @Event(&#8230;) Weld knows what methods to call. Be aware that we talk about synchronous events here. JSR-299 does not define asynchronous events.</p>
<p>This was the last part of my tutorial series. As I stated before JSR-299 is way to extensive to be completely covered by a tutorial. I just wanted to give people who are interested in working with it a litte help to get started. I hope that I achieved this goal a little bit and the ones who read the article are goind to use Weld (or other implementations) since it will boost your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/11/04/weld-tutorial-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weld tutorial &#8211; Part 2</title>
		<link>http://www.publicstaticfinal.de/2009/10/28/weld-tutorial-part-2/</link>
		<comments>http://www.publicstaticfinal.de/2009/10/28/weld-tutorial-part-2/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 18:00:57 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JavaEE 6]]></category>
		<category><![CDATA[jsr-299]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=89</guid>
		<description><![CDATA[Welcome to part 2 of my litte Weld tutorial. Before I start I have to point you to the PFD2 of Weld. Why? Well, the whole JSR-299 is very extensive. It is IMO nearly impossible to cover all parts of it in a few lines. Hence I&#8217;m not going into much details of Weld but [...]]]></description>
				<content:encoded><![CDATA[<p>Welcome to part 2 of my litte Weld tutorial. Before I start I have to point you to the PFD2 of Weld. Why? Well, the whole JSR-299 is very extensive. It is IMO nearly impossible to cover all parts of it in a few lines. Hence I&#8217;m not going into much details of Weld but just show you how to get started.</p>
<p>Having said that lets go to&#8230;<span id="more-89"></span><strong> </strong></p>
<p><strong>Obtaining the BeanManager</strong></p>
<p>In your web.xml/context.xml you declared a managed resource called BeanManager which is main interface to all Bean related stuff (adding/removing beans from a context etc.). There are two ways for obtaining the Bean Manager. The first way is to use dependey injection with the @Resource annotation:</p>
<pre class="brush: java; title: ; notranslate">
@Resource(mappedName=&quot;java:/comp/env/BeanManager&quot;)
BeanManager beanManager;
</pre>
<p>Here you let the container do all the work. Or you cann ask Weld to inject the BeanManager by using @Inject:</p>
<pre class="brush: java; title: ; notranslate">
@Inject
BeanManager beanManager;
</pre>
<p><strong>Simple Dependency Injection</strong></p>
<p>In the previous section I made a little trip to the future by using the @Inject annotation. As you might have already guessed this annotation tells Weld that the field/parameter should be injected. This is the simplest dependency injection available. You just tell Weld that you need something injected and Weld takes care of it. A good example for this would be a Cache which is typically application scoped (although every scoped bean can be injected):</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named
@ApplicationScoped
public class Cache {...}
</pre>
<p>As you learned already this managed bean can be accessed via EL using #{cache}. But most often you&#8217;re not only using the Cache in the frontend but in the business logic too. The extenden HelloWeld bean would look like this:</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named(&quot;helloWeld&quot;)
@SessionScoped
public class HelloWeld implements Serializable {
  private String message = &quot;Hello Weld&quot;;

  @Inject
  private transient Cache cache;

  public String getMessage() {
    return message;
  }
}
</pre>
<p>The injected Cache object has to be marked as transient since HelloWeld is serializable while the Cache is not. If the cache field is not marked as transient Weld will throw an Exception since it enforces serializability. This is really a good feature in Weld since it leads to consistent data.</p>
<p>Another good point is that you can use loose coupling without much effort. If the Cache class above would be &#8220;CacheImpl&#8221; and implementing a Cache interface you don&#8217;t have to change your code that much. The Cache implementation class would look like this:</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named(&quot;cache&quot;)
@ApplicationScoped
public class CacheImpl implements Cache
{

}
</pre>
<p>And the CacheImpl would be injected like this:</p>
<pre class="brush: java; title: ; notranslate">
@Inject @Named(&quot;cache&quot;)
private transient Cache cache;
</pre>
<p>What if you need mor than one Caches? I&#8217;m too lazy at the moment to think of a scenario where you might need this but of course this is possible. Although with the restriction that this cannot be achieved directly by dependency injection. If you asked yourself why I explained how to obtain the BeanManager here&#8217;s the answer: the BeanManager helps you to create new instances of an injectable resource. The following mehtod gets called with getNewCache(&#8220;cache&#8221;):</p>
<pre class="brush: java; title: ; notranslate">
private Cache getNewCache(String elName) {
  Set&lt;Bean&lt;?&gt;&gt; beans = beanManager.getBeans(elName);
  for (Bean&lt;?&gt; bean : beans) {
    Set&lt;Type&gt; beanTypes = bean.getTypes();
    for (Type type : beanTypes) {
      if (type.equals(Cache.class)) {
        Bean&lt;Cache&gt; tmp = (Bean&lt;Cache&gt;) bean;
        Cache newCache = tmp.create(beanManager.createCreationalContext(tmp));
        return newCache;
      }
    }
 }
 return null;
}
</pre>
<ul>
<li>2: In this line all beans which can be accessed by #{cache} are retrieved</li>
<li>4: all types of the bean are read</li>
<li>6: Check if the bean is of type Cache</li>
<li>7: cast to the proper type</li>
<li>8: retrieval of the proxy object by api calls</li>
</ul>
<p>I&#8217;m not going into detail of every single API call. If you&#8217;re interested in more information please refer to the Javadoc (link: http://docs.jboss.org/cdi/api/1.0-CR1/).</p>
<p>I think that&#8217;s enough for the second part of my tutorial. This part just covered injection of scoped beans. While this is a pretty powerful tool JSR-299 doesn&#8217;t limit injection to scoped beans. Generally speaking you can <span style="text-decoration: line-through;">blow</span> inject your foot away using Weld.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/10/28/weld-tutorial-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Weld Tutorial &#8211; Part 1</title>
		<link>http://www.publicstaticfinal.de/2009/10/23/weld-tutorial-part-1/</link>
		<comments>http://www.publicstaticfinal.de/2009/10/23/weld-tutorial-part-1/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 08:03:52 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JavaEE 6]]></category>
		<category><![CDATA[jsr-299]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=68</guid>
		<description><![CDATA[Following my recently published article about integrating Weld with Tomcat6 here&#8217;s Part 1 of my Weld tutorial. In this first part I want to create a really really really simple example application &#8211; the so called &#8220;Hello Weld&#8221; example. For the Non-German readers: &#8220;Hello Weld&#8221; is a litte pun. &#8220;World&#8221; is &#8220;Welt&#8221; in German which [...]]]></description>
				<content:encoded><![CDATA[<p>Following my recently published article about integrating Weld with Tomcat6 here&#8217;s Part 1 of my Weld tutorial.</p>
<p>In this first part I want to create a really really really simple example application &#8211; the so called &#8220;Hello Weld&#8221; example. For the Non-German readers: &#8220;Hello Weld&#8221; is a litte pun. &#8220;World&#8221; is &#8220;Welt&#8221; in German which is pretty close to Weld. <img src='http://www.publicstaticfinal.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Enough jokes for now, let&#8217;s go to work.<span id="more-68"></span>First we create the simplest bean known to mankind:</p>
<pre class="brush: java; title: ; notranslate">
package de.publicstaticfinal.web.jsf;
import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named(&quot;helloWeld&quot;)
@SessionScoped
public class HelloWeld implements Serializable {
private String message = &quot;Hello Weld&quot;;

 public String getMessage() {
   return message;
 }
}
</pre>
<ul>
<li>9: @Named(&#8220;helloWeld&#8221;) tells Weld that this bean is accessible under the name &#8220;helloWeld&#8221;. You don&#8217;t have to specify a value the default would be the camel-cased de-capitalized name of the Class.</li>
<li>10: @SessionScoped tells Weld that this bean resides in session scope. Be aware: When you use JSF 2.0 the are two @SessionScoped annotation. If using Wled always use the annotation in the javax.enterprise package.</li>
</ul>
<p>Now consider the following Facelets page which just outputs the &#8220;message&#8221; field from the bean referenced by the name &#8220;helloWeld&#8221;:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
 xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
 xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
 xmlns:f=&quot;http://java.sun.com/jsf/core&quot;&gt;
&lt;head&gt;
&lt;title&gt;Test&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h:outputText value=&quot;#{helloWeld.message}&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And with little surprise you get this output:</p>
<p><a href="http://www.publicstaticfinal.de/wp-content/uploads/2009/10/helloWeld01.png" rel="thumbnail"><img class="alignnone size-medium wp-image-67" title="helloWeld01" src="http://www.publicstaticfinal.de/wp-content/uploads/2009/10/helloWeld01-300x167.png" alt="helloWeld01" width="300" height="167" /></a></p>
<p>What happened? When helloWeld.jsf is requested Weld does a lookup of &#8220;#{helloWeld}&#8221; and since we declared the bean it can be found by Weld. Weld creates an instance of the bean and puts it into session scope. If you debug the application and create a breakpoint you can see that it is indeed always the same instance within a session.</p>
<p>There&#8217;s nothing that special about it since the scoped annotations are also included in JSF 2.0. Part 2 of my tutorial will show you the real fun with dependency injection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/10/23/weld-tutorial-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrating JSF 2.0 and Weld with Tomcat6</title>
		<link>http://www.publicstaticfinal.de/2009/10/22/integrating-jsf-2-0-and-weld-with-tomcat6/</link>
		<comments>http://www.publicstaticfinal.de/2009/10/22/integrating-jsf-2-0-and-weld-with-tomcat6/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 12:29:11 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[jsr-299]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.publicstaticfinal.de/?p=61</guid>
		<description><![CDATA[While Mojarra 2.0.0 is out on the street and Weld (aka Java Contexts and Dependency Injection (JSR-299)) is reaching CR1 there&#8217;s not much content on the web about it. So I tried to give a litte tutorial how they can be integrated with Tomcat6 (Glassfish v3 and JBoss provide built in support).What&#8217;s needed? Mojarra 2.0.0 [...]]]></description>
				<content:encoded><![CDATA[<p>While Mojarra 2.0.0 <a href="http://blogs.sun.com/rlubke/entry/mojarra_2_0_0_is" target="_blank">is out on the street</a> and Weld (aka Java Contexts and Dependency Injection (JSR-299)) <a href="http://in.relation.to/Bloggers/Weld100CR1Available" target="_blank">is reaching CR1</a> there&#8217;s not much content on the web about it. So I tried to give a litte tutorial how they can be integrated with Tomcat6 (Glassfish v3 and JBoss provide built in support).<span id="more-61"></span>What&#8217;s needed?</p>
<ul>
<li>Mojarra 2.0.0 (Instructions for obtaining can be found <a href="http://blogs.sun.com/rlubke/entry/mojarra_2_0_0_is" target="_blank">here</a>)</li>
<li>Weld 1.0.0CR1 Servlet Environment (&#8220;weld-servlet.jar&#8221; contained in <a href="https://sourceforge.net/projects/jboss/files/Weld/1.0.0.CR1/weld-1.0.0.CR1.zip/download" target="_blank">Weld donwload archive</a>)</li>
<li><a href="http://repository.jboss.org/maven2/sun-jaxws/jsr250-api/2.1.1/jsr250-api-2.1.1.jar" target="_blank">JSR-250 API</a></li>
<li><a href="https://maven-repository.dev.java.net/repository/jstl/jars/jstl-1.2.jar" target="_blank">jstl 1.2</a></li>
<li><a href="http://repository.jboss.com/maven2/org/glassfish/web/el-impl/2.1.2-b04/el-impl-2.1.2-b04.jar" target="_blank">el-impl 2.1.2-b04</a></li>
</ul>
<p>Thats&#8217;s not really much (just about 5 MB of JARs) but all you need to get your application running. I&#8217;m not going into detail on how to configurate JSF but just what&#8217;s additionally required for Weld.</p>
<p>First you have to &#8220;tell&#8221; Weld and Tomcat that Weld is present by including the Weld Servlet listener in your application&#8217;s web.xml:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;listener&gt;
  &lt;listener-class&gt;org.jboss.weld.environment.servlet.Listener&lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p>After that create an empty file called &#8220;beans.xml&#8221; in the WEB-INF folder. Now Weld can do its magical stuff with all incoming Servlet request. Buth there&#8217;s more. This was just the setup of the Weld Servlet environment. Next you need to tell Weld what BeanManager should be used. The BeanManager is the reference to the Injection Manager itself.</p>
<p>The first thing to add is a resource reference in web.xml:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;resource-env-ref&gt;
 &lt;description&gt;Object factory for the CDI Bean Manager&lt;/description&gt;
 &lt;resource-env-ref-name&gt;BeanManager&lt;/resource-env-ref-name&gt;
 &lt;resource-env-ref-type&gt;javax.enterprise.inject.spi.BeanManager&lt;/resource-env-ref-type&gt;
&lt;/resource-env-ref&gt;
</pre>
<p>And finally if not already present create META-INF/context.xml and put the Resource itself in it:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;Resource
 name=&quot;BeanManager&quot;
 auth=&quot;Container&quot;
 type=&quot;javax.enterprise.inject.spi.BeanManager&quot;
 factory=&quot;org.jboss.weld.resources.ManagerObjectFactory&quot;
/&gt;
</pre>
<p>That&#8217;s all. Tomcat6 is now running with JSF 2.0 and Weld 1.0.0CR1 and ready for hours of fun. As you might have already guessed this post doesn&#8217;t contain anything about how to use Weld but just how to set it up with Tomcat6. However I&#8217;m writing a short introduction for Wled which should be online within 3 or 4 days.</p>
<p><strong>UPDATE: </strong>For those using Maven here&#8217;s a simple POM containing the required repositories and dependencies:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;project
 xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
 xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
 &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
 &lt;groupId&gt;de.publicstaticfinal&lt;/groupId&gt;
 &lt;artifactId&gt;WeldJSF2&lt;/artifactId&gt;
 &lt;packaging&gt;war&lt;/packaging&gt;
 &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
 &lt;repositories&gt;
  &lt;repository&gt;
   &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
   &lt;name&gt;Java.net Repository for Maven&lt;/name&gt;
   &lt;url&gt;http://download.java.net/maven/2/&lt;/url&gt;
   &lt;layout&gt;default&lt;/layout&gt;
  &lt;/repository&gt;
  &lt;repository&gt;
  &lt;snapshots /&gt;
   &lt;id&gt;ibiblio&lt;/id&gt;
   &lt;url&gt;http://www.ibiblio.org/maven2/&lt;/url&gt;
   &lt;/repository&gt;
   &lt;repository&gt;
   &lt;id&gt;JBoss&lt;/id&gt;
   &lt;url&gt;http://repository.jboss.com/maven2&lt;/url&gt;
  &lt;/repository&gt;
 &lt;/repositories&gt;
 &lt;dependencies&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
   &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
   &lt;version&gt;2.0.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
   &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
   &lt;scope&gt;runtime&lt;/scope&gt;
   &lt;version&gt;2.0.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;javax.enterprise&lt;/groupId&gt;
   &lt;artifactId&gt;cdi-api&lt;/artifactId&gt;
   &lt;scope&gt;provided&lt;/scope&gt;
   &lt;version&gt;1.0-CR1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;javax.annotation&lt;/groupId&gt;
   &lt;artifactId&gt;jsr250-api&lt;/artifactId&gt;
   &lt;version&gt;1.0&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
   &lt;artifactId&gt;jstl&lt;/artifactId&gt;
   &lt;version&gt;1.2&lt;/version&gt;
   &lt;scope&gt;runtime&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;org.jboss.weld.servlet&lt;/groupId&gt;
   &lt;artifactId&gt;weld-servlet&lt;/artifactId&gt;
   &lt;version&gt;1.0.0-CR1&lt;/version&gt;
   &lt;scope&gt;runtime&lt;/scope&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;org.glassfish.web&lt;/groupId&gt;
   &lt;artifactId&gt;el-impl&lt;/artifactId&gt;
   &lt;version&gt;2.1.2-b04&lt;/version&gt;
   &lt;scope&gt;runtime&lt;/scope&gt;
   &lt;exclusions&gt;
    &lt;exclusion&gt;
     &lt;groupId&gt;javax.el&lt;/groupId&gt;
     &lt;artifactId&gt;el-api&lt;/artifactId&gt;
    &lt;/exclusion&gt;
   &lt;/exclusions&gt;
  &lt;/dependency&gt;
 &lt;/dependencies&gt;
&lt;/project&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.publicstaticfinal.de/2009/10/22/integrating-jsf-2-0-and-weld-with-tomcat6/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
