<?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; Tomcat</title>
	<atom:link href="http://www.publicstaticfinal.de/tag/tomcat/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</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<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 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>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>

