<?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>Matt's Blog &#187; java</title>
	<atom:link href="http://blog.rueedlinger.ch/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rueedlinger.ch</link>
	<description>Software Engineering and Java</description>
	<lastBuildDate>Tue, 23 Feb 2010 15:26:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>More readable and typeable&#8230;</title>
		<link>http://blog.rueedlinger.ch/2009/02/more-readable-and-typeable/</link>
		<comments>http://blog.rueedlinger.ch/2009/02/more-readable-and-typeable/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 22:27:00 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=42</guid>
		<description><![CDATA[Hamcrest allows you to write readable constraints, which for example can be used with an assert statement. Hamcrest is included since JUnit 4.4 and it is the first time that third-party classes have been included in JUnit. But when you play around with Hamcrest and the assertThat statement you don&#8217;t want go back to old [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/hamcrest/">Hamcrest</a> allows you to write readable constraints, which for example can be used with an assert statement. <a href="http://code.google.com/p/hamcrest/">Hamcrest</a> is included since <a href="http://junit.sourceforge.net/doc/ReleaseNotes4.4.html">JUnit 4.4</a> and it is the first time that third-party classes have been included in JUnit. But when you play around with Hamcrest and the <strong>assertThat</strong> statement you don&#8217;t want go back to old complex and unreadable assert statements.</p>
<h3>JUnit and assertThat</h3>
<p>With Hamcrest it&#8217;s very easy to write readable assert statements in a JUnit test case . In the following example we want to check if a person is older than 21 years.</p>
<pre class="code">import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;

...

Person person1 = new Person();
person1.setName(&quot;Bob&quot;);
person1.setAge(22);

<strong>assertThat</strong>(person1.getAge(), greaterThan(21));</pre>
<p>As you can see the assert statement is pretty straightforward. The second parameter of an assertThat statement is a Matcher which evaluates if the first parameter is greater than the integer value from the Matcher. This syntax allows you to think in terms of subject, verb, object and not in assertEquals.</p>
<p>Hamcrest uses Matcher which are responsible to evaluate a given statement. A good overview about Hamcrest is the <a href="http://code.google.com/p/hamcrest/wiki/Tutorial">official tutorial</a>.</p>
<p>JUnit currently ships with a few matchers, defined in <strong>org.hamcrest.CoreMatchers</strong> and <strong>org.junit.matchers.JUnitMatchers</strong>. To use the other matchers download the <strong>hamcrest-all.*.jar</strong> library.</p>
<h3>hamcrest-collections</h3>
<p><a href="http://code.google.com/p/hamcrest-collections/">hamcrest-collections</a> implements features such as select, reject, map, reduce and zip which can be used on collections. This is a useful library which uses Hamcrest to operate on collections.</p>
<p>The following example show how to select from a List of integers all numbers between 5 and 9.</p>
<pre class="code">import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrestcollections.Selector.*;

...

List&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;();
for (int i = 0; i &lt;= 10; i++) {
	numbers.add(i);
}

Iterable&lt;Integer&gt; items = select(numbers, allOf(greaterThan(5), lessThan(9)));

System.out.println(items);</pre>
<p>Which genearte the following output:</p>
<pre class="code">[6, 7, 8]</pre>
</pre>
<h3>Further reading...</h3>
<p>A good starting point as already mention is the <a href="http://code.google.com/p/hamcrest/">official Hamcrest Homepage</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2009/02/more-readable-and-typeable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JYaml &#8211; YAML for Java</title>
		<link>http://blog.rueedlinger.ch/2009/02/jyaml-yaml-for-java/</link>
		<comments>http://blog.rueedlinger.ch/2009/02/jyaml-yaml-for-java/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 21:45:43 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=41</guid>
		<description><![CDATA[“YAML Ain’t Markup Language” (abbreviated YAML) is a data serialization language designed to be human-friendly according to the official Yaml homepage. One implementation for the Java language is the JYaml framework.
There are a lot of other YAML frameworks for different languages. You find a list of some frameworks on the official Yaml homepage. 
Short Introduction [...]]]></description>
			<content:encoded><![CDATA[<p>“YAML Ain’t Markup Language” (abbreviated YAML) is a data serialization language designed to be human-friendly according to the official <a href="http://www.yaml.org">Yaml</a> homepage. One implementation for the Java language is the <a href="http://jyaml.sourceforge.net/">JYaml</a> framework.</p>
<p>There are a lot of other YAML frameworks for different languages. You find a list of some frameworks on the official <a href="http://www.yaml.org">Yaml</a> homepage. </p>
<h3>Short Introduction to YAML</h3>
<p>In YAML there are different kinds of nodes:</p>
<ul>
<li>Scalar is a value that can be presented as a series of zero or more Unicode characters.</li>
<li>Sequence is an ordered series of zero or more nodes.</li>
<li>Mapping is an unordered set of key: value node pairs, with the restriction that each of the keys is unique.</li>
</ul>
<p>YAML uses three dashes (“<strong>- &#8211; -</strong>”) to show that a document begins.  A comment is denoted by a <strong>#</strong>. In the following sections we now have a look at the YAML constructs sequences, mappings, tags, anchors and aliases. </p>
<p><b>Sequence</b><br />
A sequence is  a series of nodes, each denoted by a leading “<strong>-</strong>” indicator.</p>
<pre class="code">
- Memoirs Found in a Bathtub
- Snow Crash
- Ghost World
</pre>
<p><b>Mapping</b><br />
A mapping represents a key: value pair. </p>
<pre class="code">
Stanislaw Lem: Memoirs Found in a Bathtub
Neal Stephenson: Snowcrash
Daniel Clowes: Ghost World
</pre>
<p><b>Tag</b><br />
YAML represents type information of native data structures with a simple identifier, called a tag (<strong>!</strong>). The tag serves to restrict the set of possible values the content can have. In this example from JYaml the tag specifies from which type of class the node is.</p>
<pre class="code">
<strong>!</strong>my.app.yaml.model.Book
</pre>
<p><b>Anchors and Aliases</b><br />
In the representation graph, a node may appear in more than one collection. An anchor is denoted by the <strong>“&#038;</strong>” indicator and an alias node by the “<strong>*</strong>” indicator. The alias refers to the most recent preceding node  having the same anchor. </p>
<pre class="code">
- !my.app.yaml.model.Book
  authors:
    - <strong>&#038;3 </strong>!my.app.yaml.model.Author
      firstName: Gary
      lastName: Michaels
- !my.app.yaml.model.Book
  authors:
    - !my.app.yaml.model.Author
      firstName: Bob
      lastName: Jackson
    - <strong>*3</strong>
</pre>
<p>You find more detail about the YAML standard in the <a href="http://yaml.org/spec/1.2/">YAML specification</a>. </p>
<p><b>Note</b>: Some of the examples are from the homepage <a href="http://yaml.kwiki.org/?YamlInFiveMinutes">Yaml In Five Minutes</a>.</p>
<h3>JYaml</h3>
<p>When you want to serialize and deserialize Java classes with JYaml then all these classes have to obey the following Java beans naming convention.</p>
<ul>
<li>The class must have a public default constructor.</li>
<li>Set/get methods for properties</li>
</ul>
<p>JYaml currently supports the serialization and deserialization of the following types of Java objects:</p>
<ul>
<li>Primitives and respective wrapper classes</li>
<li>Collection (List and Set)</li>
<li>Maps</li>
<li>Arrays</li>
<li>BigInteger and BigDecimal</li>
<li>Date</li>
<li>Custom Java Objects by implementing ObjectsWrappers yourself</li>
</ul>
<p>JYaml is also in the maven repository. You have just to add the following lines in your <strong>pom.xml</strong> file.</p>
<pre class="code">&lt;dependency&gt;
 &lt;groupId&gt;org.jyaml&lt;/groupId&gt;
 &lt;artifactId&gt;jyaml&lt;/artifactId&gt;
 &lt;version&gt;1.3&lt;/version&gt;
&lt;/dependency&gt;</pre>
<h3>Data structure</h3>
<p>So we want to serialize and deserialize our data structure which are books and authors. The following line of codes shows you the simple data structure as Java code.</p>
<pre class="code">public class Book {

	private String isbn;
	private String title;
	private int pages;	

	private List&lt;Author&gt; authors = new ArrayList&lt;Author&gt;();

	public String getIsbn() {
		return isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getPages() {
		return pages;

	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public List&lt;Author&gt; getAuthors() {
		return authors;
	}

	public void setAuthors(List&lt;Author&gt; authors) {
		this.authors = authors;
	}
}

public class Author {

	private String firstName;
	private String lastName;

	private Date dateOfBirth;

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}
}
</pre>
<h3>Serialize</h3>
<p>The serialize step is quite simple all work is done with the static methods from the <b>org.ho.yaml.Yaml</b> class.</p>
<pre class="code">List&lt;Book&gt; books = new ArrayList&lt;Book&gt;();

Book book1 = new Book();
book1.setIsbn("123-x");
book1.setTitle("YAML in Action");
book1.setPages(330);

Author author1 = new Author();
author1.setDateOfBirth(new Date());
author1.setFirstName("Gary");
author1.setLastName("Michaels");

book1.getAuthors().add(author1);

books.add(book1);

Book book2 = new Book();
book2.setIsbn("897-x");
book2.setTitle("JYAML for dummies");
book2.setPages(230);

Author author2 = new Author();

author2.setDateOfBirth(new Date());
author2.setFirstName("Bob");
author2.setLastName("Jackson");
book2.getAuthors().add(author2);
book2.getAuthors().add(author1);

books.add(book2);

// write to file
<strong>Yaml.dump(books, new File("books.yml"));</strong>
</pre>
<p>The output after the serialization process looks as follow:</p>
<pre class="code">---
- !my.app.yaml.model.Book
  authors:
    - &amp;3 !my.app.yaml.model.Author
      dateOfBirth: !java.util.Date "1234212351636"
      firstName: Gary
      lastName: Michaels
  isbn: 123-x
  pages: 330
  title: YAML in Action
- !my.app.yaml.model.Book
  authors:
    - !my.app.yaml.model.Author
      dateOfBirth: !java.util.Date "1234212351636"
      firstName: Bob
      lastName: Jackson
    - *3
  isbn: 897-x
  pages: 230
  title: JYAML for dummies
</pre>
<h3>Deserialize</h3>
<p>To obtain the Java objects from a YAML file you have just to add the following line of code:</p>
<pre class="code">List&lt;Book&gt; out = Yaml.loadType(new File("books.yml"), ArrayList.class);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2009/02/jyaml-yaml-for-java/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I wanted to buy an apache wicket book but I got stuck on stripes</title>
		<link>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/</link>
		<comments>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 22:29:13 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=39</guid>
		<description><![CDATA[So today I wanted to buy an apache wicket book, because I try to create a simple example which shows how you could use apache activemq as embedded JMS broker in a web application with spring and hibernate to process data asynchronously.
I have already written the whole business layer (spring, hibernate and JMS) but for [...]]]></description>
			<content:encoded><![CDATA[<p>So today I wanted to buy an <a href="http://manning.com/dashorst/">apache wicket book</a>, because I try to create a simple example which shows how you could use <a href="http://activemq.apache.org/">apache activemq</a> as embedded JMS broker in a web application with spring and hibernate to process data asynchronously.</p>
<p>I have already written the whole business layer (spring, hibernate and JMS) but for a simple demonstration I need a web ui framework.</p>
<p>I didn&#8217;t want to write the ui in JSF, so I thought this is a good way to learn <a href="http://wicket.apache.org/">Apache wicket</a>. I went to my locale bookstore but they didn&#8217;t had the &#8220;<a href="http://manning.com/dashorst/">wicket in action</a>&#8221; book. </p>
<p>But an other book got my attention. <a href="http://www.pragprog.com/titles/fdstr/stripes">Stripes &#8230;and Java Web Development is fun again</a>.</p>
<p><em>Stripes is an open source web application framework based on the model-view-controller pattern. It aims to be a more lightweight framework than Struts by using Java technologies such as annotations and generics that were introduced in Java 1.5, to achieve &#8220;convention over configuration&#8221;.  [<a href="http://en.wikipedia.org/wiki/Stripes_(framework)">Wikipedia</a>]</em></p>
<p>As fare as I can tell <a href="http://www.stripesframework.org/">Stripes</a> looks quite interesting. I&#8217;m not yet finished with reading, but I must say after few chapters I already have a glue how to implement the ui layer. The book covers also a chapter how you could integrate hibernate and spring annotations.  </p>
<p>So I&#8217;m looking forward to see how stripes fits in with spring and hibernate. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/12/i-wanted-to-buy-an-apache-wicket-book-but-i-got-stuck-on-stripes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Thanks Head First Servlet and JSP</title>
		<link>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/</link>
		<comments>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 20:25:53 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=37</guid>
		<description><![CDATA[&#8230;. I am now a Sun Certified Web Component Developer (SCWCD). The Oreilly Book Head First Servlet and JSP gives you a quick overview about what you should know. One advantages of the Book is it&#8217;s very &#8220;brain friendly&#8221;. But I got some tough  questions on the exam which were not covered in the Book.
When [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;. I am now a Sun Certified Web Component Developer (SCWCD). The <a href="http://www.amazon.com/Head-First-Servlets-JSP-Brain-Friendly/dp/0596516681/">Oreilly Book Head First Servlet and JSP</a> gives you a quick overview about what you should know. One advantages of the Book is it&#8217;s very &#8220;brain friendly&#8221;. But I got some tough  questions on the exam which were not covered in the Book.</p>
<p>When you want a Book which covers almost everything and when your are interested in a Book which you can keep after the exam as reference book the I recommend you the <a href="http://www.amazon.com/Certified-Component-Developer-310-081-310-082/dp/0072258810">Book from David Bridgewater.</a></p>
<p>Also a good source to prepare yourself on a Sun certificate is the <a href="http://www.javaranch.com/">javaranch webiste</a>.</p>
<p>I also got asked why should I take the exam. One statement I mostly heard was they only test you on &#8220;old technologies&#8221; like JSP and Servlets&#8221; and why should I take the exam when JSF is not part of the exam.</p>
<p>But most of the Java web frameworks use JSP and Servlets as the fundamentals. So with the SCWCD exam you will be forced to learn the fundamentals. You get a glue how JSF could be realized. Honestly there are a lot of things you will never use but I think when you prepare yourself seriously then it gives you a great benefit.</p>
<p><cite>Steve</cite> which works in the same company as I took recently the Sun Certified Business Component Developer and he created some nice <a href="http://blog.stefanjaeger.ch/2008/11/14/sun-certified-business-component-developer/">fact sheets</a> which you can use to prepare yourself for the Sun Certified Business Component Developer exam.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/12/thanks-head-first-servlet-and-jsp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EJB 3.1 and JSF 2.0 with GlassFish V3 Prelude</title>
		<link>http://blog.rueedlinger.ch/2008/11/ejb-31-and-jsf-20-with-glassfish-v3-prelude/</link>
		<comments>http://blog.rueedlinger.ch/2008/11/ejb-31-and-jsf-20-with-glassfish-v3-prelude/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 13:13:45 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Java EE 6]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=17</guid>
		<description><![CDATA[I got finally some time to write a simple CRUD web application with EJB 3.1 (JPA) and JSF 2.0 (facelets). Keep in mind that JSF 2.0 and EJB 3.1 are still in development and that some features are not yet implemented or can change. The goal was to make a simple GlassFish V3 Prelude project [...]]]></description>
			<content:encoded><![CDATA[<p>I got finally some time to write a simple CRUD web application with EJB 3.1 (JPA) and JSF 2.0 (facelets). Keep in mind that JSF 2.0 and EJB 3.1 are still in development and that some features are not yet implemented or can change. The goal was to make a simple GlassFish V3 Prelude project setup for a CRUD web application with EJB 3.1, JSF 2.0 (facelets) and maven.</p>
<h3>First Install EJB 3.1 and JSF 2.0</h3>
<p>I used for this this example the GalssFish V3 Prelude <a href="https://glassfish.dev.java.net/downloads/v3-prelude.html">Platform-independent download file</a> with Java 1.6 on a Ubuntu 8.04 Linux.</p>
<p>Unzip the GlassFish zip file and run the <strong>updatetool</strong> to install the <strong>EJB 3.1</strong> and<strong> JSF 2.0</strong> components.</p>
<pre class="code">$ ./updatetool</pre>
<p><strong>Remark:</strong> You can also install JSF 2.0 and EJB 3.1 over the GlassFish web administration console (http://localhost:4848). Be sure to restart GlassFish after you have updated JSF 2.0 and EJB 3.1.</p>
<p>After that you can run the pkg command to list the installed components.</p>
<pre class="code">$ ./pkg list</pre>
<p>As you can see the EJB and JSF components were installed.</p>
<pre class="code">felix                                         1.2.2-0         installed  ----
glassfish-amx                                 3.0-28.3        installed  ----
glassfish-api                                 3.0-28.3        installed  ----
glassfish-common                              3.0-28.3        installed  ----
glassfish-ejb                                 3.0-28.3        installed  ----
glassfish-grizzly                             1.8.6.2-0       installed  ----
glassfish-gui                                 3.0-28.3        installed  ----
glassfish-hk2                                 3.0-28.3        installed  ----
glassfish-jca                                 3.0-28.3        installed  ----
glassfish-jdbc                                3.0-28.3        installed  ----
glassfish-jdbc-gui                            3.0-28.3        installed  ----
glassfish-jdbc-management                     3.0-28.3        installed  ----
glassfish-jpa                                 3.0-28.3        installed  ----
glassfish-jsf                                 2.0.0-5         installed  ----
glassfish-jta                                 3.0-28.3        installed  ----
glassfish-management                          3.0-28.3        installed  ----
glassfish-nucleus                             3.0-28.3        installed  ----
glassfish-registration                        3.0-28.3        installed  ----
glassfish-scripting                           3.0-28.3        installed  ----
glassfish-web                                 3.0-28.3        installed  ----
glassfish-web-gui                             3.0-28.3        installed  ----
glassfish-web-management                      3.0-28.3        installed  ----
javadb                                        10.2.2.1-0      installed  ----
pkg                                           1.0.7-15.1269   installed  ----
pkg-java                                      1.0.7-15.1269   installed  ----
python2.4-minimal                             2.4.4.0-15.1269 installed  ----
updatetool                                    2.0.0-15.1269   installed  ----
wxpython2.8-minimal                           2.8.8-15.1269   installed  ----</pre>
<h3>Create a simple maven project setup</h3>
<p>With the maven-archetype-webapp I created a simple webapp maven project.</p>
<pre class="code">mvn archetype:create
  -DgroupId=my.app.crud
  -DartifactId=CRUD-GVFv3
  -DarchetypeArtifactId=maven-archetype-webapp</pre>
<p>Now we have to customize our pom.xml file. We need some dependencies and the appropriate repositories. I used the following repositories:</p>
<pre class="code">
&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;id&gt;glassfish-repository&lt;/id&gt;
     &lt;name&gt;Java.net Repository for Glassfish&lt;/name&gt;
     &lt;url&gt;http://download.java.net/maven/glassfish&lt;/url&gt;
  &lt;/repository&gt;
&lt;/repositories&gt;
</pre>
<p>To have the Java EE 6 JAR&#8217;s like EJB 3.1, JSF 2.0, etc in the build classpath I put the following dependencies in my pom.xml file.</p>
<pre class="code">
&lt;dependency&gt;
   &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
   &lt;artifactId&gt;javax.javaee&lt;/artifactId&gt;
   &lt;version&gt;3.0-Prelude-b28b&lt;/version&gt;
   &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&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.0-b05&lt;/version&gt;
   &lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
</pre>
<p>I must say I&#8217;m not sure if these API&#8217;s are in sync with the current installed GlassFish. But an alternate way could be to use the maven <a href="http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies">system dependencies</a> and point them to the the EJB, JSF, JPA, and common annotations JAR&#8217;s of the installed GlassFish.</p>
<p>I&#8217;m sure when the Java EE 6 API gets stable we will find it in the java.net maven repository, but for now we have to be patient. :-)</p>
<p>We will deploy our application as WAR and so we need to customize our maven project a little. I added <strong> src/main/resources</strong> as web resource to the maven war plugin,  because we want to add some resources like <strong>META-INF/persistence.xml</strong> to the WAR file. The persistence.xml file is used to configure JPA and it must be placed inside of the META-INF directory of the WAR file. </p>
<p><strong>pom.xml</strong></p>
<pre class="xml" name="code">
&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;my.app.crud&lt;/groupId&gt;
  &lt;artifactId&gt;CRUD-GFv3&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;CRUD-GVFv3 Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.glassfish&lt;/groupId&gt;
      &lt;artifactId&gt;javax.javaee&lt;/artifactId&gt;
      &lt;version&gt;3.0-Prelude-b28b&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&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.0-b05&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;3.8.1&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.5&lt;/source&gt;
          &lt;target&gt;1.5&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.0&lt;/version&gt;
        &lt;configuration&gt;
          &lt;warName&gt;${pom.artifactId}&lt;/warName&gt;
          &lt;webResources&gt;
            &lt;resource&gt;
              &lt;!-- this is relative to the pom.xml directory --&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
            &lt;/resource&gt;
          &lt;/webResources&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;

    &lt;resources&gt;
      &lt;resource&gt;
        &lt;directory&gt;src/main/resources&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
      &lt;/resource&gt;
    &lt;/resources&gt;

  &lt;/build&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;id&gt;glassfish-repository&lt;/id&gt;
      &lt;name&gt;Java.net Repository for Glassfish&lt;/name&gt;
      &lt;url&gt;http://download.java.net/maven/glassfish&lt;/url&gt;
    &lt;/repository&gt;
  &lt;/repositories&gt;
&lt;/project&gt;
</pre>
<h3>Configure JPA</h3>
<p>For this example I used the default datasource <strong>jdbc/__default</strong> in GlassFish to store the JPA entities. The <strong>jdbc/__default</strong> datasource uses the apache derby database that comes preconfigured with GlassFish.</p>
<p>As you can see the persistence.xml was adapted for <strong>EclipseLink</strong>, <a href="http://blogs.sun.com/theaquarium/entry/eclipselink_in_glassfish_v3_as">which is the new JPA implementation in GlassFIsh V3</a>. </p>
<p>I used an <a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/RCP#Persistence.xml">example from the EclipseLink</a> homepage and adapted it for the GlassFish container.</p>
<p><strong>persistence.xml</strong></p>
<pre class="xml" name="code">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;&gt;
  &lt;persistence-unit name=&quot;defaultPersistenceUnit&quot;
    transaction-type=&quot;JTA&quot;&gt;
    &lt;jta-data-source&gt;jdbc/__default&lt;/jta-data-source&gt;
    &lt;properties&gt;
      &lt;property name=&quot;eclipselink.jdbc.driver&quot;
        value=&quot;org.apache.derby.jdbc.ClientDriver&quot; /&gt;

      &lt;property name=&quot;eclipselink.jdbc.url&quot;
        value=&quot;jdbc:derby://localhost:1527/CRUDGFv3;create=true&quot; /&gt;

      &lt;property name=&quot;eclipselink.jdbc.user&quot; value=&quot;app&quot; /&gt;

      &lt;property name=&quot;eclipselink.jdbc.password&quot; value=&quot;app&quot; /&gt;

      &lt;property name=&quot;eclipselink.ddl-generation&quot;
        value=&quot;drop-and-create-tables&quot; /&gt;

      &lt;property name=&quot;eclipselink.ddl-generation.output-mode&quot;
        value=&quot;database&quot; /&gt;

      &lt;!-- Logging --&gt;
      &lt;property name=&quot;eclipselink.logging.level&quot; value=&quot;FINE&quot; /&gt;
      &lt;property name=&quot;eclipselink.logging.timestamp&quot; value=&quot;false&quot; /&gt;
      &lt;property name=&quot;eclipselink.logging.session&quot; value=&quot;false&quot; /&gt;
      &lt;property name=&quot;eclipselink.logging.thread&quot; value=&quot;false&quot; /&gt;

    &lt;/properties&gt;
  &lt;/persistence-unit&gt;
&lt;/persistence&gt;
</pre>
<h3>Configure JSF</h3>
<p><strong>Hint</strong>: Be sure to use at least the 2.5 web.xml deployment descriptor. When you use a previous version of the deployment descriptor dependency injection like <strong>@EJB</strong> will not work.</p>
<p>In the web.xml we declare the mapping for the JSF servlet. </p>
<p><strong>web.xml</strong></p>
<pre class="xml" name="code">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5"&gt;

	&lt;display-name&gt;Sample CRUD EJB 3.1 / JSF 2.0 App&lt;/display-name&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</pre>
<p>The faces-config was customized for JSF 2.0 and so we can use faclets which was include in JSF 2.0. Be sure that you use a JSF 2.0 faces-config.xml file when you want to use the new JSF 2.0 features. </p>
<p>I just added some old fashion navigation rules and  to declare the managed bean we will use the new <strong>@ManagedBean</strong> annotation.</p>
<p><strong>faces-config.xml</strong></p>
<pre class="xml" name="code">&lt;?xml version="1.0"?&gt;
&lt;faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"

	version="2.0"&gt;

	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;/listBooks.xhtml&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;editBook.xhtml&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/editBook.xhtml&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;

	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;/editBook.xhtml&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;listBooks.xhtml&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/listBooks.xhtml&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;
&lt;/faces-config&gt;
</pre>
<p>JSF 2.0 has some cool new annotations to declare managed beans an their scope. The following example shows a managed bean declared with the @ManagedBean annotation. The session scope for this managed bean is specified with the @SessionScoped annotation. </p>
<pre class="code">
import javax.faces.model.ManagedBean;
import javax.faces.model.SessionScoped;

@ManagedBean(name = "BookBean")
@SessionScoped
public class BookManagedBean {
   ...
}
</pre>
<h3>Create a simple CRUD Application with EJB 3.1 and JSF 2.0</h3>
<p>I created the following Java artifacts.</p>
<ul>
<li><a href='http://blog.rueedlinger.ch/wp-content/uploads/2008/11/bookservicebeanjava.txt'>BookServiceBean.java</a> (Session Bean)</li>
<li><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/bookjava.txt">Book.java</a> (JPA Entity)</li>
<li><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/bookmanagedbeanjava.txt">BookManagedBean.java</a> (Managed Bean)</li>
</ul>
<p>And the following JSF pages.</p>
<ul>
<li><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/editbookxhtml.txt">editBook.xhtml</a></li>
<li><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/listbooksxhtml.txt">listBooks.xhtml</a></li>
</ul>
<h3>Prepare deployment</h3>
<p>So now it&#8217;s time to startup GlassFish and the include derby database</p>
<pre class="code">$ ./asadmin start-domain
$ ./asadmin start-database
</pre>
<p>We create our WAR file with the following maven command.</p>
<pre class="code">
$ mvn package
</pre>
<p>The last step is to deploy our application.</p>
<pre class="code">$ ./asadmin deploy /home/mr/project/CRUD-GFv3/target/CRUD-GFv3.war
</pre>
<p><strong>Remark:</strong> It seemed that when I deploy the WAR over the web administration console I had to restart GlassFish. After the restart the CRUD example worked correctly.</p>
<p>Finally the hard work is over&#8230;. :-) The application should now be deployed and you can try it out under the following address.<br />
<strong>http://localhost:8080/CRUD-GFv3</strong></p>
<p><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/crud-example.png"><img class="alignnone size-medium wp-image-18" title="crud-example" src="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/crud-example-300x193.png" alt="" width="300" height="193" /></a></p>
<h3>Source Code CRUD-GFv3</h3>
<p>You can download the full source code as ZIP file.</p>
<ul>
<li><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/11/crud-gfv3.zip">crud-gfv3.zip</a></li>
</ul>
<p><strong>Remark</strong> I also tested my example with Windows XP and the GlassFish V3 Prelude Platform-independent download file. So nobody can say I only preferred Linux&#8230;. :-) <strong>But bear in mind that the example could not work because of some changes in the Java EE 6 API that occurred after the writing of this post.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/11/ejb-31-and-jsf-20-with-glassfish-v3-prelude/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Is Linux the better choice for Java developers?</title>
		<link>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/</link>
		<comments>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 12:55:45 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[woolly thoughts]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=16</guid>
		<description><![CDATA[Last week I had a discussion with some colleges from work, if it would be better when we used Linux instead of Windows. I don&#8217;t want to start a flame war with my blog. I personally use Linux because when I was a student I couldn&#8217;t effort the licenses cost :-) and since then I [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I had a discussion with some colleges from work, if it would be better when we used Linux instead of Windows. I don&#8217;t want to start a flame war with my blog. I personally use Linux because when I was a student I couldn&#8217;t effort the licenses cost :-) and since then I pretty happy with my choice. But I must say that I don&#8217;t&#8217; have a problem to work with Windows, but sometimes I think it would be easier for me to work with Linux. But thats my personal opinion. I really miss a package manager (apt-get, emerge, etc.) under Windows and the shell (bash, etc).</p>
<p>I started to think about this topic when they did a update of the antivirus software last week. Suddenly the build of our Java application took longer, because the antivirus software scanned during the build all jar&#8217;s, war&#8217;s, ear&#8217;s and class files. It took about a day and the problem was fixed from the IT support! Now the problem is solved but there are still some points which could be improved, like to exclude XML files from the scan.</p>
<p>A big company mostly have a Java development crew and they have to customize the workstations for them. For example when you are lucky you have local administration rights and you can install a JDK. So would it be better to give them Linux workstations (or a MacBook Air&#8230;;-)  with a Windows Terminal Server client to access the MS applications?</p>
<p>A interesting post is from Cay Horstmann about why Java developers should switch to Linux.<br />
<a href="http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/why_java_develo.html ">http://weblogs.java.net/blog/cayhorstmann/archive/2006/06/why_java_develo.html<br />
</a><br />
And naturally a blog from Eitan Suez about Mac and Java.<br />
<a href="http://weblogs.java.net/blog/eitan/archive/2004/11/java_developmen_1.html">http://weblogs.java.net/blog/eitan/archive/2004/11/java_developmen_1.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/11/is-linux-the-better-choice-for-java-developers/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>First look at GlassFish V3 Prelude</title>
		<link>http://blog.rueedlinger.ch/2008/10/first-look-at-glassfish-v3-part-1/</link>
		<comments>http://blog.rueedlinger.ch/2008/10/first-look-at-glassfish-v3-part-1/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 20:15:12 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[GlassFish]]></category>
		<category><![CDATA[Java EE 6]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.rueedlinger.ch/?p=10</guid>
		<description><![CDATA[So finally I was able to install GlassFish V3 (glassfish-v3-prelude-b28 ) on my Ubuntu Linux. The previous version didn&#8217;t work because I was not able to run the update tool.
First download GlassFish V3 Prelude b28 and run the following commands.

$ chmod 755 glassfish-v3-prelude-b28b-unix.sh
$ ./glassfish-v3-prelude-b28b-unix.sh

Hint : When you choose a password for your GlassFish make sure [...]]]></description>
			<content:encoded><![CDATA[<p>So finally I was able to install GlassFish V3 (<a href="http://download.java.net/glassfish/v3-prelude/promoted/">glassfish-v3-prelude-b28</a> ) on my Ubuntu Linux. The previous version didn&#8217;t work because I was not able to run the update tool.</p>
<p>First download GlassFish V3 Prelude b28 and run the following commands.</p>
<pre class="code">
$ chmod 755 glassfish-v3-prelude-b28b-unix.sh
$ ./glassfish-v3-prelude-b28b-unix.sh
</pre>
<p><strong>Hint</strong> : When you choose a password for your GlassFish make sure that it has at least eight characters. The Installer does not remark that. When you choose a password which has not eight characters the GlassFish Installer is not able to create a domain.</p>
<p>With the update tool we can now enable features like EJB 3.1 and JSF 2.0.</p>
<pre class="code">
$ cd glassfish-v3-prelude-b28b/bin
$ ./updatetool
</pre>
<p>To deploy some EJB Apps we have to install the EJB container. Obviously the EJB container is just 463.4 kB.<br />
<a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/screenshot-update-tool.png"><img class="alignnone size-full wp-image-7" title="screenshot-update-tool" src="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/screenshot-update-tool.png" alt="" title="screenshot-update-tool" width="500" height="353" /> </a></p>
<p>I think we can effort some 600 kB more and the we have JSF 2.0 enabled.</p>
<p><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/screenshot-update-tool-1.png"><img class="alignnone size-full wp-image-9" title="screenshot-update-tool-1" src="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/screenshot-update-tool-1.png" alt="" title="screenshot-update-tool-1" width="500" height="353" /> </a></p>
<p>So it&#8217;s about time to start GlassFish and login for the first time.</p>
<pre class="code"">
$ ./asadmin start-domain
</pre>
<p><a href="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/login_glassfishv3.png"><img class="alignnone size-full wp-image-12" title="login_glassfishv3" src="http://blog.rueedlinger.ch/wp-content/uploads/2008/10/login_glassfishv3.png" alt="" title="login_glassfishv3" width="500" height="460" /> </a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/10/first-look-at-glassfish-v3-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Java based Mail Server DevNull SMTP</title>
		<link>http://blog.rueedlinger.ch/2008/10/java-based-mail-server-devnull-smtp/</link>
		<comments>http://blog.rueedlinger.ch/2008/10/java-based-mail-server-devnull-smtp/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 17:56:19 +0000</pubDate>
		<dc:creator>Matthias Rüedlinger</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://rueedlinger.ch/blog/?p=3</guid>
		<description><![CDATA[I found a simple Java based SMTP Server. DevNull SMTP is a dummy SMTP server that can be used for testing purposes. It helps you see all communication between a client and the server and is very useful if you are trying to find problems with your email server or a client that you wrote.
]]></description>
			<content:encoded><![CDATA[<p>I found a simple Java based SMTP Server. <a href="http://www.aboutmyip.com/AboutMyXApp/DevNullSmtp.jsp">DevNull SMTP</a> is a dummy SMTP server that can be used for testing purposes. It helps you see all communication between a client and the server and is very useful if you are trying to find problems with your email server or a client that you wrote.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rueedlinger.ch/2008/10/java-based-mail-server-devnull-smtp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
