<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-160318223199333541</id><updated>2012-02-16T15:48:12.447+01:00</updated><category term='Tools'/><category term='Tomcat'/><category term='JSF'/><category term='Database'/><title type='text'>Technology For Human</title><subtitle type='html'>Computers, Java programming - for an ordinary human being, simple as possible.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://technology-for-human.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2581670077965516141</id><published>2011-12-08T17:53:00.001+01:00</published><updated>2011-12-08T20:32:38.036+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 1.2 (myFaces) + RichFaces 3.3.x + IE 9 = troubles</title><content type='html'>&lt;div style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: inherit;"&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;working JSF 1.2 sample application from &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;here&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;latest myFaces for JSF 1.2 - version 1.2.11, latest RichFaces for JSF 1.2 - version 3.3.3 final&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;ul style="font-family: inherit;"&gt;&lt;li&gt;&lt;span style="font-size: small;"&gt;how to fix problems with RichFaces 3.3.x &lt;/span&gt;&lt;span style="font-size: small;"&gt;for IE 9 &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: inherit;"&gt;&lt;span style="font-size: small;"&gt;Let's assume that You develop JSF 1.2 web application. It does not matter if Your application uses .jsp pages or Facelets with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.xhtml&lt;/span&gt; pages. I assume that &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.jsp&lt;/span&gt; pages are in use. Then You decided to add some Ajax capabilities, new components and so on. So You simply take RichFaces and add them to the project. This is simple thing:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;a)&lt;/b&gt; download latest RichFaces 3.3.3 (final), take those jars:&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; richfaces-api-3.3.3.Final.jar, richfaces-impl-3.3.3.Final.jar, richfaces-ui-3.3.3.Final.jar&lt;/span&gt; and place them in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WEB-INF\lib&lt;/span&gt; folder of Your web application.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;&lt;b&gt;b)&lt;/b&gt; modify your faces-config.xml file by adding there:&lt;/span&gt;&lt;/div&gt;&lt;pre class="brush: xml"&gt; &amp;lt;filter&amp;gt;&lt;br /&gt;  &amp;lt;display-name&amp;gt;RichFaces Filter&amp;lt;/display-name&amp;gt;&lt;br /&gt;  &amp;lt;filter-name&amp;gt;richfaces&amp;lt;/filter-name&amp;gt;&lt;br /&gt;  &amp;lt;filter-class&amp;gt;org.ajax4jsf.Filter&amp;lt;/filter-class&amp;gt;&lt;br /&gt; &amp;lt;/filter&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;  &amp;lt;filter-name&amp;gt;richfaces&amp;lt;/filter-name&amp;gt;&lt;br /&gt;  &amp;lt;servlet-name&amp;gt;Faces Servlet&amp;lt;/servlet-name&amp;gt;&lt;br /&gt;  &amp;lt;dispatcher&amp;gt;REQUEST&amp;lt;/dispatcher&amp;gt;&lt;br /&gt;  &amp;lt;dispatcher&amp;gt;FORWARD&amp;lt;/dispatcher&amp;gt;&lt;br /&gt;  &amp;lt;dispatcher&amp;gt;INCLUDE&amp;lt;/dispatcher&amp;gt;&lt;br /&gt; &amp;lt;/filter-mapping&amp;gt;&lt;/pre&gt;c) add proper taglib directives to each Your jsp page (note that for .xhtml pages syntax is different):&lt;br /&gt;&lt;pre class="brush: html"&gt;&amp;lt;%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%&amp;gt;&lt;br /&gt;&amp;lt;%@ taglib uri="http://richfaces.org/rich" prefix="rich"%&amp;gt;&lt;/pre&gt;Now You can use RichFaces components. Let's try to modify &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;our sample JSF 1.2 application&lt;/a&gt; by creating new web project named "JSFRichFaces". Then let's add ajax button (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;a4j:commanButton&amp;gt;&lt;/span&gt;) and expandable toggle panel (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;rich:simpleTogglePanel&amp;gt;&lt;/span&gt;). All modifications are shown below:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-6MLfAeQr4zQ/TuD0U_mE7ZI/AAAAAAAAGcI/h3PSu6iIPFs/s1600/JSF_RichFaces_IE9_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="217" src="http://3.bp.blogspot.com/-6MLfAeQr4zQ/TuD0U_mE7ZI/AAAAAAAAGcI/h3PSu6iIPFs/s400/JSF_RichFaces_IE9_1.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Everything works OK under Firefox, Chrome, IE 7, IE 8 - unless You use &lt;b&gt;Internet Explorer 9&lt;/b&gt;. You can observe&lt;b&gt; two problems&lt;/b&gt;: with RichFaces ajax components and RichFaces components layout.&lt;br /&gt;RichFaces 3.3.x does not fully support IE 9. RichFaces developers encourage everyone to migrate into RichFaces 4.x which are IE 9 compatible. The main problem is that &lt;b&gt;RichFaces 4.x works only with JSF 2.x application&lt;/b&gt;, and this is not so easy to migrate If You have many clients where You already delivered Your application...&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Problem 1:&lt;/b&gt; ajax components do not work (some JavaScript errors).&lt;br /&gt;&lt;br /&gt;When You try to press ajax button named "Go (RichFaces) " &lt;b&gt;under IE 9&lt;/b&gt;, You can observe following error (open IE Developer's Toolbar Java Script console before):&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ONDt4tFsu9Q/TuD4UBE62CI/AAAAAAAAGcQ/wR5rSrqq52s/s1600/JSF_RichFaces_IE9_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="242" src="http://4.bp.blogspot.com/-ONDt4tFsu9Q/TuD4UBE62CI/AAAAAAAAGcQ/wR5rSrqq52s/s400/JSF_RichFaces_IE9_2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Solution:&lt;/span&gt; &lt;/b&gt;You have to force IE 9 to act as IE 8, where RichFaces 3.3.x works OK. In order to do it You have to define X-UA-Compatible header for each page. You can do it in two ways:&lt;br /&gt;&lt;b&gt;a)&lt;/b&gt; add a special &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;meta&amp;gt;&lt;/span&gt; element for each page or&lt;br /&gt;&lt;b&gt;b)&lt;/b&gt; write a special filter which adds this header to the HTTP response&lt;br /&gt;&lt;br /&gt;In our simple case it is sufficient to add a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;meta&amp;gt;&lt;/span&gt; into the page &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;head&amp;gt;&lt;/span&gt; section:&lt;br /&gt;&lt;pre class="brush: java"&gt;&amp;lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /&amp;gt;&lt;/pre&gt;Remember that this &amp;lt;meta&amp;gt; &lt;b&gt;must be placed as first element&lt;/b&gt; in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;head&amp;gt;&lt;/span&gt; section!&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Problem 2: &lt;/b&gt;RichFaces components have broken layout (problems with CSS).&lt;br /&gt;&lt;br /&gt;When You open our sample application &lt;b&gt;under IE 9&lt;/b&gt;, toggle panel has no CSS styles set at all. Under Chrome or Firefox everything looks OK. Checking HTTP request/response headers shows that for IE 9 proper CSS for RichFaces component (CSS located in the .jar file) is not loaded and server returns error:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ftPll6eDCKY/TuEEH30paaI/AAAAAAAAGcY/7F54UyDIz1U/s1600/JSF_RichFaces_IE9_3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="251" src="http://3.bp.blogspot.com/-ftPll6eDCKY/TuEEH30paaI/AAAAAAAAGcY/7F54UyDIz1U/s400/JSF_RichFaces_IE9_3.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Console under Eclipse shows that exception is thrown:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ziceypvcLHY/TuEFpfDIT0I/AAAAAAAAGco/vgNvANPOwRw/s1600/JSF_RichFaces_IE9_5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="242" src="http://3.bp.blogspot.com/-ziceypvcLHY/TuEFpfDIT0I/AAAAAAAAGco/vgNvANPOwRw/s400/JSF_RichFaces_IE9_5.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Under Firefox everything looks OK:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-D2rIw0Tg7D8/TuEFBIuzThI/AAAAAAAAGcg/siPvD-XqMOc/s1600/JSF_RichFaces_IE9_4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="237" src="http://1.bp.blogspot.com/-D2rIw0Tg7D8/TuEFBIuzThI/AAAAAAAAGcg/siPvD-XqMOc/s400/JSF_RichFaces_IE9_4.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Why it happens?&lt;/b&gt; Accroding to that &lt;a href="http://blogs.msdn.com/b/ie/archive/2010/10/26/mime-handling-changes-in-internet-explorer.aspx"&gt;article&lt;/a&gt;, there was a &lt;b&gt;change in IE 9 for MIME type handling&lt;/b&gt;. IE 9 ignores CSS styles if they are not delivered with a &lt;b&gt;text/css&lt;/b&gt; MIME type.&lt;br /&gt;Why it works for previous IE 7 and IE 8? Because also HTTP Request Accept header sent by IE 9 is different than sent from IE 7 or 8. IE 7/8 sent &lt;b style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;text/css, */*&lt;/b&gt; as Accept, where IE 9 sends &lt;b&gt;only &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;text/css&lt;/span&gt;&lt;/b&gt; as Accept.&lt;br /&gt;Knowing that it is time to look inside myFaces source, to find the code which produces mentioned exception. Everything is located in HtmlRendererUtils.java (located in myfaces-impl-1.2.11.jar) in the selectContentType() method. It works for IE 7/8 because */* sent in Accept by IE 7/8 is on supported content type list, where text/css is not recognized at all.&lt;br /&gt;&lt;br /&gt;&lt;b style="color: red;"&gt;Solution:&lt;/b&gt; add &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;text/css&lt;/span&gt; support, then recompile  &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;HtmlRendererUtils.java&lt;/span&gt; and replace it in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myfaces-impl-1.2.11.jar&lt;/span&gt; (or build complete myfaces-impl-1.2.11.jar). In order to avoid this mumbo-jumbo with Maven to build whole &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.jar&lt;/span&gt;, just create simple Java Project, create a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;HtmlRendererUtils.java&lt;/span&gt; in certain package, change it and compile, then replace compiled class in  &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myfaces-impl-1.2.11.jar&lt;/span&gt; ;-)&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-xMTizFNLmmU/TuEMmhq9KqI/AAAAAAAAGcw/A0WfKgoMe90/s1600/JSF_RichFaces_IE9_6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="242" src="http://3.bp.blogspot.com/-xMTizFNLmmU/TuEMmhq9KqI/AAAAAAAAGcw/A0WfKgoMe90/s400/JSF_RichFaces_IE9_6.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Or download recompiled &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myfaces-impl-1.2.11.jar&lt;/span&gt; from &lt;a href="https://sites.google.com/site/technologyforhuman/myfaces-impl-1.2.11.jar"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;That's all. IE 9 works again without need to add Your web page to its compatibility view list or something. And You have time to migrate to JSF 2.x and RichFaces 4.x before IE 10 comes to market...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2581670077965516141?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2581670077965516141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2581670077965516141'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/12/jsf-12-myfaces-richfaces-33x-ie-9.html' title='JSF 1.2 (myFaces) + RichFaces 3.3.x + IE 9 = troubles'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-6MLfAeQr4zQ/TuD0U_mE7ZI/AAAAAAAAGcI/h3PSu6iIPFs/s72-c/JSF_RichFaces_IE9_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-5048024130471335254</id><published>2011-09-21T21:47:00.001+02:00</published><updated>2011-09-21T21:48:15.012+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Tomcat - using Realm to protect access to JSF application (part 2 of 2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;understanding basics of Tomcat's Realm&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to define users and roles in own web applications (JSF 2.0 as example)&lt;/li&gt;&lt;li&gt;how to use encrypted passwords for realm users instead od plain text&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In the &lt;a href="http://technology-for-human.blogspot.com/2011/09/tomcat-change-default-application.html"&gt;previous post&lt;/a&gt; I described how to configure access to Tomcat's server administration application using Tomcat's Realm elements. The whole thing boiled down to write a few lines of text in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; file. But how does it look like when we have to do it from scratch in our application?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1.&lt;/b&gt; Let's create very simple JSF application which has only 3 pages:&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/index.html&lt;/span&gt; - main page with two buttons navigating into two pages:&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/unrestrictedPage.xhtml&lt;/span&gt; - page always accessible and visible to anyone&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/restricted/restrictedPage.xhtml&lt;/span&gt; - page and directory available only for valid users&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The complete application structure will look like:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-rm_MCEUaj2s/TnobrqKknaI/AAAAAAAAGQg/_pnMQGVjwa0/s1600/Tomcat_Realm_7.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://2.bp.blogspot.com/-rm_MCEUaj2s/TnobrqKknaI/AAAAAAAAGQg/_pnMQGVjwa0/s400/Tomcat_Realm_7.PNG" width="303" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&amp;nbsp;Step 2:&lt;/b&gt; we have to add a privilleged user named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;admin&lt;/span&gt; with password &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;adminpass&lt;/span&gt; who belongs to role &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;privillegedUsers&lt;/span&gt; (You can choose any user login, password and role name). Just simply add this line:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;user username="admin" password="adminpass" roles="privillegedUsers" /&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;into &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[tomcat directory]\conf\tomcat-users.xml&lt;/span&gt; file.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; configuring application. We have to modify &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; of our sample application by adding following text:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;web-app&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;security-role&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;description&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; All persons belong to that role have access to restricted application area.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/description&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;role-name&amp;gt;privillegedUsers&amp;lt;/role-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/security-role&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;security-constraint&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;web-resource-collection&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;web-resource-name&amp;gt;Restricted&amp;lt;/web-resource-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url-pattern&amp;gt;/faces/restricted/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url-pattern&amp;gt;/restricted/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/web-resource-collection&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;auth-constraint&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;role-name&amp;gt;privillegedUsers&amp;lt;/role-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/auth-constraint&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/security-constraint&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;login-config&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;auth-method&amp;gt;BASIC&amp;lt;/auth-method&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;realm-name&amp;gt;Restricted access&amp;lt;/realm-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/login-config&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;/web-app&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;First we defined a role named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;privillegedUsers&lt;/span&gt; - the same we put in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;tomcat-users.xml&lt;/span&gt; file above. Second we have to defined prottected parts of our application, by providing proper URL pattern. Please note that we have two entries here: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/restricted/*&lt;/span&gt; - everything in this directory is protected in case someone typed this part manually in browser's address bar,&amp;nbsp; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/faces/restricted/*&lt;/span&gt; - JSF adds "faces" prefix when navigating between pages, so the URL is a little bit different and we have to watch for this also. After that we have to define a role which is allowed to access to the protected parts. This is &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;privillegedUsers&lt;/span&gt; role defined earlier. At the end we have to define the way how the authentication is done - the simplest way is BASIC, which displays predefined form with credentials.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we are ready to deploy our application on Tomcat and run it. It should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ZjbEBmTCU8I/TnorImOHgTI/AAAAAAAAGQk/Ekf9HCghnSc/s1600/Tomcat_Realm_8.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://4.bp.blogspot.com/-ZjbEBmTCU8I/TnorImOHgTI/AAAAAAAAGQk/Ekf9HCghnSc/s400/Tomcat_Realm_8.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;when we try to access to restricted area. In order to do this we have to put credentials for user defined in step 2 (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;admin&lt;/span&gt;, &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;adminpass&lt;/span&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b style="color: red;"&gt;Note:&lt;/b&gt; there is a little trick here, for the button "Restricted area" - see &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;index.xhtml&lt;/span&gt; page source code:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;h:commandButton value="Resricted area" action="/restricted/restrictedPage.xhtml?faces-redirect=true" /&amp;gt;&lt;br /&gt;&amp;lt;h:commandButton value="Unrestricted area" action="/unrestrictedPage.xhtml" /&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Because JSF internally by default makes forward to other page, browser is unaware what has happened and display URL from one step back. In such case our URL security patterns will not match anything, and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;restrictedPage.xhtml&lt;/span&gt; will be displayed without asking for login and password! In order to make protection work we have to perform full redirection for that action in order to force browser to fetch target URL and display it. For JSF applications it is better to use filters or Spring Security in order to avoid such dirty tricks.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Encrypted passwords.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As You probably have seen, passwords vor valid users are stored inside tomcat-users.xml file as a plain text. There is a possibility to store them in encrypted form, using MD5. Here is what needs to be done:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; using Eclipse modify Tomcat &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; and its &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;Realm&amp;gt;&lt;/span&gt; atrribute into:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" digest="MD5"/&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; change &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;auth-method&amp;gt;&lt;/span&gt; from BASIC to DIGEST&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; for user &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;admin&lt;/span&gt; and his previous password &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;adminpass&lt;/span&gt; we have to generate its md5 equivalent using Tomcat's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;digest.bat&lt;/span&gt; file (located in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[tomcat directory]\bin&lt;/span&gt; folder) :&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;digest.bat -a md5 admin:"Restricted access":adminpass&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;"Restricted access" is a realm name taken from &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;auth-method&amp;gt;&lt;/span&gt; tag from &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt;. Those names &lt;b&gt;must match&lt;/b&gt;, if name contains spaces, it must be surrounded with "".&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Step 4:&lt;/b&gt; using Eclipse modify Tomcat's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;tomcat-users.xml&lt;/span&gt; file:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;user username="admin" password="db7bc05adcf611fc779f32a4e680cc01" roles="privillegedUsers" /&amp;gt; &lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;where password was taken as a result of executing command from step 3.&lt;br /&gt;&lt;br /&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;b style="color: black;"&gt;Note:&lt;/b&gt;&lt;span style="color: black;"&gt; make sure that &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html" style="color: black;"&gt;Java&lt;/a&gt;&lt;span style="color: black;"&gt;, &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html" style="color: black;"&gt;Eclipse&lt;/a&gt;&lt;span style="color: black;"&gt; and &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html" style="color: black;"&gt;Tomcat&lt;/a&gt;&lt;span style="color: black;"&gt;      are properly installed and configured for running the project      (additional configuration may be required if different directories are      used).&lt;/span&gt; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/sithttps://sites.google.com/site/technologyforhuman/JSF2TomcatBasicSecurity.zip"&gt;here&lt;/a&gt;   (with all required libraries).&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-5048024130471335254?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5048024130471335254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5048024130471335254'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/09/tomcat-using-realm-to-protect-access-to.html' title='Tomcat - using Realm to protect access to JSF application (part 2 of 2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-rm_MCEUaj2s/TnobrqKknaI/AAAAAAAAGQg/_pnMQGVjwa0/s72-c/Tomcat_Realm_7.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-4383816518302579020</id><published>2011-09-13T22:01:00.000+02:00</published><updated>2011-09-13T22:01:51.036+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Tomcat - change default application, protecting access to web applications using Realm (part 1 of 2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and confiured Tomcat for the Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to change default Tomcat application&lt;/li&gt;&lt;li&gt;how to allow users access to Tomcat's server administration application using Tomcat's Realm&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's assume that You have Tomcat which is configured to work in Eclipse. When You start Tomcat (using Eclipse or standard scripts from Tomcat's distribution) and type in the browser URL &lt;b&gt;http://localhost:8080&lt;/b&gt;, You will see Tomcat's default application:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-n7_CMQlU9ZY/Tm-fjI-FywI/AAAAAAAAGQI/ZPFvKQxTO2o/s1600/Tomcat_Realm_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="291" src="http://1.bp.blogspot.com/-n7_CMQlU9ZY/Tm-fjI-FywI/AAAAAAAAGQI/ZPFvKQxTO2o/s400/Tomcat_Realm_1.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This application is located in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[tomcat directory]\webapps\ROOT&lt;/span&gt; folder. If You want to &lt;b&gt;change this page&lt;/b&gt;, just edit content of file &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;index.jsp&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;index.html&lt;/span&gt;. If You want to &lt;b&gt;completely remove this application&lt;/b&gt;, just remove complete ROOT folder.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Removing is not the best choice, because Tomcat is shipped with a special application for server administration. You can access this application using links (in red square) from left menu of a default page: Status and Tomcat Manager. Try to click on that links - You should see screen with login and password prompt:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-r4z2MHbJSNk/Tm-it9iithI/AAAAAAAAGQM/iaoWpT7P0EY/s1600/Tomcat_Realm_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="293" src="http://4.bp.blogspot.com/-r4z2MHbJSNk/Tm-it9iithI/AAAAAAAAGQM/iaoWpT7P0EY/s400/Tomcat_Realm_2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Those parts are protected using &lt;b&gt;Tomcat Realm&lt;/b&gt;. What is Realm? Realm is a set of valid users (defined by user name and password) and roles where those users belong. The idea is to configure access to web application only for valid users from certain roles. But where are those users and roles stored? It depends on a implementation of a realm - they can be stored in database, in LDAP, or in xml file. Tomcat's server administration application uses xml file to define users' access. Let's try to set up some users able to start that application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; using Eclipse open &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; from the Servers, and make sure that entry &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;Realm classname="org.apache.catalina.realm.UserDatabaseRealm" resourcename="UserDatabase"&amp;gt;&amp;lt;/Realm&amp;gt;&lt;/span&gt; exsits between &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;Engine&amp;gt;&lt;/span&gt; tags, outside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;Host&amp;amp;gt&lt;/span&gt; tags - it means that this realm will be used for all hosts and all applications on that&amp;nbsp; hosts:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Qch4CxnmRiI/Tm-o_duDClI/AAAAAAAAGQQ/LqEgrZRyZ1g/s1600/Tomcat_Realm_3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="155" src="http://2.bp.blogspot.com/-Qch4CxnmRiI/Tm-o_duDClI/AAAAAAAAGQQ/LqEgrZRyZ1g/s400/Tomcat_Realm_3.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; using Eclipse open &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;tomcat-users.xml&lt;/span&gt; from the Servers and add an entry for the user who will be able to access Tomcat's server administration application:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-zlYKoWA9Dd0/Tm-qQIQCaNI/AAAAAAAAGQU/hBERzhbVvVQ/s1600/Tomcat_Realm_4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="192" src="http://3.bp.blogspot.com/-zlYKoWA9Dd0/Tm-qQIQCaNI/AAAAAAAAGQU/hBERzhbVvVQ/s400/Tomcat_Realm_4.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;By default UserDatabaseRealm uses &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[tomcat directory]\conf\tomcat-users.xml &lt;/span&gt;file to load users and their roles into memory on server startup. In order to allow defined users to access administration application, they need to belong to roles named &lt;b&gt;manager-status&lt;/b&gt; and &lt;b&gt;manager-gui&lt;/b&gt;. After changes made, restart Tomcat server and try to access Tomcat's administration application giving username and password from tomcat-users.xml file. If everything was set up OK, You should see manager application:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8gvaHclCxnI/Tm-0uLvuG1I/AAAAAAAAGQY/VU7emVC1YqQ/s1600/Tomcat_Realm_5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="343" src="http://4.bp.blogspot.com/-8gvaHclCxnI/Tm-0uLvuG1I/AAAAAAAAGQY/VU7emVC1YqQ/s400/Tomcat_Realm_5.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-qQfOC-7Mr3Y/Tm-0znSM3ZI/AAAAAAAAGQc/Qa-wYfcD8jI/s1600/Tomcat_Realm_6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="323" src="http://2.bp.blogspot.com/-qQfOC-7Mr3Y/Tm-0znSM3ZI/AAAAAAAAGQc/Qa-wYfcD8jI/s400/Tomcat_Realm_6.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;You may wonder why we used here roles named &lt;b&gt;manager-status&lt;/b&gt; and &lt;b&gt;manager-gui&lt;/b&gt;. Those role names come from Tomcat's server administration application specific settings, stored in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; file. In the next post I will show how to protect own application (JSF2 application will be used as an example) and how to define own roles.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-4383816518302579020?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4383816518302579020'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4383816518302579020'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/09/tomcat-change-default-application.html' title='Tomcat - change default application, protecting access to web applications using Realm (part 1 of 2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-n7_CMQlU9ZY/Tm-fjI-FywI/AAAAAAAAGQI/ZPFvKQxTO2o/s72-c/Tomcat_Realm_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-8751535572150797799</id><published>2011-08-04T22:15:00.001+02:00</published><updated>2011-08-04T22:19:44.270+02:00</updated><title type='text'>Sending emails using Java Mail and Google Mail account</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description here)&lt;/li&gt;&lt;li&gt;installed and configured Eclipse (description here)&lt;/li&gt;&lt;li&gt;valid Google Mail account &lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to send e-mails from Java application using Java Mail and Google Mail account.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Sometimes You need to send an email from Your Java application. In order to do this You have to use valid e-mail account, and You have to know the address of SMTP server for this account. And of course You have to write some code which will connect to the SMTP server (using Your account credentials) and then create and send email. A Google Mail account will be used as an example.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; create clean Java Eclipse Project&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; download&amp;nbsp; JavaMail API 1.4.4 (javamail_1_4_4.zip) from &lt;a href="http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-eeplat-419426.html#javamail-1.4.4-oth-JPR"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After downloading JavaMail, extract it and go into its /lib folder. Copy all .jar files from that directory into Your project and add them to the build path.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; write a simple code for sending email using Google Mail. You can use TLS or SSL connection to Google SMTP server.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;a) &lt;/b&gt;using TLS connection to SMTP server:&lt;/div&gt;&lt;pre class="brush: java" style="font-family: Verdana,sans-serif;"&gt;// ...&lt;br /&gt;import java.util.Properties;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;// ...&lt;br /&gt;Properties propsTLS = new Properties();&lt;br /&gt;propsTLS.put("mail.transport.protocol", "smtp");&lt;br /&gt;propsTLS.put("mail.smtp.host", "smtp.gmail.com");&lt;br /&gt;propsTLS.put("mail.smtp.auth", "true");&lt;br /&gt;propsTLS.put("mail.smtp.starttls.enable", "true"); // GMail requires STARTTLS&lt;br /&gt;&lt;br /&gt;Session sessionTLS = Session.getInstance(propsTLS);&lt;br /&gt;sessionTLS.setDebug(true);&lt;br /&gt;&lt;br /&gt;Message messageTLS = new MimeMessage(sessionTLS);&lt;br /&gt;messageTLS.setFrom(new InternetAddress("random_sender_4568744122@gmail.com", "John Smith"));&lt;br /&gt;messageTLS.setRecipients(Message.RecipientType.TO, InternetAddress.parse("random_recipient_4568744122@gmail.com")); // real recipient&lt;br /&gt;messageTLS.setSubject("Test mail using TLS");&lt;br /&gt;messageTLS.setText("This is test email sent to Your account using TLS.");&lt;br /&gt;&lt;br /&gt;Transport transportTLS = sessionTLS.getTransport();&lt;br /&gt;transportTLS.connect("smtp.gmail.com", 587, "random_sender_4568744122@gmail.com", "sender_account_pass"); // account used&lt;br /&gt;transportTLS.sendMessage(messageTLS, messageTLS.getAllRecipients());&lt;br /&gt;transportTLS.close();&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;b)&lt;/b&gt; using SSL connection to SMTP server:&lt;/div&gt;&lt;pre class="brush: java" style="font-family: Verdana,sans-serif;"&gt;// ...&lt;br /&gt;import java.util.Properties;&lt;br /&gt;import javax.mail.Message;&lt;br /&gt;import javax.mail.Session;&lt;br /&gt;import javax.mail.Transport;&lt;br /&gt;import javax.mail.internet.InternetAddress;&lt;br /&gt;import javax.mail.internet.MimeMessage;&lt;br /&gt;// ...&lt;br /&gt;Properties propsSSL = new Properties();&lt;br /&gt;propsSSL.put("mail.transport.protocol", "smtps");&lt;br /&gt;propsSSL.put("mail.smtps.host", "smtp.gmail.com");&lt;br /&gt;propsSSL.put("mail.smtps.auth", "true");&lt;br /&gt;&lt;br /&gt;Session sessionSSL = Session.getInstance(propsSSL);&lt;br /&gt;sessionSSL.setDebug(true);&lt;br /&gt;&lt;br /&gt;Message messageSSL = new MimeMessage(sessionSSL);&lt;br /&gt;messageSSL.setFrom(new InternetAddress("random_sender_4568744122@gmail.com", "John Smith"));&lt;br /&gt;messageSSL.setRecipients(Message.RecipientType.TO, InternetAddress.parse("random_recipient_4568744122@gmail.com")); // real recipient&lt;br /&gt;messageSSL.setSubject("Test mail using SSL");&lt;br /&gt;messageSSL.setText("This is test email sent to Your account using SSL.");&lt;br /&gt;&lt;br /&gt;Transport transportSSL = sessionSSL.getTransport();&lt;br /&gt;transportSSL.connect("smtp.gmail.com", 465, "random_sender_4568744122@gmail.com", "sender_account_pass"); // account used&lt;br /&gt;transportSSL.sendMessage(messageSSL, messageSSL.getAllRecipients());&lt;br /&gt;transportSSL.close();&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note: &lt;/b&gt;in both cases You for the connect() method, You have to pass a real login and password of the Google Mail account used. The main differences between those two methods are: different protocol (smtp for TLS and smtps for SSL), different ports (587 for TLS and 465 for SSL). In addition TLS requires STARTTLS.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;b style="color: black;"&gt;Note:&lt;/b&gt;&lt;span style="color: black;"&gt; make sure that &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;Java&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;Eclipse&lt;/a&gt; are properly installed and configured for running the project      (additional configuration may be required if different directories are      used). &lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Eclipse complete sample project is &lt;/span&gt;&lt;a href="https://sites.google.com/site/technologyforhuman/GoogleJavaMail.zip" style="font-family: Verdana,sans-serif;"&gt;here&lt;/a&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;   (with all required libraries). &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-8751535572150797799?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/8751535572150797799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/8751535572150797799'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/08/sending-emails-using-java-mail-and.html' title='Sending emails using Java Mail and Google Mail account'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-4291359402303419174</id><published>2011-08-03T23:38:00.001+02:00</published><updated>2011-08-03T23:39:54.440+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>SSL in Tomcat under Eclipse (part 2 - certificate from CA)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;You should be able to generate self signed SSL certificate and integrate it into Tomcat, as described in &lt;a href="http://technology-for-human.blogspot.com/2011/08/ssl-in-tomcat-under-eclipse-part-1-self.html"&gt;previous post&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt; how to obtain and install a real SSL certificate from well known Certificate Authority (CA)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In the previous post I described the complete procedure of generating self signed SSL certificate and integrating it into Tomcat. In this post I would like to focus on the example with real certificate obtained from CA - I will use Thawte as example.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note:&lt;/b&gt; let's assume that You created an application which is going to be visible under the following URL: &lt;b&gt;http://www.myapp.com&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; generating self signed certificate for domain www.myapp.com.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This is exactly the same step to step 1 in &lt;a href="http://technology-for-human.blogspot.com/2011/08/ssl-in-tomcat-under-eclipse-part-1-self.html"&gt;previous post&lt;/a&gt;. You have to execute the following command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -genkey -alias myappcert -keyalg RSA -keystore myapp.keystore&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; Generate Certificate Signing Request (CSR).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;You have to generate a special request, which will be send to the CA. You have to execute command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -certreq -keyalg RSA -alias myappcert -file certreq.csr -keystore myapp.keystore&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Generated request is saved as a certreq.csr file, which will be send to CA. CA will use this file to generate certificate signed by them. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b style="color: red;"&gt;Important:&lt;/b&gt; You have to use exactly the same alias (in this example: myappcert) for step 1 and step 2.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; Getting certificate from CA.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Usually certificate are delivered in &lt;b&gt;PKCS#7&lt;/b&gt; or &lt;b&gt;X.509&lt;/b&gt; format. For the first one, the file with certificate will have &lt;b&gt;.p7b&lt;/b&gt; extension, for the second one - &lt;b&gt;.cer&lt;/b&gt;. Sometimes You can get such certificate &lt;b&gt;also by email as a pure text&lt;/b&gt; - for the X.509 format, certificate will be placed between tags &lt;b&gt;-----BEGIN CERTIFICATE-----&lt;/b&gt; and &lt;b&gt;-----END CERTIFICATE-----&lt;/b&gt;, for PKCS#7 certificate will be placed between tags &lt;b&gt;-----BEGIN PKCS7-----&lt;/b&gt; and &lt;b&gt;-----END PKCS7-----&lt;/b&gt;. Then You have to copy the certificate content (including those begin/end tags!) and save this as a .cer or .p7b file (You can use Notepad for that). Now You are ready to import Your signed certificate.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4: &lt;/b&gt;importing signed certificate.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;a) as a .p7b (PKCS#7) format:&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Acording to the Thawte, when You obtained Your certificate as a .p7b file, You need only one command to import and install this certificate in Your keystore:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -alias myappcert -trustcacerts -file signed_cert.p7b&amp;nbsp; -keystore myapp.keystore&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;where &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;signed_cert.p7b&lt;/span&gt; is a signed certificate obtained from CA.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;b) as a .cer (X.509) format:&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;According to the Thawte, when You obtained Your certificate as .cer file,&amp;nbsp; You need to download Primary and Secondary Intermediate CAs and import them. They are delivered as .p7b format (i.e. intermediate.p7b). I should import them first, using command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -trustcacerts -alias intermediatecerts&amp;nbsp; -file intermediate.p7b -keystore myapp.keystore&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;and then import my certificate (it is in .cer file signed_cert.cer) using this command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -trustcacerts -alias myappcert -file signed_cert.cer -keystore myapp.keystore&lt;/span&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;where &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;signed_cert.cer&lt;/span&gt; is a signed certificate obtained from CA.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Problem and workaround: &lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Both above ways seems to be simple, but... when I was buying some time ago a web SSL certificate from Thawte, I  receive certificate as a pure text in e-mail. Certificate was in X.509  format (I had tags ----BEGIN/END CERTIFICATE-----). I created a &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;signed_cert.cer&lt;/span&gt; file from that e-mail content. Then I tried to install intermediate certificates like it was described in Thawte documentation.&lt;b&gt; Unfortunately it didn't work&lt;/b&gt;. The first command for importing intermediate certificates failed with error:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool error: java.lang.Exception: Input not an X.509 certificate&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It seems that &lt;b&gt;keytool does not work with .p7b format&lt;/b&gt; (I used JDK 1.6.0_16), so I expect that even if I get my certificate as .p7b file (complete, without need to import intermediate certificates as in a) subpoint) it will also not work. I took a .p7b file with intermediate certificates, opened it under Windows, and for each certificate found inside i exported it as a X.509 DER certificate, giving each file .cer extension. So I had three .cer (X.509) files: signed_cert.cer, thawte_primary.cer, thawte_secondary.cer. Now I had to import intermediate certificates and after that import my signed certificate with those commands:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -trustcacerts -alias primary -file thawte_primary.cer -keystore myapp.keystore&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -trustcacerts -alias secondary -file thawte_secondary.cer.cer -keystore myapp.keystore&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -import -trustcacerts -alias myappcert -file signed_cert.cer -keystore myapp.keystore&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now import was OK. So the &lt;b&gt;general workaround rule&lt;/b&gt; &lt;b&gt;(if there are any troubles) is:&lt;/b&gt; get all needed certificates in X.509 form, import intermediate certificates (if any required) and import Your signed certificate at the end.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b style="color: red;"&gt;Important:&lt;/b&gt; You have to use exactly the same  alias (in this example: myappcert) like You used in step 1 and step 2,  except for importing intermediate certificates - You can use whatever  alias You like. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; copy Your &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myapp.keystore&lt;/span&gt; file into Tomcat's /conf directory&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; modify Tomcat configuration to use SSL certificate&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It is exactly the same as step 3 in &lt;a href="http://technology-for-human.blogspot.com/2011/08/ssl-in-tomcat-under-eclipse-part-1-self.html"&gt;previous post&lt;/a&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's all.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-4291359402303419174?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4291359402303419174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4291359402303419174'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/08/ssl-in-tomcat-under-eclipse-part-2.html' title='SSL in Tomcat under Eclipse (part 2 - certificate from CA)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-6942387546899916476</id><published>2011-08-01T23:21:00.001+02:00</published><updated>2011-08-01T23:23:58.219+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>SSL in Tomcat under Eclipse (part 1 - self signed certificate)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Tomcat for the Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt; how to set up Tomcat for SSL connection using self signed certificate under Eclipse&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;When You want to secure Your application SSL is the most natural choice. In order to make Your application be recognized as trusted by browser, You can by a buy a certificate from well known certificate authority (CA), which will be generated for the domain Your application uses. If You do not care about being recognized as trusted service, but instead You just want to encrypt the data exchanged between server and client's browser, You can use Your own self signed SSL certificate. In this post I will show how to generate such SSL certificate and how to set up Tomcat (from the Eclipse level) to use generated certificate.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note:&lt;/b&gt; let's assume that You created an application which is going to be visible under the following URL: &lt;b&gt;http://www.myapp.com&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; generating self signed certificate for domain www.myapp.com.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Go into Your Java bin directory (i.e &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;C:\Development\Java\bin&lt;/span&gt;). Then open Windows console (under Windows Vista/7 open the console with Administrator right) and type in command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;keytool -genkey -alias myappcert -keyalg RSA -keystore myapp.keystore &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;where &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myappcert&lt;/span&gt; is the name of the certificate being generated and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myapp.keystore&lt;/span&gt; is a file where certificate will be stored. You will be asked about the password for created the myapp.keystore file. Type in "mypass", press Enter and type it again and press Enter again. Then You will be asked for some details about You:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-8FQCnPzGteE/TjcNUgwiI1I/AAAAAAAAF4Y/cxwF25gkjCQ/s1600/SSL_self_signed_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="227" src="http://3.bp.blogspot.com/-8FQCnPzGteE/TjcNUgwiI1I/AAAAAAAAF4Y/cxwF25gkjCQ/s400/SSL_self_signed_1.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that for the first question about first and last name I  gave answer www.myapp.com. &lt;b&gt;This is very important&lt;/b&gt; - this name (known as  CN - Common Name) will be used for the checking if certificate on the  page we visit was generated for the same URL which we typed in in the  browser.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;At the end You will be asked for the password for the  newly created certificate. The password must be the same as one used for  &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myapp.keystore&lt;/span&gt; file ("mypass"). Do not type antyhing, just press Enter to use the same password. Your myapp.keystore file containing myappcert certificate is ready.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; copy Your &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;myapp.keystore&lt;/span&gt; file into Tomcat's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/conf&lt;/span&gt; directory&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt;&amp;nbsp; modify Tomcat configuration to use SSL certificate.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Make sure that Your Tomcat is configured with Eclipse and works OK without SSL (start Tomcat from Eclipse and type in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;http://localhost:8080&lt;/span&gt; in the browser). Stop Tomcat if it is running. Then open &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; file form the "Servers" view:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-9w5l8swmAaA/TjcP-eKjK9I/AAAAAAAAF4c/L8kho83aTqA/s1600/SSL_self_signed_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="167" src="http://4.bp.blogspot.com/-9w5l8swmAaA/TjcP-eKjK9I/AAAAAAAAF4c/L8kho83aTqA/s400/SSL_self_signed_2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;and locate default &lt;connector&gt; element for standard HTTP connections (marked red). Then add additional &lt;connector&gt; element for the SSL connection (next to existing one):&lt;/connector&gt;&lt;/connector&gt;&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;Connector&lt;br /&gt;        SSLEnabled="true"&lt;br /&gt;        clientAuth="false"&lt;br /&gt;        keyAlias="myappcert"&lt;br /&gt;        keystoreFile="conf/myapp.keystore"&lt;br /&gt;        keystorePass="mypass"&lt;br /&gt;        maxThreads="200"&lt;br /&gt;        port="8081"&lt;br /&gt;        scheme="https"&lt;br /&gt;        secure="true"&lt;br /&gt;        sslProtocol="TLS"&lt;br /&gt; /&amp;gt; &lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that next to some specific SSL settings, we set the location of the keystore file, the password for that file and certificate name to be use. SSL connection uses port 8081, where normal HTTP connection &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;uses port 8080.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 1:&lt;/b&gt; all modification of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; file were done from Eclipse level, using "Servers" view. If You want to use Eclipse WTP for starting Tomcat (like I do so far) You &lt;b&gt;can't edit this file from elsewhere&lt;/b&gt;. Eclipse WTP overrides original Tomcat configuration files by files visible under "Servers" - changes done outside Eclipse &lt;b&gt;will not be visible for WTP&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; I added &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;connector&gt;&lt;/connector&gt;&lt;/span&gt; element specific for SSL next to existing &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;connector&gt;&lt;/connector&gt;&lt;/span&gt; element for standard non encrypted HTTPS connections. This is second issue directly connected with Eclipse WTP - &lt;b&gt;when You remove standard connector for HTTP, Eclipse will close Tomcat&lt;/b&gt; after a time set in "Timeouts" section in the Tomcat settings:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-t2Q1M9SjE6k/TjcUxCkJepI/AAAAAAAAF4g/eDyHhkXDUn4/s1600/SSL_self_signed_3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="http://3.bp.blogspot.com/-t2Q1M9SjE6k/TjcUxCkJepI/AAAAAAAAF4g/eDyHhkXDUn4/s400/SSL_self_signed_3.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Some people try to extend the timeout time into long period, but still after this period Eclipse kills Tomcat process, as if Tomcat was not properly started in the required time. Unfortunately there is no way to set timeout into ifinite time - the only way to fix this under WTP is to leave standard HTTP &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;connector&gt;&lt;/connector&gt;&lt;/span&gt; element in Tomcat's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server.xml&lt;/span&gt; file.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; that's all. Tomcat is configured to work with SSL.&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Try to enter the URL: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;https://localhost:8081&lt;/span&gt;. If You see Tomcat's page, everything works OK (You can see certificate warning - You Need to add security exception for that certificate). Of course You can still open the same Tomcat page by standard HTTP (You have two &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;connector&gt;&lt;/connector&gt;&lt;/span&gt; elements), just enter &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;http://localhost:8080&lt;/span&gt; URL.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-6942387546899916476?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/6942387546899916476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/6942387546899916476'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/08/ssl-in-tomcat-under-eclipse-part-1-self.html' title='SSL in Tomcat under Eclipse (part 1 - self signed certificate)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-8FQCnPzGteE/TjcNUgwiI1I/AAAAAAAAF4Y/cxwF25gkjCQ/s72-c/SSL_self_signed_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-4141942439359571362</id><published>2011-07-27T19:52:00.004+02:00</published><updated>2011-08-01T23:22:34.216+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Tomcat OutOfMemoryError: Heap space/PermGen space</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Have You ever seen such error in Your logs? Probably yes. It simply means that available memory for Tomcat was consumed and nothing left. To be precise: &lt;b&gt;available memory for JVM which Tomcat uses to run&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;What causes this error? It can be caused by memory leaks in the application or the applications has big requirements "by design", even if there are no memory leaks. For the first case You should use some profiling tools to find and fix memory leaks - perhaps this might help without need to change memory settings for Tomcat JVM. If You are sure that Your application has no memory leaks, the only way is to increase memory used by Tomcat JVM. See below how to do that - please note that I described modifying &lt;b&gt;Tomcat memory settings when it is installed as a service under Windows OS&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;32-bit Windows&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The main problem here is that 32-bit OS is able to see no more than 3,2GB of RAM, even if You have 4GB or more physically installed. This is upper limit of memory that can be use - in theory. However, in practise You will not be able to use more than 1 to 1,5GB of RAM for Tomcat's JVM - the rest of memory is used by OS itself and installed software.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;64-bit Windows&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's assume that You need to assign more than 1,5GB of RAM for Tomcat JVM. Therefore You need 64-bit OS with at least 4GB&lt;b&gt; &lt;/b&gt;of RAM (for example 64-bit Windows Professional supports up to 192GB of RAM). Of course You must also use 64-bit JDK - when You use 32-bit JDK under 64-bit OS, You will again face the limit of 3,2GB RAM. You also must use 64-bit version of Tomcat (as it contains Windows service     wrapper to use with 64-bit JVMs on 64-bit Windows platforms). Below You will find complete list of all needed steps:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; make sure You are using 64-bit Windows OS.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 2:&lt;/b&gt; install 64-bit JDK and set $JAVA_HOME to the installation directory.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 3:&lt;/b&gt; download .zip file with 64-bit Tomcat for Windows (file: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;apache-tomcat-[version]-windows-x64.zip&lt;/span&gt;).&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 4:&lt;/b&gt; extract Tomcat and go into Tomcat's &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/bin&lt;/span&gt; directory.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; open &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;service.bat&lt;/span&gt; file and locate the line with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;--JvmMS&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;--JvmMX &lt;/span&gt;parameters, and modify it with new values memory, eg:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp" ++JvmOptions "-XX:MaxPermSize=1024m" --JvmMs 2048 --JvmMx 4096&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;PermSize&lt;/span&gt; is set in different way than heap which has predefined &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;JvmMS&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;JvmMX&lt;/span&gt; flags.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 6:&lt;/b&gt; open Windows console with administrator rights, then go into Tomcat /bin and execute command:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;service.bat install tomcat6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 7:&lt;/b&gt; start service with command:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;net start tomcat6&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note 1:&lt;/b&gt; You can skip point 5 and execute directly point 6. After that just start &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;tomcat6w.exe&lt;/span&gt; which is a GUI tool for managing the service. You can set memory values there.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; as an alternative to above steps, You can download Tomcat service installer (file: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;apache-tomcat-[version].exe&lt;/span&gt;) which performs service installation, and then use &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;tomcat6w.exe&lt;/span&gt; tool for tune memory settings.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's all. Your Tomcat service should use provided memory settings. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-4141942439359571362?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4141942439359571362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4141942439359571362'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/07/tomcat-outofmemoryerror-heap.html' title='Tomcat OutOfMemoryError: Heap space/PermGen space'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-1211557363474428027</id><published>2011-05-22T17:41:00.005+02:00</published><updated>2011-05-22T18:22:25.607+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>PostgreSQL - strange database server errors under Windows</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;I often use PostgreSQL as a database server for my web applications which are usually deployed under Tomcat. PostgreSQL and Tomcat are registered as system services which starts automatically when Windows starts.&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In one of my application I have about 50 different databases with connection pools for each database, where each pool has about 10 connections opened. So I have about 500 connections opened for requests. Each opened connection is visible as a separate postgres.exe process in the system next to the own PostgreSQL processes also visible as postgres.exe (usually 5 processes). Sometimes &lt;b&gt;under Windows XP&lt;/b&gt; &lt;b&gt;Prof. SP 3&lt;/b&gt; I saw PostgreSQL stop working and in the server logs there were errors like: &lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: inherit;"&gt;&lt;b&gt;&lt;/b&gt;&amp;nbsp;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;java.net.SocketException: No buffer space available (maximum       connections reached?): recv failed &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: inherit;"&gt;or:&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: inherit;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;server process (PID XXXX) was terminated by exception       0xC0000142 HINT:&amp;nbsp; See C include file "ntstatus.h" for a description of the       hexadecimal value.&lt;/span&gt;&lt;/span&gt; &lt;/li&gt;&lt;/ul&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;No buffer space available error:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;"Maximum connection reached" may suggest that we set too low value of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;max_connections&lt;/span&gt; in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;postgresql.conf&lt;/span&gt; file. Let's assume that settings for connections amount and required memory are OK for the server, but the problem is still visible from time to time.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The first thing to be checked is amount of short-lived ports (ephemeral). Those ports are used by applications during their normal work. They are opened and live until certain application works, in comparison to server application ports that are typically open for the entire time that the server computer is running. They are assigned automatically from predefined range. Range differs between operating systems:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;a) Windows 2000 -&amp;gt; from 1024 to 5000&lt;br /&gt;b) Windows 2003 Server -&amp;gt; from 1024 to 5000&lt;br /&gt;c) Windows XP (all service packs) -&amp;gt; from 1024 to 5000&lt;br /&gt;d) Windows Vista -&amp;gt; from 49152 to 65535&lt;br /&gt;e) Windows 2008 Server -&amp;gt; from 49152 to 65535&lt;br /&gt;f) Windows 7 -&amp;gt; from 49152 to 65535 &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;g) Linux kernels -&amp;gt; from 32768 to 61000 (see /proc/sys/net/ipv4/ip_local_port_range)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If the available pool of ephemeral ports is exahsuted we see Windows WSAENOBUFS error (no buffer space, code 10055). In order to check for exceeded range, we have to see how many processes are running in the system and how many ports they are opening - we can use free &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb897437"&gt;TCPView&lt;/a&gt; application. We can kill the process that causes exceeding or we can increase the range of ephemeral ports. If we want to increase it, we have to change a registry entry named maxUserPort in:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\maxUserPort&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; &lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If that registry entry does not exist it means that system uses default value (see above) and we have to create this entry. Then we have to set a proper value for that entry (REG_DWORD) from the range 5000 to 65534.&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The second thing to be checked is limit of half-opened TCP/IP connections (connection with state SYN-RCVD). When this limit is exceeded, TCP/IP starts up  SYN flooding attack protection (when SynAttackProtect is enabled). This limit differs between operating systems:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;a) Windows 2000 Workstation -&amp;gt; 500&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;b) Windows 2000 Server -&amp;gt; 100&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;c) Windows Server 2003 -&amp;gt; 500&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;d) Windows XP SP 1 -&amp;gt; 100 &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;e) Windows XP SP 2, SP3 -&amp;gt; 10 &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;f) Windows Vista SP 1 -&amp;gt; 10&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;g) Windows Vista SP 2 -&amp;gt; limit removed (not implmented = unlimited)&lt;br /&gt;h) Windows Server 2008 SP 1 -&amp;gt; 10&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;i) Windows Server 2008 SP 2 -&amp;gt; limit removed (not implemented = unlimited)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;f) Windows 7 -&amp;gt; limit removed (not implemented = unlimited)&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We can use mentioned TCPView application to check for half-opened TCP connections. This limit can be increased by changing the registry entry named TcpMaxHalfOpen in:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpMaxHalfOpen&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If that registry entry does not exist it means that system uses default value (see above) and we have to create this entry and then manualy assign new value.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Under Windows Vista SP2, Windows 7 or Linux I did not see that error. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="color: red; font-family: Verdana,sans-serif;"&gt;0xC0000142 error&lt;/span&gt;&lt;span style="color: red;"&gt;: &lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This problem is not so easy to explain, although I was able to fix it. The error code means that "A dynamic link library (DLL) initialization routine failed." I am not sure what exacly causes this...&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In my case under &lt;b&gt;Windows XP Prof. SP 3&lt;/b&gt;, when I started my application and number of postgres.exe processes was about 100 (it should be about 500, see description at the top) the whole database server process was suddenly terminated and I saw second mentioned error (with error code &lt;span style="font-family: inherit;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;0xC0000142&lt;/span&gt;&lt;/span&gt;) in the logs. The most important part here is that PostgreSQL service, which spawned many postgres.exe child processes, was &lt;b&gt;registered under LOCAL SYSTEM&lt;/b&gt; account, &lt;b&gt;without&lt;/b&gt; "Allow Service to Interact   with Desktop" option set.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It seems that this problem is not only connected with PostgreSQL. It is general problem with services and their subprocesses (see &lt;a href="http://stefan.samaflost.de/blog/en/Windows"&gt;this &lt;/a&gt;and &lt;a href="http://www.eggheadcafe.com/microsoft/Windows-Server/29929112/custom-services-failing-on-restart-when-70-are-running.aspx"&gt;that&lt;/a&gt; article). From the information found the problem my be connected with so-called desktop heaps (see more &lt;a href="http://support.microsoft.com/default.aspx?scid=kb;[LN];184802"&gt;here&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/ntdebugging/archive/2007/01/04/desktop-heap-overview.aspx"&gt;here&lt;/a&gt;). Some people having similar problems with many subprocesses did the workaround by setting "Allow Service to Interact   with Desktop" to true for their LOCAL SYSTEM services. I was able to fix it under Windows XP Prof. SP 3, by &lt;b&gt;registering PostgreSQL service for regular user account instead of LOCAL SYSTEM&lt;/b&gt; (see "Long Version" from my article about &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-hard.html"&gt;manual installation of PostgreSQL&lt;/a&gt; how to do this). I also checked this under Windows Vista SP2 and Windows 7 - it works OK there, even under LOCAL SYSTEM account. Under Linux I did not see that error.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I &lt;b&gt;did not try&lt;/b&gt; to assign more desktop heap from default for Windows XP SharedSection=1024,3072,512 (2nd or 3rd value needs to be changed) and then try it again to run under LOCAL SYSTEM without "Allow Service to Interact   with Desktop". Perhaps this might also help.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-1211557363474428027?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1211557363474428027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1211557363474428027'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/05/postgresql-strange-database-server.html' title='PostgreSQL - strange database server errors under Windows'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-9163223123623023496</id><published>2011-04-26T19:36:00.002+02:00</published><updated>2011-04-26T19:39:10.511+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>JSF 2, Spring 3, JPA (Hibernate 3), PostgreSQL, c3p0 - everything together (part 2 of  2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;running database and complete project with all required libraries integrated, described in previous post (can be found &lt;a href="http://technology-for-human.blogspot.com/2011/03/jsf-2-spring-3-jpa-hibernate-3.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4 (continued):&lt;/b&gt; configuration files - &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Comparing to a JSF 2.0 project with Spring integrated, only &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt; file will be changed - &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; and faces-config.xml files will be the same. We need to add below code into &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt;:&lt;/div&gt;&lt;pre class="brush: xml"&gt;&amp;lt;bean id="pooledDataSource" &lt;br /&gt; class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&amp;gt; &lt;br /&gt; &amp;lt;property name="driverClass" value="org.postgresql.Driver" /&amp;gt;&lt;br /&gt; &amp;lt;property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/bikes"/&amp;gt;  &lt;br /&gt;    &amp;lt;property name="user" value="postgres"/&amp;gt;  &lt;br /&gt;    &amp;lt;property name="password" value="pgpass"/&amp;gt; &lt;br /&gt;    &amp;lt;property name="maxPoolSize" value="10" /&amp;gt;&lt;br /&gt; &amp;lt;property name="maxStatements" value="0" /&amp;gt;&lt;br /&gt; &amp;lt;property name="minPoolSize" value="5" /&amp;gt;  &lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt; &lt;br /&gt;&amp;lt;bean id="JDBCDataSource" &lt;br /&gt; class="org.springframework.jdbc.datasource.DriverManagerDataSource" &amp;gt;&lt;br /&gt; &amp;lt;property name="driverClassName" value="org.postgresql.Driver"/&amp;gt;&lt;br /&gt; &amp;lt;property name="url" value="jdbc:postgresql://localhost:5432/bikes"/&amp;gt;&lt;br /&gt; &amp;lt;property name="username" value="postgres"/&amp;gt;&lt;br /&gt; &amp;lt;property name="password" value="pgpass"/&amp;gt;&lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt; &lt;br /&gt;&amp;lt;bean id="entityManagerFactory"&lt;br /&gt; class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&amp;gt;&lt;br /&gt; &amp;lt;property name="jpaVendorAdapter"&amp;gt;&lt;br /&gt;  &amp;lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" &amp;gt;&lt;br /&gt;   &amp;lt;!-- &lt;br /&gt;   Specific properties for Hibernate are in persistence.xml file, &lt;br /&gt;   but also can be placed here and removed from persistence.xml file.  &lt;br /&gt;   --&amp;gt;&lt;br /&gt;  &amp;lt;/bean&amp;gt;&lt;br /&gt; &amp;lt;/property&amp;gt;&lt;br /&gt; &amp;lt;property name="dataSource" ref="pooledDataSource" /&amp;gt;&lt;br /&gt; &amp;lt;property name="persistenceUnitName" value="persistenceUnit"/&amp;gt; &lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean &lt;br /&gt; class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;bean name="transactionManager" &lt;br /&gt; class="org.springframework.orm.jpa.JpaTransactionManager"&amp;gt;&lt;br /&gt; &amp;lt;property name="entityManagerFactory" ref="entityManagerFactory" /&amp;gt;  &lt;br /&gt;&amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;tx:annotation-driven /&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Note that this approach is similar to situation when plain Hibernate API is used with Spring: JPA's EntityManagerFactory is like Hibernate's SessionFactory, JPA's EntityManager (obtained from EntityManagerFactory) is like Hibernate's Session (obtained from SessionFactory). JPA's EntityManager is injected into Repositories (with the help of Spring's PersistenceAnnotationBeanPostProcessor class), while Hibernate's Session was injected into DAO's (with the help of Spring's HibernateDaoSupport class exteneded by each DAO). JPA's TransactionManager (built on EntityManagerFactory) is like Hibernate's HibernateTransactionManager (built on SessionFactory). &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;JPA's Repositories and Services are similar to oldschool DAOs and Facades. Repositories are injected into Services, while DAOs are injected into Facades.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that I defined here two datasources: a basic one without connection pool (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;JDBCDataSource&lt;/span&gt;) and second one using c3p0 as a connection pool (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;pooledDataSource&lt;/span&gt;).&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; configuration files - &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;persistence.xml&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In addition JPA uses a special configuration file named persistence.xml. This file contains additional settings for JPA vendor. The location of this file is described in this &lt;a href="http://javahowto.blogspot.com/2007/06/where-to-put-persistencexml-in-web-app.html"&gt;article&lt;/a&gt;. In order to have this file inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WEB-INF/classes/META-INF/persistence.xml&lt;/span&gt; under Eclipse, I created a directory "config" where I put META-INF subdirectory with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;persistence.xml&lt;/span&gt; file inside. Then I select the directory "config" to be used as a source directory. This means that content of "config" directory will be on classpath, and for a web application during a build time it will be moved into &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WEB-INF/classes&lt;/span&gt;. Note that I also added there log4j config file:&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-_m70LIxgyJ8/TaSyBFv4FfI/AAAAAAAAFqE/ONp5QUMA_qo/s1600/JSF2_Features_Spring_JPA_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="213" src="http://2.bp.blogspot.com/-_m70LIxgyJ8/TaSyBFv4FfI/AAAAAAAAFqE/ONp5QUMA_qo/s320/JSF2_Features_Spring_JPA_2.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Persistence.xml&lt;/span&gt; file contains some specific settings for Hibernate (as JPA vendor):&lt;/div&gt;&lt;pre class="brush: xml"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt;&lt;br /&gt;&amp;lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"&lt;br /&gt; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt; xsi:schemaLocation="http://java.sun.com/xml/ns/persistence&lt;br /&gt;        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&lt;br /&gt; version="1.0"&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL"&amp;gt;&lt;br /&gt;  &amp;lt;properties&amp;gt;   &lt;br /&gt;     &amp;lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /&amp;gt;&lt;br /&gt;     &amp;lt;property name="hibernate.show_sql" value="true" /&amp;gt;&lt;br /&gt;    &amp;lt;/properties&amp;gt; &lt;br /&gt; &amp;lt;/persistence-unit&amp;gt;&lt;br /&gt;&amp;lt;/persistence&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; configuration files - l&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;og4j.properties&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As I wrote before we will use Log4j instead of Hibernate's default SLF4j. Lets's log everything we can (we can see how Hibernate opens/closes connections, how connections are taken from the pool, how Spring manages transactions and so on):&lt;/div&gt;&lt;pre class="brush: xml"&gt;log4j.appender.A1=org.apache.log4j.ConsoleAppender&lt;br /&gt;log4j.appender.A1.layout=org.apache.log4j.PatternLayout&lt;br /&gt;log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n&lt;br /&gt;log4j.rootLogger=info,A1&lt;br /&gt;&lt;br /&gt;log4j.logger.com.mchange.v2=DEBUG &lt;br /&gt;log4j.logger.org.hibernate=DEBUG&lt;br /&gt;log4j.logger.org.springframework=DEBUG&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 7:&lt;/b&gt; database entities.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As shown at the beginning of previous post, we had only one entity represented by the class &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Bike.java&lt;/span&gt;. Instances of Bike.java where created inside Spring service nam&lt;code&gt;&lt;/code&gt;ed &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDataProvider&lt;/span&gt; (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProviderImp.java&lt;/span&gt;). Now we have a database with tables Bike, Bike_Category, Account and Role. For each table we should create one class (note: this is the simplest mapping one table to one class - there are other way to map tables to classes).&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Bike entity:&lt;/div&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.model;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@Table(name="bike")&lt;br /&gt;public class Bike implements Serializable {&lt;br /&gt;&lt;br /&gt; private Integer id;&lt;br /&gt; private BikeCategory category; &lt;br /&gt; &lt;br /&gt; @Id&lt;br /&gt; @GeneratedValue(strategy=GenerationType.IDENTITY)     &lt;br /&gt; @Column(name="bike_id")&lt;br /&gt; public Integer getId() {&lt;br /&gt;  return id;&lt;br /&gt; }&lt;br /&gt; public void setId(Integer id) {&lt;br /&gt;  this.id = id;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; @ManyToOne&lt;br /&gt; @JoinColumn(name="bike_category_id") &lt;br /&gt; public BikeCategory getCategory() {&lt;br /&gt;  return category;&lt;br /&gt; }&lt;br /&gt; public void setCategory(BikeCategory category) {&lt;br /&gt;  this.category = category;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; // rest of columns&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Bike_category entity:&lt;/div&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.model;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@Table(name="bike_category")&lt;br /&gt;public class BikeCategory {&lt;br /&gt; &lt;br /&gt; private Integer categoryId;&lt;br /&gt; &lt;br /&gt; @Id&lt;br /&gt; @GeneratedValue(strategy=GenerationType.IDENTITY)&lt;br /&gt;    @Column(name="bike_category_id")&lt;br /&gt; public Integer getCategoryId() {&lt;br /&gt;  return categoryId;&lt;br /&gt; }&lt;br /&gt; public void setCategoryId(Integer categoryId) {&lt;br /&gt;  this.categoryId = categoryId;&lt;br /&gt; }&lt;br /&gt; // rest of columns&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Account entity:&lt;/div&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.model;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@Table(name="account")&lt;br /&gt;public class Person {&lt;br /&gt; &lt;br /&gt; private Integer accountId;&lt;br /&gt; private Role currentRole;&lt;br /&gt; &lt;br /&gt; @Id&lt;br /&gt; @GeneratedValue(strategy=GenerationType.IDENTITY)&lt;br /&gt;    @Column(name="account_id")&lt;br /&gt; public Integer getAccountId() {&lt;br /&gt;  return accountId;&lt;br /&gt; }&lt;br /&gt; public void setAccountId(Integer accountId) {&lt;br /&gt;  this.accountId = accountId;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; @ManyToOne&lt;br /&gt; @JoinColumn(name="role_id") &lt;br /&gt; public Role getCurrentRole() {&lt;br /&gt;  return currentRole;&lt;br /&gt; }&lt;br /&gt; public void setCurrentRole(Role currentRole) {&lt;br /&gt;  this.currentRole = currentRole;&lt;br /&gt; }&lt;br /&gt; // rest of columns &lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Role entity:&lt;/div&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.model;&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;@Table(name="role")&lt;br /&gt;public class Role {&lt;br /&gt;&lt;br /&gt; private Integer roleId;&lt;br /&gt; &lt;br /&gt; @Id&lt;br /&gt; @GeneratedValue(strategy=GenerationType.IDENTITY)&lt;br /&gt;    @Column(name="role_id")&lt;br /&gt; public Integer getRoleId() {&lt;br /&gt;  return roleId;&lt;br /&gt; }&lt;br /&gt; public void setRoleId(Integer roleId) {&lt;br /&gt;  this.roleId = roleId;&lt;br /&gt; }&lt;br /&gt; // rest of columns&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Note how classes are mapped to tables (using &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@Table(name="...")&lt;/span&gt;) and how fields are mapped to columns (using &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@Column(name="...")&lt;/span&gt;). We also mapped many-to-one relations between tables using &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@ManyToOne&lt;/span&gt; annotation with proper joim column name. Note also how primary keys are generated - we do not use PostgreSQL sequence (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;GenerationType.SEQUENCE&lt;/span&gt;) - PostgreSQL supports &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;SERIAL&lt;/span&gt; data type for primary keys, which actually hides sequences (see &lt;a href="http://wiki.postgresql.org/wiki/FAQ#How_do_I_create_a_serial.2Fauto-incrementing_field.3F"&gt;this link&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 8:&lt;/b&gt; repositories and services.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Spring repositories are similar to DAO. All database interactions is done insde them. As an example, let's look inside repository resposnible for loading and saving bikes - &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikesDAOImpl.java&lt;/span&gt;:&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.repositories.impl;&lt;br /&gt;&lt;br /&gt;@Repository("BikesRepository")&lt;br /&gt;public class BikesDAOImpl implements BikesDAO {&lt;br /&gt; &lt;br /&gt; private EntityManager em = null;&lt;br /&gt; &lt;br /&gt; @PersistenceContext&lt;br /&gt; public void setEntityManager(EntityManager em) {&lt;br /&gt;  this.em = em;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; @Override&lt;br /&gt; public Bike loadSelectedBike(Integer bikeId) {&lt;br /&gt;  return em.find(Bike.class, bikeId);&lt;br /&gt; }&lt;br /&gt; // other methods for saving bike and loading bike for given category&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This repository is used in Spring's service named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDataProvider &lt;/span&gt;(&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProviderImpl.java&lt;/span&gt;):&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.services.impl;&lt;br /&gt;...&lt;br /&gt;@Service("bikeDataProvider")&lt;br /&gt;public class BikeDataProviderImpl implements BikeDataProvider {&lt;br /&gt;&lt;br /&gt; @Resource(name="BikesRepository")&lt;br /&gt; private BikesDAO bikesRepository;&lt;br /&gt; &lt;br /&gt; @Resource(name="DictionaryRepository")&lt;br /&gt; private DictionariesDAO dictionaryRepository;&lt;br /&gt;&lt;br /&gt; public Bike getBikeById(Integer id){&lt;br /&gt;  return bikesRepository.loadSelectedBike(id);&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; @Transactional&lt;br /&gt; public void add(Bike newBike, Integer categoryId) {&lt;br /&gt;  BikeCategory categorySelected = dictionaryRepository.loadBikeCategroryById(categoryId);&lt;br /&gt;  newBike.setCategory(categorySelected);&lt;br /&gt;  bikesRepository.saveBike(newBike);&lt;br /&gt; } &lt;br /&gt; &lt;br /&gt; // other methods using repositories&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Similar solution is used for account (person) repository which is then used in Spring's Security service named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;userDetailsService&lt;/span&gt; (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;UserDetailsServiceImpl.java&lt;/span&gt;). Note how easy is to execute a method within database transaction - just use &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@Transactional&lt;/span&gt; annotation and voila.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;That's all about adding JPA into Spring-based JSF2 sample application.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The rest of application code (web pages, JSF managed beans) are the same  as in pure Spring example project - we only modified services by  providing repositories.&lt;b&gt; &lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;How to test it? After deploying application on the server and starting the server, we have to open a browser and type in URL:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;http://localhost:8080/JSF2FeaturesSpringJPA&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: inherit;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;b style="color: black;"&gt;Note:&lt;/b&gt;&lt;span style="color: black;"&gt; make sure that &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html" style="color: black;"&gt;Java&lt;/a&gt;&lt;span style="color: black;"&gt;, &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html" style="color: black;"&gt;Eclipse&lt;/a&gt;&lt;span style="color: black;"&gt; and &lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html" style="color: black;"&gt;Tomcat&lt;/a&gt;&lt;span style="color: black;"&gt;     are properly installed and configured for running the project     (additional configuration may be required if different directories are     used).&lt;/span&gt; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2FeaturesSpringJPA.zip"&gt;here&lt;/a&gt;   (with all required libraries). The sample project is a ready to run   application which contains JPA (Hibernate), Spring (with Spring Security). You can also download a war file located &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2FeaturesSpringJPA.war"&gt;here&lt;/a&gt; (just copy it inside webapps folder in Your Tomcat and start Tomcat with the script startup.bat). Make sure that before doing this You created required database and PostgreSQL server is up and running (You can check access using pgAdmin III).&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-9163223123623023496?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/9163223123623023496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/9163223123623023496'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/04/jsf-2-spring-3-jpa-hibernate-3.html' title='JSF 2, Spring 3, JPA (Hibernate 3), PostgreSQL, c3p0 - everything together (part 2 of  2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-_m70LIxgyJ8/TaSyBFv4FfI/AAAAAAAAFqE/ONp5QUMA_qo/s72-c/JSF2_Features_Spring_JPA_2.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-8104474114408909984</id><published>2011-03-09T21:28:00.002+01:00</published><updated>2011-04-12T19:07:31.830+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>JSF 2, Spring 3, JPA (Hibernate 3), PostgreSQL, c3p0 - everything together (part 1 of 2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;a working example of JSF 2.0 application with Spring Framework and Spring Security integrated (can be found &lt;a href="http://technology-for-human.blogspot.com/2011/01/jsf-2-with-spring-3-protection-with.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed PostgreSQL database (simple installation variant described &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-wersja-soft.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to use database for loading and storing the data in the sample JSF 2.0&amp;nbsp; application&lt;/li&gt;&lt;li&gt;how to access the database from the application using JPA (Hibernate) and Spring&lt;/li&gt;&lt;li&gt;how to optimize database access by using connection pool (c3p0)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It is a high time to create a real working example with a database. Sample application used in previous posts use no database. We had Spring's managed service named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDataProvider&lt;/span&gt; acting as a database - all bikes data were created in that service during startup, all bikes data were retrieved from that service, even new bike data were stored internally in the service:&lt;/div&gt;&lt;pre class="brush: java" style="font-family: Verdana,sans-serif;"&gt;package com.jsfsample.services.impl;&lt;br /&gt;...&lt;br /&gt;@Service("bikeDataProvider")&lt;br /&gt;public class BikeDataProviderImpl implements BikeDataProvider {&lt;br /&gt;&lt;br /&gt; private List&amp;lt;Bike&amp;gt; bikes;&lt;br /&gt;&lt;br /&gt; @PostConstruct&lt;br /&gt; private void prepareData(){&lt;br /&gt;  bikes = new ArrayList&amp;lt;Bike&amp;gt;();&lt;br /&gt;  &lt;br /&gt;  // MTB&lt;br /&gt;  Bike mtb1 = new Bike();&lt;br /&gt;  mtb1.setId(1);&lt;br /&gt;  mtb1.setName("Kellys Mobster");&lt;br /&gt;  mtb1.setDescription("Kellys Mobster, lorem ipsut...");&lt;br /&gt;  mtb1.setPrice(6500);&lt;br /&gt;  mtb1.setCategory(1);&lt;br /&gt;  &lt;br /&gt;  // ... rest of mock bikes created here&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public List&amp;lt;Bike&amp;gt; getBikesByCategory(Integer categoryId, boolean onlyWithDiscount) {&lt;br /&gt;  // returns bikes by given category&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public Bike getBikeById(Integer id){&lt;br /&gt;  // returns certain bike for its details&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public void add(Bike newBike) {&lt;br /&gt;  // add new bike &lt;br /&gt;  bikes.add(newBike);&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The same method of creating mock data was used in Spring's managed service named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;userDetailsService&lt;/span&gt; - users and their authorities were created directly inside the service:&lt;/div&gt;&lt;pre class="brush: java" style="font-family: Verdana,sans-serif;"&gt;package com.jsfsample.application.impl;&lt;br /&gt;...&lt;br /&gt;@Service("userDetailsService")&lt;br /&gt;public class UserDetailsServiceImpl implements UserDetailsService {&lt;br /&gt;&lt;br /&gt; private HashMap&amp;lt;String, org.springframework.security.core.userdetails.User&amp;gt; users = new HashMap&amp;lt;String, org.springframework.security.core.userdetails.User&amp;gt;();&lt;br /&gt; &lt;br /&gt; @Override&lt;br /&gt; public UserDetails loadUserByUsername(String username) {&lt;br /&gt;  // returns user&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @PostConstruct&lt;br /&gt; public void init() {&lt;br /&gt;  &lt;br /&gt;  // mocked roles  &lt;br /&gt;  Collection&amp;lt;GrantedAuthority&amp;gt; adminAuthorities = new ArrayList&amp;lt;GrantedAuthority&amp;gt;();&lt;br /&gt;  adminAuthorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));&lt;br /&gt;  &lt;br /&gt;  Collection&amp;lt;GrantedAuthority&amp;gt; userAuthorities = new ArrayList&amp;lt;GrantedAuthority&amp;gt;();&lt;br /&gt;  userAuthorities.add(new GrantedAuthorityImpl("ROLE_REGISTERED"));&lt;br /&gt;  &lt;br /&gt;  boolean enabled = true;&lt;br /&gt;  boolean accountNonExpired = true;&lt;br /&gt;  boolean credentialsNonExpired = true;&lt;br /&gt;  boolean accountNonLocked = true;&lt;br /&gt;  &lt;br /&gt;  // mocked users with roles&lt;br /&gt;  users.put("admin", new org.springframework.security.core.userdetails.User("admin", "admin", enabled, accountNonExpired,&lt;br /&gt;    credentialsNonExpired, accountNonLocked, adminAuthorities));&lt;br /&gt;  &lt;br /&gt;  users.put("user", new org.springframework.security.core.userdetails.User("user", "user", enabled, accountNonExpired,&lt;br /&gt;    credentialsNonExpired, accountNonLocked, userAuthorities));&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In both cases all data are created in the method annotated with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@PostConstruct&lt;/span&gt;. That annotation means, that method will be invoked first after creating an instance of a class (in this case Spring creates instances of those service classes).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Our objective is to remove that mocked data created explicite in the services classes and replace them with data coming from real database.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; we need database structure:&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE TABLE "role" (&lt;br /&gt; role_id SERIAL NOT NULL,&lt;br /&gt; name VARCHAR(32),  &lt;br /&gt; CONSTRAINT role_pk PRIMARY KEY (role_id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;CREATE TABLE "account" (&lt;br /&gt; account_id SERIAL NOT NULL,&lt;br /&gt; role_id INTEGER NOT NULL,&lt;br /&gt; login VARCHAR(32),&lt;br /&gt; password VARCHAR(32),&lt;br /&gt; CONSTRAINT account_pk PRIMARY KEY (account_id),&lt;br /&gt; CONSTRAINT role_id_fk FOREIGN KEY (role_id) REFERENCES role(role_id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;CREATE TABLE "bike_category" (&lt;br /&gt; bike_category_id SERIAL NOT NULL,&lt;br /&gt; name VARCHAR(32),  &lt;br /&gt; CONSTRAINT bike_category_pk PRIMARY KEY (bike_category_id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;CREATE TABLE "bike" (&lt;br /&gt; bike_id SERIAL NOT NULL,&lt;br /&gt; bike_category_id INTEGER NOT NULL,&lt;br /&gt; name VARCHAR(32),&lt;br /&gt; description TEXT,&lt;br /&gt; price numeric(10,2),&lt;br /&gt; discount_price numeric(10,2),    &lt;br /&gt; CONSTRAINT bike_pk PRIMARY KEY (bike_id),&lt;br /&gt; CONSTRAINT bike_category_fk FOREIGN KEY (bike_category_id) REFERENCES bike_category(bike_category_id)&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This is very simple database with two many-to-one relations: many users belongs to (have) one role and many bikes belongs to (have) one category. Of course in real world user would have many roles, so we would use many-to-many relation, but I decided to use many-to-one to simplify it.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Tables account and role will be used by Spring Security - they store users and their authorities (roles). Tables bike and bike_category are the "heart" of bike store.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; when structure is ready, it is time to insert some sample data:&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;INSERT INTO role (name) values ('ROLE_ADMIN'); -- id 1&lt;br /&gt;INSERT INTO role (name) values ('ROLE_REGISTERED'); -- id 2&lt;br /&gt;&lt;br /&gt;INSERT INTO account (role_id, login, password) values (1, 'admin', 'admin'); -- ROLE_ADMIN&lt;br /&gt;INSERT INTO account (role_id, login, password) values (2, 'user', 'user'); -- ROLE_REGISTERED&lt;br /&gt;&lt;br /&gt;INSERT INTO bike_category (name) values ('Mountain'); -- id 1&lt;br /&gt;INSERT INTO bike_category (name) values ('Trekking'); -- id 2&lt;br /&gt;INSERT INTO bike_category (name) values ('Cross'); -- id 3&lt;br /&gt;&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (1, 'Kellys Mobster', 'Kellys Mobster, lorem ipsut...', 6500, null); -- Mountain&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (1, 'Scott Scale', 'Scott Scale, lorem ipsut...', 18900, null); -- Mountain&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (1, 'Author Magnum', 'Author Magnum, lorem ipsut...', 17200, 15500); -- Mountain&lt;br /&gt;&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (2, 'Giant Accend', 'Giant Accend, lorem ipsut...', 5000, 4600); -- Trekking&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (2, 'Merida Freeway', 'Merida Freeway, lorem ipsut...', 2400, 2100); -- Trekking&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (2, 'Mbike Massive', 'Mbike Massive, lorem ipsut...', 1900, null); -- Trekking&lt;br /&gt;&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (3, 'Giant Roam XR 1', 'Giant Roam XR 1, lorem ipsut...', 3900, null); -- Cross&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (3, 'Cannondale Quick Cx', 'Cannondale Quick Cx, lorem ipsut...', 4999, null); -- Cross&lt;br /&gt;INSERT INTO bike (bike_category_id, name, description, price, discount_price) values (3, 'Cube Cross', 'Cube Cross, lorem ipsut...', 4500, 4200); -- Cross&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; adding required libraries into project.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-kPp5OMWzOlw/TXfcQBZ9_mI/AAAAAAAAFp8/eqC8KPG0FwU/s1600/JSF2_Features_Spring_JPA_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-kPp5OMWzOlw/TXfcQBZ9_mI/AAAAAAAAFp8/eqC8KPG0FwU/s320/JSF2_Features_Spring_JPA_1.PNG" width="197" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;Comparing those libraries with libraries from clean JSF 2.0 project (look &lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/TJEDMF3peKI/AAAAAAAAFRs/Icr94q8io-g/s1600/JSF2_Eclipse_project.PNG"&gt;here&lt;/a&gt;) or libraries from JSF 2.0 project with Spring (look &lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TQfWXfhx6SI/AAAAAAAAFlU/bgXDKk1aFAc/s1600/JSF2_Features_Spring_1.PNG"&gt;here&lt;/a&gt;) we have extra libraries here: Hibernate libraries marked green, Spring JPA libraries marked red and some third party libraries marked blue. Those blue libraries are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;c3p0 libraries for connection pool&lt;/li&gt;&lt;li&gt;log4j library and bridge library from sl4j to log4j - Hibernate by default uses sl4j, but we would like to use log4j&lt;/li&gt;&lt;li&gt;JDBC driver for PostgreSQL&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; configuration files - &lt;i&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;will be continued in next post.&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;The   complete working  example of mentioned application which will contain   all described issues, will be available in the last (second) article   of this serie.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-8104474114408909984?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/8104474114408909984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/8104474114408909984'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/03/jsf-2-spring-3-jpa-hibernate-3.html' title='JSF 2, Spring 3, JPA (Hibernate 3), PostgreSQL, c3p0 - everything together (part 1 of 2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-kPp5OMWzOlw/TXfcQBZ9_mI/AAAAAAAAFp8/eqC8KPG0FwU/s72-c/JSF2_Features_Spring_JPA_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-3188296209973517971</id><published>2011-01-28T21:37:00.006+01:00</published><updated>2011-03-04T19:12:30.298+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2 with Spring 3 - protection with Spring Security (part 2 of 2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;a working example of JSF 2.0 application with Spring Framework integrated (can be found &lt;a href="http://technology-for-human.blogspot.com/2010/12/jsf-2-with-spring-3-basics-part-1-of-2.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to use Spring Security Framework in order to protect web application&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;From the previous &lt;a href="http://technology-for-human.blogspot.com/2010/12/jsf-2-with-spring-3-basics-part-1-of-2.html"&gt;post&lt;/a&gt; we know what Spring Framework is, and what advantages it gives us when used in web application. Business logic managed by Spring is not the only one advantage coming from Spring - we can use &lt;b&gt;Spring's embedded mechanisms to secure our web application&lt;/b&gt;. This post will show the basic usage of Spring Security for securing our sample JSF 2.0 webapp.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;What parts of our application will be protected? Consider those scenarios: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;1.&lt;/b&gt; Only registered user (or page administrator) can see details of a selected bike.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;2.&lt;/b&gt; Only page administrator can add a new bike to the shop offer.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;We need two user roles which will determine the privilleges which user has: &lt;i&gt;registered users&lt;/i&gt; role and &lt;i&gt;admin users&lt;/i&gt; role. Moreover, for the scenario 2, we have to add a new function: adding new bike. For this function we will create a page &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;addBike.xhtml&lt;/span&gt; and a JSF managed bean for that page, named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;addBike.java&lt;/span&gt;. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;addBike.xhtml&lt;/span&gt; source code is shown below:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&lt;br /&gt;      xmlns:ui="http://java.sun.com/jsf/facelets"&lt;br /&gt;      xmlns:h="http://java.sun.com/jsf/html"&lt;br /&gt;      xmlns:f="http://java.sun.com/jsf/core"&amp;gt;&lt;br /&gt;  &amp;lt;ui:composition template="../shopTemplate.xhtml"&amp;gt;&lt;br /&gt;       &lt;br /&gt;        &amp;lt;ui:define name="content"&amp;gt;&lt;br /&gt;        &amp;lt;h:form&amp;gt;&lt;br /&gt;         &amp;lt;h:outputText value="#{msg['bikes.list.name']}: "/&amp;gt;&amp;lt;h:inputText value="#{addBike.name}" /&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;         &amp;lt;h:outputText value="#{msg['bikes.list.price']}: "/&amp;gt;&amp;lt;h:inputText value="#{addBike.price}" /&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;         &amp;lt;h:outputText value="#{msg['bikes.list.discountprice']}: "/&amp;gt;&amp;lt;h:inputText value="#{addBike.discountPrice}" /&amp;gt;&amp;lt;br/&amp;gt;         &lt;br /&gt;         &amp;lt;h:outputText value="#{msg['bikes.list.description']}: "/&amp;gt;&amp;lt;h:inputText value="#{addBike.description}" /&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;         &amp;lt;h:commandButton action="#{addBike.addNewBike}" value="#{msg['bikes.add.button']}" /&amp;gt;&lt;br /&gt;        &amp;lt;/h:form&amp;gt;&lt;br /&gt;        &amp;lt;/ui:define&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/ui:composition&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Nothing special - standard form for entering the data.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;addBike.java&lt;/span&gt; source code is also simple:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.managedbeans;&lt;br /&gt;...&lt;br /&gt;@ManagedBean(name="addBike")&lt;br /&gt;@SessionScoped&lt;br /&gt;public class AddBike implements Serializable {&lt;br /&gt;&lt;br /&gt; private static final long serialVersionUID = -2155913853431899821L;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; @ManagedProperty("#{bikeDataProvider}")&lt;br /&gt; private BikeDataProvider bikeDataProvider; // injected Spring defined service for bikes&lt;br /&gt; &lt;br /&gt; private String name;&lt;br /&gt; private String description;&lt;br /&gt; private String price;&lt;br /&gt; private String discountPrice;&lt;br /&gt; private Integer categoryId;&lt;br /&gt; &lt;br /&gt; public String addNewBike(){&lt;br /&gt;&lt;br /&gt;  Bike newBike = new Bike();&lt;br /&gt;  newBike.setName(getName());&lt;br /&gt;  newBike.setDescription(getDescription());&lt;br /&gt;  newBike.setPrice(Integer.parseInt(getPrice()));&lt;br /&gt;  newBike.setDiscountPrice(Integer.parseInt(getDiscountPrice()));&lt;br /&gt;  newBike.setCategory(categoryId);&lt;br /&gt;  &lt;br /&gt;  // save new bike and return to the shop&lt;br /&gt;  bikeDataProvider.add(newBike);  &lt;br /&gt;  return "/bikesShop.xhtml";&lt;br /&gt; }; &lt;br /&gt; ...&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Please note that we use here &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; class, which is Spring managed service, the same we used for loading bikes list and loading a certain bike details in previous &lt;a href="http://technology-for-human.blogspot.com/2010/12/jsf-2-with-spring-3-basics-part-1-of-2.html"&gt;post&lt;/a&gt;. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Now it is time for protected parts of application. I will show two ways of protecting webapp: &lt;b&gt;protecting resources&lt;/b&gt; (like access to certain page) and &lt;b&gt;protecting business logic methods execution&lt;/b&gt;. &lt;b&gt;Scenario 1 will be an example of protecting business logic&lt;/b&gt; and&lt;b&gt; scenario 2 will be an example of protecting resources&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;When user tries to access the protected area (resource or invoke protected method), application will check user roles and based on them will decide if let the user go further or force him to log in. Log in - that's right - a login page will be displayed where user will enter his credentials. Based on them Spring Security will decide what roles user has and depends on assigned roles further action will be continued or not. Let's modify our application to use Spring Security:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1. &lt;/b&gt;Modify configuration files:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt; source:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;...&lt;br /&gt; &amp;lt;!-- &lt;br /&gt; resource security  &lt;br /&gt; --&amp;gt;&lt;br /&gt; &amp;lt;sec:http auto-config="true" access-denied-page="/faces/accessDenied.xhtml"&amp;gt;&lt;br /&gt;  &amp;lt;sec:form-login login-page="/faces/login.xhtml" /&amp;gt;&lt;br /&gt;  &amp;lt;sec:intercept-url pattern="/faces/admin/**" access="ROLE_ADMIN" /&amp;gt;     &lt;br /&gt; &amp;lt;/sec:http&amp;gt;&lt;br /&gt; &amp;lt;!-- &lt;br /&gt; business logic (method) security &lt;br /&gt; --&amp;gt;&lt;br /&gt; &amp;lt;sec:global-method-security&lt;br /&gt;  secured-annotations="enabled" jsr250-annotations="enabled" &amp;gt;  &lt;br /&gt; &amp;lt;/sec:global-method-security&amp;gt;&lt;br /&gt; &amp;lt;!-- &lt;br /&gt; manager responsible for loading user account with assigned roles &lt;br /&gt; --&amp;gt;&lt;br /&gt; &amp;lt;sec:authentication-manager alias="authenticationManager"&amp;gt;&lt;br /&gt;  &amp;lt;sec:authentication-provider&lt;br /&gt;   user-service-ref="userDetailsService" /&amp;gt;&lt;br /&gt; &amp;lt;/sec:authentication-manager&amp;gt;&lt;br /&gt; ...&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Access-denied-page is invoked when user is &lt;b&gt;authenticated&lt;/b&gt; but is not &lt;b&gt;authorized&lt;/b&gt; to access protected resources. When user is &lt;b&gt;not authenticated&lt;/b&gt;, he is moved into form-login instead of access-denied-page.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; source:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;...&lt;br /&gt; &amp;lt;filter&amp;gt;&lt;br /&gt;  &amp;lt;filter-name&amp;gt;springSecurityFilterChain&amp;lt;/filter-name&amp;gt;&lt;br /&gt;  &amp;lt;filter-class&amp;gt;org.springframework.web.filter.DelegatingFilterProxy&amp;lt;/filter-class&amp;gt;&lt;br /&gt; &amp;lt;/filter&amp;gt;&lt;br /&gt; &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;  &amp;lt;filter-name&amp;gt;springSecurityFilterChain&amp;lt;/filter-name&amp;gt;&lt;br /&gt;  &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt; &amp;lt;/filter-mapping&amp;gt;&lt;br /&gt; ...&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2.&lt;/b&gt; Additional pages: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login.xhtml&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;accessDenied.xhtml&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;accessDenied.xhtml&lt;/span&gt; is simple page displaying only a message saying that the user is authenticated but still is not authorized to go further.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;login.xhtml&lt;/span&gt; is a simple page with login form where user enters his credentials (login and password). The more interesting part is corresponding managed bean LoginBean.java which uses a Spring service for authenticating users:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.managedbeans;&lt;br /&gt;...&lt;br /&gt;@ManagedBean(name = "loginBean")&lt;br /&gt;@SessionScoped&lt;br /&gt;public class LoginBean implements Serializable {&lt;br /&gt; private static final long serialVersionUID = 1L;&lt;br /&gt;&lt;br /&gt; private String login;&lt;br /&gt; private String password;&lt;br /&gt;&lt;br /&gt; @ManagedProperty(value = "#{authenticationService}")&lt;br /&gt; private AuthenticationService authenticationService; // injected Spring defined service for bikes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public String login() {&lt;br /&gt;&lt;br /&gt;  boolean success = authenticationService.login(login, password);&lt;br /&gt;  &lt;br /&gt;  if (success){&lt;br /&gt;   return "bikesShop.xhtml"; // return to application but being logged now &lt;br /&gt;  }&lt;br /&gt;  else{&lt;br /&gt;   FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Login or password incorrect."));   &lt;br /&gt;   return "login.xhtml";&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; ...&lt;br /&gt;}&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;When login was successful and user is authenticated, he is moved to the shop. If not a proper message is displayed and user can re-enter his credentials or go back to the shop without login. Let's look inside AuthenticationService.java class which is a service deciding if user is authenticated or not.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3.&lt;/b&gt; AuthenticationService implementation:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.application.impl;&lt;br /&gt;...&lt;br /&gt;@Service("authenticationService")&lt;br /&gt;public class AuthenticationServiceImpl implements com.jsfsample.application.AuthenticationService {&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; @Resource(name = "authenticationManager")&lt;br /&gt; private AuthenticationManager authenticationManager; // specific for Spring Security&lt;br /&gt;&lt;br /&gt; @Override&lt;br /&gt; public boolean login(String username, String password) {&lt;br /&gt;  try {&lt;br /&gt;   Authentication authenticate = authenticationManager&lt;br /&gt;     .authenticate(new UsernamePasswordAuthenticationToken(&lt;br /&gt;       username, password));&lt;br /&gt;   if (authenticate.isAuthenticated()) {&lt;br /&gt;    SecurityContextHolder.getContext().setAuthentication(&lt;br /&gt;      authenticate);    &lt;br /&gt;    return true;&lt;br /&gt;   }&lt;br /&gt;  } catch (AuthenticationException e) {   &lt;br /&gt;  }&lt;br /&gt;  return false;&lt;br /&gt; }&lt;br /&gt; ...&lt;br /&gt;}&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;This Spring managed service uses internally a class &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;AuthenticationManager&lt;/span&gt;, which comes from Spring Security and was defined as a manager in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt; file:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;...&lt;br /&gt; &amp;lt;!-- &lt;br /&gt; manager responsible for loading user account with assigned roles &lt;br /&gt; --&amp;gt;&lt;br /&gt; &amp;lt;sec:authentication-manager alias="authenticationManager"&amp;gt;&lt;br /&gt;  &amp;lt;sec:authentication-provider&lt;br /&gt;   user-service-ref="userDetailsService" /&amp;gt;&lt;br /&gt; &amp;lt;/sec:authentication-manager&amp;gt;&lt;br /&gt; ...&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Note that we do not explicit define &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;AuthenticationManager&lt;/span&gt;! It is a ready to use object. But &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;AuthenticationManager&lt;/span&gt; has helper service named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;userDetailService&lt;/span&gt; defined in applicationContext.xml file - this service must be written by our own.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4.&lt;/b&gt; Implementation of &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;userDetailService&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;userDetailsService&lt;/span&gt; source code is shown below:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.application.impl;&lt;br /&gt;...&lt;br /&gt;@Service("userDetailsService")&lt;br /&gt;public class UserDetailsServiceImpl implements UserDetailsService {&lt;br /&gt;&lt;br /&gt; private HashMap&lt;string, org.springframework.security.core.userdetails.user=""&gt; users = new HashMap&lt;string, org.springframework.security.core.userdetails.user=""&gt;();&lt;br /&gt; &lt;br /&gt; @Override&lt;br /&gt; public UserDetails loadUserByUsername(String username)&lt;br /&gt;   throws UsernameNotFoundException{&lt;br /&gt;  &lt;br /&gt;  org.springframework.security.core.userdetails.User user = users.get(username);&lt;br /&gt;  &lt;br /&gt;  if (user == null) {&lt;br /&gt;   throw new UsernameNotFoundException("UserAccount for name \""&lt;br /&gt;     + username + "\" not found.");&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  return user;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; @PostConstruct&lt;br /&gt; public void init() {&lt;br /&gt;  &lt;br /&gt;  // sample roles  &lt;br /&gt;  Collection&lt;grantedauthority&gt; adminAuthorities = new ArrayList&lt;grantedauthority&gt;();&lt;br /&gt;  adminAuthorities.add(new GrantedAuthorityImpl("ROLE_ADMIN"));&lt;br /&gt;  &lt;br /&gt;  Collection&lt;grantedauthority&gt; userAuthorities = new ArrayList&lt;grantedauthority&gt;();&lt;br /&gt;  userAuthorities.add(new GrantedAuthorityImpl("ROLE_REGISTERED"));&lt;br /&gt;  &lt;br /&gt;  boolean enabled = true;&lt;br /&gt;  boolean accountNonExpired = true;&lt;br /&gt;  boolean credentialsNonExpired = true;&lt;br /&gt;  boolean accountNonLocked = true;&lt;br /&gt;  &lt;br /&gt;  // sample users with roles set&lt;br /&gt;  users.put("admin", new org.springframework.security.core.userdetails.User("admin", "admin", enabled, accountNonExpired,&lt;br /&gt;    credentialsNonExpired, accountNonLocked, adminAuthorities));&lt;br /&gt;  &lt;br /&gt;  users.put("user", new org.springframework.security.core.userdetails.User("user", "user", enabled, accountNonExpired,&lt;br /&gt;    credentialsNonExpired, accountNonLocked, userAuthorities));&lt;br /&gt; }&lt;br /&gt;}&lt;/grantedauthority&gt;&lt;/grantedauthority&gt;&lt;/grantedauthority&gt;&lt;/grantedauthority&gt;&lt;/string,&gt;&lt;/string,&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;We have here a Spring Security specific objects representing users and roles. In the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;init()&lt;/span&gt; method I created some mocked data two roles representing page administrators and registered users - ROLE_ADMIN and ROLE_REGISTERED. For each role I created a single account: admin (password: admin) for the ROLE_ADMIN and user (password: user) for the ROLE_REGISTERED. That's all - it is time to protect applicartion.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5.&lt;/b&gt; Protecting application.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;5 a)&lt;/b&gt; Scenario 1: protecting business logic. We have to protect invoking a method which allows to see bike details. This method is placed inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; service class. In order to protect the method we have to add an annotation defining roles allowed to execute this method:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.services;&lt;br /&gt;...&lt;br /&gt;public interface BikeDataProvider {&lt;br /&gt; ...&lt;br /&gt; &lt;br /&gt; @RolesAllowed({"ROLE_ADMIN","ROLE_REGISTERED"}) &lt;br /&gt; public abstract Bike getBikeById(Integer id);&lt;br /&gt; &lt;br /&gt; public abstract void add(Bike newBike);&lt;br /&gt;}&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;This simply means that &lt;b&gt;only registered users or admin users&lt;/b&gt; can see bike details.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Why we do not protect the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;add(...)&lt;/span&gt; method? Because we protect the whole page access where this method is executed - of course in addition we can also protect this method by annotating it with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@RolesAllowed({"ROLE_ADMIN"})&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;5 b)&lt;/b&gt; Scenario 2: protecting resource. According to rules of protecting resources defined in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt;, we protect all resources which are located inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/admin&lt;/span&gt; directory. So we have to create a directory &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/admin&lt;/span&gt; under &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/WebContent&lt;/span&gt; directory and move &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;addBike.xhtml&lt;/span&gt; page there. It should look like this:&lt;/span&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/TUMkEymi29I/AAAAAAAAFow/2dQm0nf2-Zc/s1600/JSF2_Features_Spring_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="183" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/TUMkEymi29I/AAAAAAAAFow/2dQm0nf2-Zc/s200/JSF2_Features_Spring_2.PNG" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;span style="color: red;"&gt;Note:&lt;/span&gt;&lt;/b&gt; there is a little trick in the protecting resources like pages in JSF. Spring Security tries to match exact URL address to apply the rule. But in JSF there is a "old URL" issue - after navigtation from page A to page B, URL address in browser still points to page A. In order to make the rule working we have to force the browser to show the current URL instead of old one. It is done by adding a special command into the navigation string returning a page for adding a bike:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;public String showForm(){  &lt;br /&gt; ...  &lt;br /&gt; return "/admin/addBike.xhtml?faces-redirect=true";&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;That's all about Spring Security in our sample application.&lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;How to test it? After deploying application on the server and starting the server, we have to open a browser and type in URL:&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;http://localhost:8080/JSF2FeaturesSpring&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;br /&gt;Then try to display some bike details. When promped for login, enter credentials: user, user and try again. Then try to add a new bike - You should see access denied page. The close the application and clean the browser cache and try the same with the user admin, admin.&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note:&lt;/b&gt; make sure that &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;Java&lt;/a&gt;, &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;Eclipse&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;Tomcat&lt;/a&gt;    are properly installed and configured for running the project    (additional configuration may be required if different directories are    used).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2FeaturesSpring.zip"&gt;here&lt;/a&gt;  (with all required libraries). The sample project is a ready to run  application which contains all described Spring Security issues in this post. You can also download a war file located &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2FeaturesSpring.war"&gt;here&lt;/a&gt; (just copy it inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;webapps&lt;/span&gt; folder in Your Tomcat and start Tomcat with the script &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;startup.bat&lt;/span&gt;)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-3188296209973517971?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3188296209973517971'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3188296209973517971'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2011/01/jsf-2-with-spring-3-protection-with.html' title='JSF 2 with Spring 3 - protection with Spring Security (part 2 of 2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_JXxdCCKdTo0/TUMkEymi29I/AAAAAAAAFow/2dQm0nf2-Zc/s72-c/JSF2_Features_Spring_2.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-5246802640817887316</id><published>2010-12-14T22:45:00.003+01:00</published><updated>2011-03-04T19:02:58.688+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2  with Spring 3 - basics (part 1 of 2)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;a working example from the &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-3-of-3.html"&gt;last article&lt;/a&gt; of a serie introducing new JSF 2.0 features.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to integrate Spring Framework into JSF 2.0 application&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;In the previous three posts I described some interesting JSF 2.0 features and I put them together in the sample application. Those parts were mostly focused on web content, a GUI and its behaviour.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;What about the server side? What about the business logic executed underneath? Do we had a business logic in the sample application mentioned above? Of course we had. Presenting bikes list or a certain bike under some condition -&amp;nbsp; this is business logic resposniblity. Filtering bikes and presenting only those with the discount - this is also business logic. Don't think of it as a naive filtering of presented data - the business logic decides what does it mean that the certain bike has discount - it can be lower price but it can be also more complicated. &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;In the previous example we had a class named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; which represented business logic. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;It was a singleton invoked with the help of static method &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;getInstance()&lt;/span&gt; anywhere where needed.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;When the application starts to grow up, we have more business logic accomplishing some business cases. We need something that will help us to manage the whole business logic in an elegant way - this is where Spring comes to play.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;We will change the BikeDataProvider class into object created and managed by Spring. This object will be called service. A service which serves business logic. Then the service will be used by JSF managed beans. Let's add Spring to our sample web apllication.&lt;/span&gt;&lt;b&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; adding required Spring libraries into the project.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TQfWXfhx6SI/AAAAAAAAFlU/bgXDKk1aFAc/s1600/JSF2_Features_Spring_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/TQfWXfhx6SI/AAAAAAAAFlU/bgXDKk1aFAc/s320/JSF2_Features_Spring_1.PNG" width="273" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; creating Spring's configuration file named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;applicationContext.xml&lt;/span&gt;. The file has to be located inside /WEB-INF directory. This is full content of that file:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;beans xmlns="http://www.springframework.org/schema/beans"&lt;br /&gt; xmlns:context="http://www.springframework.org/schema/context"&lt;br /&gt; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"&lt;br /&gt; xmlns:faces="http://www.springframework.org/schema/faces"&lt;br /&gt; xmlns:int-security="http://www.springframework.org/schema/integration/security"&lt;br /&gt; xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"&lt;br /&gt; xsi:schemaLocation="http://www.springframework.org/schema/integration/security http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd&lt;br /&gt;  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd&lt;br /&gt;  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;context:component-scan base-package="com.jsfsample" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/beans&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; modifying &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; by registering listener resposnible for loading Spring in web application.&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;listener&amp;gt;&lt;br /&gt;  &amp;lt;listener-class&amp;gt;org.springframework.web.context.ContextLoaderListener&amp;lt;/listener-class&amp;gt;&lt;br /&gt; &amp;lt;/listener&amp;gt;&lt;br /&gt; &amp;lt;context-param&amp;gt;&lt;br /&gt;  &amp;lt;param-name&amp;gt;contextConfigLocation&amp;lt;/param-name&amp;gt;&lt;br /&gt;  &amp;lt;param-value&amp;gt;/WEB-INF/applicationContext.xml&amp;lt;/param-value&amp;gt;&lt;br /&gt; &amp;lt;/context-param&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; modifying &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file for allow JSF components use Spring components.&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;application&amp;gt;&lt;br /&gt;... &amp;lt;el-resolver&amp;gt;org.springframework.web.jsf.el.SpringBeanFacesELResolver&amp;lt;/el-resolver&amp;gt;&lt;br /&gt;...&lt;br /&gt; &amp;lt;/application&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; modifying &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; toward Spring managed service.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;First of all we will add a new functionality to the application - possibility to add a new bike to the selected category. We need to create an .xhtml page with the form, then managed bean for that page and at the end a business logic method in class &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; responsible for adding new bike to bikes' list. That's easy part - it will be visible in the attached complete example.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Assuming that we have this new funcitonality, we can modify .java files for Spring integration. First we create an interface:&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.services;&lt;br /&gt;//imports&lt;br /&gt;public interface BikeDataProvider {&lt;br /&gt;&lt;br /&gt; public List&amp;lt;Bike&amp;gt; getBikesByCategory(Integer categoryId,&lt;br /&gt;   boolean onlyWithDiscount);&lt;br /&gt;&lt;br /&gt; public Bike getBikeById(Integer id);&lt;br /&gt;&lt;br /&gt; public void add(Bike newBike); // new function&lt;br /&gt;&lt;br /&gt;}&amp;nbsp;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Then we have to create an implementation named &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProviderImpl.java&lt;/span&gt; (yes, I know that this naming convention is bad)&lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; which will have the source code from previous &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; class. This implementation will have Spring specific annotation defining the service:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.services.impl;&lt;br /&gt;//imports&lt;br /&gt;@Service("bikeDataProvider")&lt;br /&gt;public class BikeDataProviderImpl implements BikeDataProvider {&lt;br /&gt;&lt;br /&gt; private List&amp;lt;Bike&amp;gt; bikes;&lt;br /&gt; private Integer currentBikeId;&lt;br /&gt; &lt;br /&gt; @PostConstruct&lt;br /&gt; private void prepareData(){&lt;br /&gt;  bikes = new ArrayList&amp;lt;Bike&amp;gt;();&lt;br /&gt;  &lt;br /&gt;  // MTB&lt;br /&gt;  Bike mtb1 = new Bike();&lt;br /&gt;  mtb1.setId(1);&lt;br /&gt;  mtb1.setName("Kellys Mobster");&lt;br /&gt;  mtb1.setDescription("Kellys Mobster, lorem ipsut...");&lt;br /&gt;  mtb1.setPrice(6500);&lt;br /&gt;  mtb1.setCategory(1); &lt;br /&gt;  bikes.add(mtb1);&lt;br /&gt;  // other bikes are mocked up the same way&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public List&amp;lt;Bike&amp;gt; getBikesByCategory(Integer categoryId, boolean onlyWithDiscount) {&lt;br /&gt;  // implementation &lt;br /&gt; }&lt;br /&gt; public Bike getBikeById(Integer id){&lt;br /&gt;  // implementation &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void add(Bike newBike) {&lt;br /&gt;  bikes.add(newBike);&lt;br /&gt; }&lt;br /&gt;}&amp;nbsp;&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;The annotation &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@Service("bikeDataProvider")&lt;/span&gt; means that this is Spring managed object (created by Spring) and is visible in the Spring context under the name &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;"bikeDataProvider"&lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;. &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;@PostConstruct&lt;/span&gt; is a little trick here - when object of this class is instantiated by Spring, the method is invoked right after the object is created. I used this for preparing demo data of bikes. The whole &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProviderImpl.java&lt;/span&gt; &lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;class acts as a simple data source for the application - in the future we will use a real database instead.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; modifying JSF managed beans to use Spring service inside.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;We will use registered Spring service inside JSF managed-beans. For example consider &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDetails.java&lt;/span&gt; managed bean. Previously we loaded certain bike in this way:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.managedbeans;&lt;br /&gt;// imports&lt;br /&gt;@ManagedBean(name="bikeDetails")&lt;br /&gt;@RequestScoped&lt;br /&gt;public class BikeDetails {&lt;br /&gt;&lt;br /&gt; private Integer bikeId;&lt;br /&gt; private Bike bike; &lt;br /&gt; &lt;br /&gt; public void loadBike(){&lt;br /&gt;  bike = BikeDataProvider.getInstance().getBikeById(bikeId);&lt;br /&gt; }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/pre&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;Now &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; is not a singleton - it is a Spring service. &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDetails.java&lt;/span&gt; managed bean is changed:&lt;/span&gt;&lt;br /&gt;&lt;pre class="brush: java"&gt;package com.jsfsample.managedbeans;&lt;br /&gt;// imports&lt;br /&gt;@ManagedBean(name="bikeDetails")&lt;br /&gt;@RequestScoped&lt;br /&gt;public class BikeDetails {&lt;br /&gt;&lt;br /&gt; private Integer bikeId;&lt;br /&gt; private Bike bike; &lt;br /&gt; &lt;br /&gt; @ManagedProperty("#{bikeDataProvider}")&lt;br /&gt; private BikeDataProvider bikeDataProvider; // injected Spring service&lt;br /&gt;&lt;br /&gt; public void loadBike(){&lt;br /&gt;  bike = bikeDataProvider.getBikeById(bikeId);&lt;br /&gt; }&lt;br /&gt;        ...&lt;br /&gt;}&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We used the name of registered service ("bikeDataProvider") to inject it into JSF managed bean (please note that we used here an interface as an instance variable, Spring injects its concrete implementation). This injection is possible thanks to modifications from step 4.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;br /&gt;That's all. Other JSF managed beans responsible for displaying bikes' lists or adding a bike use mentioned Spring service in the same way.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;span style="font-family: Verdana,sans-serif;"&gt;The  complete working  example of mentioned application which will contain  all described issues, will be available in the last (second) article  of this serie.&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-5246802640817887316?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5246802640817887316'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5246802640817887316'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/12/jsf-2-with-spring-3-basics-part-1-of-2.html' title='JSF 2  with Spring 3 - basics (part 1 of 2)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/TQfWXfhx6SI/AAAAAAAAFlU/bgXDKk1aFAc/s72-c/JSF2_Features_Spring_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-7150228826935073417</id><published>2010-10-21T21:19:00.004+02:00</published><updated>2011-03-04T19:13:46.236+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2.0 - New features (part 3 of 3)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;working example from &lt;span id="goog_155504699"&gt;&lt;/span&gt;&lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-2-of-3.html"&gt;previous post&lt;span id="goog_155504700"&gt;&lt;/span&gt;&lt;/a&gt; as a basis&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;support for Ajax&lt;/li&gt;&lt;li&gt;support for GET and creating bookmarkable URLs&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;This is the third post about new features that could be found in JSF 2.0 comparing to JSF 1.x. In the &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;previous post&lt;/a&gt;  (part 1), I described templating mechanism and simplified navigation  model. In the &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-2-of-3.html"&gt;second post&lt;/a&gt;  (part 2), I described resource loading mechanism. In this post I would like to focus on the built in Ajax support and on possibility to create bookmarkable URLs.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;b&gt;Ajax support.&lt;/b&gt;&lt;br /&gt;Ajax is a very wide issue. I would like to show only one of the simplest example - refreshing part of the page after some action. The purpose of this example is to show that using simple Ajax does not require any additional configuration or libraries.&lt;br /&gt;In the sample application I have a page &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt;. This page shows the bikes list in selected category (category is chosen in main menu on left). Some of the bikes have discount price. I have two buttons (above the displayed bikes list) acting as bike list filters. Pressing those buttons causes filtering the list and reloading it on the view. For example: if I press a button "Discount bikes" (in red box), only one bike will be shown on a list (Magnum bike with doscount price, marked by red box). If I press "All bikes" - all bikes from the category will be shown:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TL8-J36SZEI/AAAAAAAAFaw/X2IbUDQ_ILE/s1600/JSF2_Features_10.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="263" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/TL8-J36SZEI/AAAAAAAAFaw/X2IbUDQ_ILE/s400/JSF2_Features_10.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The idea is to reload the bike list after pressing the button, without reloading the whole page. This is done by Ajax call which is "hooked" to the buttons:&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;ui:define name="content"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;h:commandButton actionListener="#{bikesListBean.showAllBikes}" value="#{msg['bikes.filter.all']}"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;f:ajax render="bikesTable"&amp;nbsp; /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/h:commandButton&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;h:commandButton actionListener="#{bikesListBean.showDiscountBikes}" value="#{msg['bikes.filter.discount']}"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;f:ajax render="bikesTable"&amp;nbsp; /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/h:commandButton&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;h:dataTable id="bikesTable" value="#{bikesListBean.bikesList}" var="b"&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;/ui:define&amp;gt;&lt;br /&gt;&lt;/pre&gt;Ajax call defined by &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;f:ajax render="bikesTable" /&amp;gt;&lt;/span&gt; causes reloading the corresponding part of thw page with &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;id=bikesTable&lt;/span&gt;. In our case this is the list&amp;nbsp;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; &amp;lt;h:dataTable id="bikesTable" ... &amp;gt;&lt;/span&gt; which shows all or filtered bikes. Simple - isn't it?&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Creating bookmarkable URLs (GET support).&lt;/b&gt;&lt;br /&gt;Why do I need GET? Consider this situation: I found interesting bike in the Bike Shop. I would like to get the URL and send it to someone in order to show what I found. Quite normal thing isn't it? Unfortunately not possible in JSF 1.x because of lack of GET support. JSF 1.x is POST-centric, so passing parameters in the URL wiht GET was not possible - so I have no way to save the URL.&lt;br /&gt;JSF 2.0 provided GET support by introducing so-called "view parameters". A page which uses a special component for view parameters, is able to catch incoming view parameters (they are in the URL) and update page model (i.e. fields in managed bean) with their values. Moreover standard conversion and validation of the incoming parameters is possible - just like for the POST data.&lt;br /&gt;&lt;br /&gt;How it work in real example? Let's go back to our sample application. We have a page named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; which shows all bikes. We also have a page named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt; which shows the detail of selected bike. I would like to see the particular bike and take the URL with it and send it to someone. So the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt; page will contain view parameter component:&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;f:metadata&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;f:viewParam name="bikeId" value="#{bikeDetails.bikeId}"/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;f:event type="preRenderView" listener="#{bikeDetails.loadBike}"/&amp;gt;&lt;br /&gt;&amp;lt;/f:metadata&amp;gt;&lt;/pre&gt;Page expects the URL parameter named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeId&lt;/span&gt;, then value of this parameter is copied into the model to the field &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;#{bikeDetails.bikeId}&lt;/span&gt;. For now skip &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;f:event .../&amp;gt;&lt;/span&gt; component - I will back to it at the end.&lt;br /&gt;Where those parameters are created and passed to the URL? JSF 2.0 provides two components allowing to add GET parameters to the target URL: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:button /&amp;gt;&lt;/span&gt; and&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; &amp;lt;h:link /&amp;gt;&lt;/span&gt;(they work similar to the POST-centric &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:commandButton /&amp;gt;&lt;/span&gt; and&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; &amp;lt;h:commandLink&lt;/span&gt;). In our example &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; page uses &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:button /&amp;gt; &lt;/span&gt;for each presented bike to construct the button which navigates us to &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml &lt;/span&gt;and sets bikeId as a parameter:&lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;h:dataTable id="bikesTable" value="#{bikesListBean.bikesList}" var="b"&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;h:button outcome="bikeDetails" value="#{msg['bikes.list.seebike']}"&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;f:param name="bikeId" value="#{b.id}"/&amp;gt;&lt;br /&gt;&amp;lt;/h:button&amp;gt;&lt;br /&gt;...&lt;br /&gt;&amp;lt;/h:dataTable&amp;gt;&lt;/pre&gt;Notice &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;outcome&lt;/span&gt; attribute and its value - it points to the target page where view parameters component is used. &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;Simplified navigation&lt;/a&gt; is used here. Generated URL looks like this:&lt;br /&gt;&lt;br /&gt;&lt;b style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;http://localhost:8080/JSF2Features/faces/bikeDetails.xhtml?bikeId=5&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;We have bokkmarkable URL which can be saved and sent to other people and used later. &lt;br /&gt;&lt;br /&gt;Solution with view parameters on &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt; uses another new feature in JSF 2.0: system events. We register a special listener using the tag &lt;br /&gt;&lt;pre class="brush: xml"&gt;&amp;lt;f:event type="preRenderView" listener="#{bikeDetails.loadBike}"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;The listener is executed before the view is rendered. What is the benefit? When a view is reached, view parameter is copied into the managed bean and listener is executed and &lt;b&gt;after that&lt;/b&gt; the whole view (page) is rendered. Our listener uses passed &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeId&lt;/span&gt; to load the selected bike from repository like database. When the page is rendered, the proper bike is loaded from repository and ready to be displayed - we do not have to wait for loading the data.&lt;br /&gt;&lt;br /&gt;That's all. We are ready to test the application. After deploying application on the server and starting the server, we have to open a browser and type in URL:&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;http://localhost:8080/JSF2Features&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color: red;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red;"&gt;Download source files:&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Note:&lt;/b&gt; make sure that &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;Java&lt;/a&gt;, &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;Eclipse&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;Tomcat&lt;/a&gt;   are properly installed and configured for running the project   (additional configuration may be required if different directories are   used).&lt;br /&gt;&lt;br /&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2Features.zip"&gt;here&lt;/a&gt; (with all required libraries). The sample project is a ready to run application which contains all described JSF 2.0 features in &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;first&lt;/a&gt;, &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-2-of-3.html"&gt;second&lt;/a&gt; and this (third) post. You can also download a war file located &lt;a href="https://sites.google.com/site/technologyforhuman/JSF2Features.war"&gt;here&lt;/a&gt; (just copy it inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;webapps&lt;/span&gt; folder in Your Tomcat and start Tomcat with the script &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;startup.bat&lt;/span&gt;)&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-7150228826935073417?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7150228826935073417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7150228826935073417'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-3-of-3.html' title='JSF 2.0 - New features (part 3 of 3)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/TL8-J36SZEI/AAAAAAAAFaw/X2IbUDQ_ILE/s72-c/JSF2_Features_10.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-3930638103596680922</id><published>2010-10-20T20:28:00.003+02:00</published><updated>2011-03-04T18:50:42.358+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2.0 - New features (part 2 of 3)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;working example from &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;previous post&lt;/a&gt; as a basis&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;resource loading&lt;/li&gt;&lt;/ul&gt;This is the second post about new features that could be found in JSF 2.0 comparing to JSF 1.x. In the &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;previous post&lt;/a&gt; (part 1), I described templating mechanism and simplified navigation model. In this post I would like to focus on the improved resource loading and its capabilities in JSF 2.0.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Resource loading.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;What are resources in terms of a web application? It can be images files, JavaScript script files or CSS files used on web pages in the application - so some external files accessible by special tags in the page source. In the JSF application we also name as resources message bundle files. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Just as a short reminder for message bundles:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;1.&lt;/b&gt; We create message bundle files for each language we would like to support. Then we add some lines into the configuration in faces-config.xml where we define what language will be supported (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;locale-config&amp;gt;&lt;/span&gt; section) and we define EL access object (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;var&amp;gt;msg&amp;lt;/var&amp;gt;&lt;/span&gt;) for the created message bundle files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/TLtL1M2CAHI/AAAAAAAAFaY/cnn6WHHTPaY/s1600/JSF2_Features_4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="221" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/TLtL1M2CAHI/AAAAAAAAFaY/cnn6WHHTPaY/s400/JSF2_Features_4.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;2.&amp;nbsp;&lt;/b&gt; We use message from the bundle files by calling defined EL accessor in the page source, for example:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:outputText value="#{msg['top.name']}" /&amp;gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This approach gives us the most important benefit: localization of the application. Based on the browser's language, suitable message bundle file is used (EN or PL in above example).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;So far so good - nothing new is here when comparing to JSF 1.x. But what about other resources like JS, CSS or image files? JSF 2.0 can handle those resources in a more intelligent way than before - a special &lt;a href="https://javaserverfaces.dev.java.net/nonav/docs/2.0/javadocs/javax/faces/application/ResourceHandler.html"&gt;ResourceHandler&lt;/a&gt; is used for load resources from some predefined locations. According to the documentation resources are expected to be placed in:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WebRoot/resources/&amp;lt;resourceIdentifier&amp;gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;WebRoot is a root of web application - in the Eclipse generated web projects it is the directory named "WebContent". Part &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;resourceIdentifier&lt;/span&gt; have this structure:&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;[localePrefix/][libraryName/][libraryVersion/]resourceName[/resourceVersion]&amp;nbsp;&lt;/span&gt; &lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;resourceIdentifier&lt;/span&gt; defines the subdirectory structure inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WebRoot/resources/directory&lt;/span&gt;. And the most important part: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;localePrefix&lt;/span&gt; means that&lt;b&gt; resources can be localized based on the browser's language&lt;/b&gt;, like message bundles. Part &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;libraryName&lt;/span&gt; can be use to group resources by their type in different directories, for example "css", "images", "scripts".&lt;br /&gt;&lt;br /&gt;Let' see how it work in a sample application. As I wrote in previous &lt;a href="http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html"&gt;post&lt;/a&gt;, we used &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;shopTemplate.xhtml&lt;/span&gt; file as a template page for all pages in application. The second purpose of this file (next to defining reusable parts) is to separate the structure from the presentation - template page will include all CSS files and common images files. &lt;b&gt;We will use new ResourceHandler in order to load some CSS and images suitable for current browser language:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;images: we have two pictures (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bike_logo.jpg&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;flag.gif&lt;/span&gt;) in sample application visible in the header - they will change depending on current browser language&lt;/li&gt;&lt;li&gt;CSS: depending on current browser language, different CSS will be loaded. The only difference between loaded CSS's is footer color (just to show that CSS is really changed) &lt;/li&gt;&lt;/ul&gt;According to the documentation we have to create directory structure for mentioned resources and put different resource there:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/TL8uCinuOfI/AAAAAAAAFac/GMUKsiBp1Co/s1600/JSF2_Features_5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/TL8uCinuOfI/AAAAAAAAFac/GMUKsiBp1Co/s400/JSF2_Features_5.PNG" width="218" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;How to load such resources on the page? First we have to perform additional configuration to enable loading resources using proper &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; localePrefix&lt;/span&gt; ("pl" and "en" on the screenshot above). We have to create a special localized entry named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;javax.faces.resource.localePrefix&lt;/span&gt; in a resource-bundle file. This file &lt;b&gt;must be configured as message-bundle in faces-config.xml&lt;/b&gt; - we &lt;b&gt;can not use resource bundles&lt;/b&gt; (used for localized messages as shown above) to put entry there:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TL8ugPVnbiI/AAAAAAAAFag/WTYQvmmyL-M/s1600/JSF2_Features_6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="240" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/TL8ugPVnbiI/AAAAAAAAFag/WTYQvmmyL-M/s400/JSF2_Features_6.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now we can use the resources on the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;shopTemplate.xhtml&lt;/span&gt; page:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/TL8umatgr6I/AAAAAAAAFak/GEZ3tqgR8ns/s1600/JSF2_Features_7.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="161" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/TL8umatgr6I/AAAAAAAAFak/GEZ3tqgR8ns/s400/JSF2_Features_7.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Please note that we use here a new JSF 2.0 tag:&lt;br /&gt;&lt;pre class="brush: xml" style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:outputStylesheet library="css" name="layout.css" /&amp;gt;&lt;/pre&gt;Attributes &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;library&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;name&lt;/span&gt; correspond to the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;libraryName&lt;/span&gt; and  &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;resourceName &lt;/span&gt;from &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;resourceIdentifier&amp;gt;&lt;/span&gt; respectively.&lt;br /&gt;&lt;br /&gt;If we want to load&amp;nbsp; JS scripts we have to use additional JSF 2.0 tag: &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:outputScript ... /&amp;gt;&lt;/span&gt; wich has additional attribute named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;target&lt;/span&gt; - specifying where to render script link.&lt;br /&gt;&lt;br /&gt;Loading images with standard tag &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;h:graphicImage ... /&amp;gt;&lt;/span&gt; is possible in two ways:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;using attributes library and name correspond to the libraryName and resourceName from &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;resourceIdentifier&amp;gt;&lt;/span&gt; respectively (like for CSS)&lt;/li&gt;&lt;li&gt;using special EL expression &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;"#{resource['images:bike_logo.jpg']}"&lt;/span&gt; (wartch out for letters: EL has resource word but in the WebContent there is a resource&lt;b&gt;s&lt;/b&gt; directory!)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;Note about testing:&lt;/b&gt; in order to test if images and CSS (footer color) changes when browser language is changed, I recommend clean the browser cache and restart it completely before testing (sometimes image cache prevents from changing the image). The test result should be:&lt;br /&gt;&lt;br /&gt;PL version:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/TL8z6Y_Rh9I/AAAAAAAAFao/tHYnAU2NFAw/s1600/JSF2_Features_8.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="266" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/TL8z6Y_Rh9I/AAAAAAAAFao/tHYnAU2NFAw/s400/JSF2_Features_8.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;EN version:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/TL80APFtFHI/AAAAAAAAFas/mQpjLCIPuxg/s1600/JSF2_Features_9.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/TL80APFtFHI/AAAAAAAAFas/mQpjLCIPuxg/s400/JSF2_Features_9.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The complete working  example of mentioned application which will contain all described  features, will be available in the last (third) article of this serie.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-3930638103596680922?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3930638103596680922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3930638103596680922'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/10/jsf-20-new-features-part-2-of-3.html' title='JSF 2.0 - New features (part 2 of 3)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_JXxdCCKdTo0/TLtL1M2CAHI/AAAAAAAAFaY/cnn6WHHTPaY/s72-c/JSF2_Features_4.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-1654781030995322257</id><published>2010-10-17T20:39:00.007+02:00</published><updated>2011-03-04T18:48:02.244+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2.0 - New features (part 1 of 3)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;working "Hello World" example in JSF 2.0 as a basis (from &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-20-hello-world-in-eclipse-with.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;templating with Facelets&lt;/li&gt;&lt;li&gt;simplified page navigation&lt;/li&gt;&lt;/ul&gt;In the previous &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-20-hello-world-in-eclipse-with.html"&gt;post&lt;/a&gt; I showed how to create classic "Hello World" application in JSF 2.0. The example was created in the simplest possible way. I focused on generating and setting up working and ready to use project in Eclipse. Created application did not differ much from similar "Hello World" applications in JSF 1.2, because I did not use JSF 2.0 built-in featues. Now it is a time to show what new features are in JSF 2.0 and how they can improve development web applications.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Sample application: &lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In order to go higher than "Hello World"  level we will create fully  functional mini application which will serve  as an example for mentioned  JSF 2.0 features.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's assume that  we are creating a web application for bicycle shop. Our application  should present a list of available bikes. Bikes will be divided because  of their type like MTB, Trekking and Cross bikes. In addition bike  list will have a filter allowing to display only bikes with a special  discount price. User should be able to display detailed information  about selected bike from the presented list. We will use those pages in application:&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt; - start page presenting information about bike shop&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; - page presenting bikes of given type&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt; - page presenting detailed information about bike displayed on &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Under the hood we will use those classes:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; - singleton, acts as service which belongs to business logic. Responsible for loading bikes of certain type and loading single bike with its details. For simplicity all bikes instances are created and stored inside that class.&lt;/li&gt;&lt;li&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Bike.java&lt;/span&gt;&lt;i&gt; - &lt;/i&gt;a class from the model representing single bike instance. A list of bike instances is created and used inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt;.&lt;/li&gt;&lt;li&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDetails.java, BikesList.java&lt;/span&gt; - managed beans used for &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt;&lt;i&gt; &lt;/i&gt;and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; respectively. They call &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;BikeDataProvider.java&lt;/span&gt; for loading bikes list or single bike. &lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Web application will have popular and standard layout - header on top, menu on left, content on righ, footer on bottom. Header will have shop's logo and name, menu will have bike types listed, content will have some information about the shop and will display bikes list for given type, footer will be empty with some background color. The whole application will look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt;:&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TLXbOUWCq6I/AAAAAAAAFaI/3sDj8XEknBI/s1600/JSF2_Features_1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="255" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/TLXbOUWCq6I/AAAAAAAAFaI/3sDj8XEknBI/s400/JSF2_Features_1.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt;:&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/TLXdJUkYCrI/AAAAAAAAFaM/iAo7JHhhZj0/s1600/JSF2_Features_2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="262" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/TLXdJUkYCrI/AAAAAAAAFaM/iAo7JHhhZj0/s400/JSF2_Features_2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesDetails.xhtml&lt;/span&gt;:&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/TLXdPtpaF7I/AAAAAAAAFaQ/z806uO7-iMM/s1600/JSF2_Features_3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="262" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/TLXdPtpaF7I/AAAAAAAAFaQ/z806uO7-iMM/s400/JSF2_Features_3.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Facelets - templating.&lt;/b&gt; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;One of the key feature of Facelets is ability to create page templates. Have a look at our sample applications screenshot above - all of them have common content like header, left menu and footer. If we had JSF application based on JSP pages without using Facelets, those elements would be included separately into source code of each web page. Imagine small change in the header - it may become a maintenance nightmare because we have to change source code of all pages where header is visible. With the Facelets is it possible to extract common content and put it into &lt;b&gt;one page template&lt;/b&gt;. The template has special sections where variable content will be displayed - pages which use the template "injects" to those sections their specific content.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;For our application we will create a template page named &lt;b style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;shopTemplate.xhtml&lt;/b&gt; which will act as a template for three pages visible above (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml, bikesList.xhtml, bikeDetails.xhtml&lt;/span&gt;). The whole page layout common for all pages will be defined inside the single template page. This gives us another advantage - we can follow one of the best practises in designing web pages here - separate the structure from the presentation. The template will contain only the pages structure while the whole presentation will be placed in separate CSS file used by template. The source code for the template will look like this:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt; &lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&lt;br /&gt;      xmlns:ui="http://java.sun.com/jsf/facelets"&lt;br /&gt;      xmlns:h="http://java.sun.com/jsf/html"&lt;br /&gt;      xmlns:f="http://java.sun.com/jsf/core"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;h:head&amp;gt;&lt;br /&gt;        &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;Bike Shop 2.0&amp;lt;/title&amp;gt;&lt;br /&gt;    &amp;lt;/h:head&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;h:body&amp;gt;&lt;br /&gt;        &amp;lt;div id="container"&amp;gt;&lt;br /&gt;            &amp;lt;div id="top"&amp;gt;&lt;br /&gt;                &amp;lt;!-- logo and name goes here --&amp;gt;&lt;br /&gt;            &amp;lt;/div&amp;gt;&lt;br /&gt;            &amp;lt;div id="leftnav"&amp;gt;&lt;br /&gt;                &amp;lt;h:form&amp;gt;&lt;br /&gt;                    &amp;lt;!-- links goes here --&amp;gt;&lt;br /&gt;                &amp;lt;/h:form&amp;gt;&lt;br /&gt;            &amp;lt;/div&amp;gt;&lt;br /&gt;            &amp;lt;div id="content"&amp;gt;&lt;br /&gt;                &amp;lt;ui:insert name="content" /&amp;gt;&lt;br /&gt;            &amp;lt;/div&amp;gt;&lt;br /&gt;            &amp;lt;div id="footer"&amp;gt;&lt;br /&gt;                ####&lt;br /&gt;            &amp;lt;/div&amp;gt;&lt;br /&gt;        &amp;lt;/div&amp;gt;&lt;br /&gt;     &amp;lt;/h:body&amp;gt;   &lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note the element &lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:insert name="content" /&amp;gt;&lt;/span&gt; &lt;/b&gt;inside the div named "content".&lt;b&gt; &lt;/b&gt;It represents variable content which will be displayed in this place. Pages &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml, &lt;/span&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt; will "inject" here their content using special syntax. Let's have a look how &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt; page display its content using the template. Here is the code for &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt;:&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;?xml version='1.0' encoding='UTF-8' ?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&lt;br /&gt;      xmlns:ui="http://java.sun.com/jsf/facelets"&lt;br /&gt;      xmlns:h="http://java.sun.com/jsf/html"&lt;br /&gt;      xmlns:f="http://java.sun.com/jsf/core"&amp;gt;&lt;br /&gt;  &amp;lt;ui:composition template="shopTemplate.xhtml"&amp;gt;&lt;br /&gt;       &lt;br /&gt;        &amp;lt;ui:define name="content"&amp;gt;&lt;br /&gt;         Lorem ipsum dolor sit amet...&lt;br /&gt;        &amp;lt;/ui:define&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/ui:composition&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;First note that &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt; page have no &amp;lt;head&amp;gt; or &amp;lt;body&amp;gt; tags - they are defined in the template. A special element &lt;b&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:composition template="shopTemplate.xhtml"&amp;gt;&lt;/span&gt; &lt;/b&gt;tells the page to use the mentioned template.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As I wrote, the template has a special section for inserting the variable content (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:insert name="content" /&amp;gt;&lt;/span&gt;). The page  &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesShop.xhtml&lt;/span&gt;&lt;i&gt; &lt;/i&gt;defines content to be placed into that section by using the tag &lt;b style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:define name="content"&amp;gt; ... &amp;lt;/ui:define&amp;gt;&lt;/b&gt;&amp;nbsp; - note that attribute &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;name="content"&lt;/span&gt; is the same for&amp;nbsp; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:insert/&amp;gt;&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:define /&amp;gt;&lt;/span&gt;. Pages &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikeDetails.xhtml&lt;/span&gt;&lt;i&gt; &lt;/i&gt;use the same mechanism (they have the same &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;lt;ui:define /&amp;gt;&lt;/span&gt; tag in their source).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's all about templates. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Simplified page navigation.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Every page navigation in JSF 1.x required a proper entry in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file. It was something like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: xml" style="font-family: Verdana,sans-serif;"&gt;&amp;lt;navigation-rule&amp;gt;&lt;br /&gt;     &amp;lt;description&amp;gt;Welcome page to message page&amp;lt;/description&amp;gt;&lt;br /&gt;     &amp;lt;from-view-id&amp;gt;/index.jsp&amp;lt;/from-view-id&amp;gt;&lt;br /&gt;     &amp;lt;navigation-case&amp;gt;&lt;br /&gt;       &amp;lt;from-outcome&amp;gt;helloMessage&amp;lt;/from-outcome&amp;gt;&lt;br /&gt;       &amp;lt;to-view-id&amp;gt;/message.jsp&amp;lt;/to-view-id&amp;gt;&lt;br /&gt;    &amp;lt;/navigation-case&amp;gt;&lt;br /&gt;   &amp;lt;/navigation-rule&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;JSF 2.0 provides a simplified navigation model - we &lt;b&gt;do not need any entries&lt;/b&gt; (navigation rules) in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file. Why?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Suppose we have a method used for navigation which returns some string value. This string value (known as &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;outcome&lt;/span&gt;) is taken by a navigation handler and the handler checks for navigation rules in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; which have defined the same &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;from-outcome&lt;/span&gt; value. When the rule is found, it is applied and a proper navigation is done. This is how it worked in JSF 1.x and how it works in JSF 2.0. But JSF 2.0 navigation handler does additional operation here: if no matching &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;from-outcome&lt;/span&gt; value is found in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; (in other words: there is no navigation rule to apply), handler checks also existing pages names (view identifiers). If existing page name matches returned &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;outcome&lt;/span&gt; value, the navigation is done to that page.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;For example if we have a navigation method in some backing bean:&lt;/div&gt;&lt;pre class="brush: java" style="font-family: Verdana,sans-serif;"&gt;public String getBikes(){&lt;br /&gt;   bikesList = ... // load some bikes&lt;br /&gt;   return "bikesList";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;and there is a page named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;bikesList.xhtml&lt;/span&gt;, invoking this method will cause the navigation to that page - without defining proper navigation rule in &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The complete working example of mentioned application which will contain all described features, will be available in the last (third) article of this serie.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-1654781030995322257?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1654781030995322257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1654781030995322257'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/10/jsf-20-new-featuers-part-1-of-3.html' title='JSF 2.0 - New features (part 1 of 3)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/TLXbOUWCq6I/AAAAAAAAFaI/3sDj8XEknBI/s72-c/JSF2_Features_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2475956165197252916</id><published>2010-09-15T19:39:00.009+02:00</published><updated>2011-07-26T21:47:25.742+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2.0 - "Hello World" in Eclipse (with *.xhtml pages)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Tomcat for the Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to create "Hello World" application in JSF 2.0 using Eclipse&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;Note 1: &lt;/b&gt;The following post and example show classic JSF 2.0   application with a view technology as .xhtml pages. I do not use any   additional libraries and extensions for the standard JSF libraries. I don't use (for the time being) templates. JSF  implementation used comes from MyFaces.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; I use standard capabilities of IDE platform to generate   the project, without those thousands automated plugins which do   everything for the user. Sometimes configuration and usage of a plugin   is a "pain in the ..." - in my opinion it is worth to know how to deal   with a standard set of tools, and after that there is always a time to   faciliate our life ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In this post I will show how to create sample JSF 2.0 application using Eclipse. It will be similar application like in the &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;post&lt;/a&gt; about creating sample JSF 1.2 application. But there will be some small differences, especially during generating the project and adding JSF capabilities to it. Let's do it.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 1:&lt;/span&gt; create new dynamic web project for the Tomcat. It is available in "web" menu section under option "File-&amp;gt;New-&amp;gt;Project":&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6EjzR3yuiI/AAAAAAAAEf0/kImZDPTX1Ic/s1600-h/JSF2_Eclipse_1.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5449676387972725282" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6EjzR3yuiI/AAAAAAAAEf0/kImZDPTX1Ic/s320/JSF2_Eclipse_1.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" to go further and set some basic project's properties:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6EkLjE9UaI/AAAAAAAAEf8/2J6sWWuukbI/s1600-h/JSF2_Eclipse_2.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5449676804908208546" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6EkLjE9UaI/AAAAAAAAEf8/2J6sWWuukbI/s320/JSF2_Eclipse_2.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6ElHEZl5HI/AAAAAAAAEgE/e_akE4L60eQ/s1600-h/JSF2_Eclipse_3.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5449677827465405554" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6ElHEZl5HI/AAAAAAAAEgE/e_akE4L60eQ/s320/JSF2_Eclipse_3.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Step 2:&lt;/span&gt; adding JSF capabilities for the generated project (JSF and JSTL libraries).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;This step is the same as step 2 in previous &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;JSF 1.2 example under Eclipse&lt;/a&gt;. The main difference prior to version 1.2&lt;b&gt; &lt;/b&gt;is that JSTL libraries are not necessary, unless application uses *.jsp pages with some standard JSP tags, and we have to choose JSF 2.0 MyFaces. JSF 2.0 support for Project Facets was added in Eclipse Helios and above. For previous Eclipse version (like Galileo) only JSF 1.2 was supported and configuration for JSF 2.0 needs to be done in alternative way (see below).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;&lt;b&gt;Note:&lt;/b&gt; this configuration &lt;b&gt;is recommended&lt;/b&gt; in order to let the Code Assist for *.xhtml pages work properly. Code Assist allows automatically complete JSF tags when typying by pressing CTRL + Space. Unfortunately &lt;b&gt;access to beans and their methods and fields from .xhtml page is not working&lt;/b&gt; (see bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=323709) unless beans are directly declared in faces-config.xml instead of annotations.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;-------------------------------------------- &lt;/span&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;Steps 2 in an alternative way:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We do not have to download requires .jar files for JSF, make user libraries from them in Eclipse and add those libraries to the generated project with "Project Facets" screen. The alternative way is to download all required .jar files and copy them into the generated "WebContent\WEB-INF\lib" directory. After that just refresh the whole project by pressing "F5" on the project's root and all libraries should appear in the section named "Web App Libraries" in the project's structure.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: red;"&gt;&lt;b&gt;Note:&lt;/b&gt; this configuration (despite the fact it is faster) is &lt;b&gt;not recommended&lt;/b&gt;, because of Code Assist which does not completely. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="color: black;"&gt;&lt;b&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; the project structure is ready. Creating sample application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This will be the same application as for version 1.2 with some differences coming from JSF 2.0: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- pages extenstion will be &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.xhtml&lt;/span&gt; instead of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.jsp&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- we use annotations in backing beans&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- there will be no &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file (now) &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Everything should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/TJEDMF3peKI/AAAAAAAAFRs/Icr94q8io-g/s1600/JSF2_Eclipse_project.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/TJEDMF3peKI/AAAAAAAAFRs/Icr94q8io-g/s320/JSF2_Eclipse_project.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;File &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;web.xml&lt;/span&gt; has to be changed like shown on screenshot below:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/TJEDuUOHM6I/AAAAAAAAFR0/p0ICQ_wSf6Y/s1600/JSF2_Eclipse_webxml.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/TJEDuUOHM6I/AAAAAAAAFR0/p0ICQ_wSf6Y/s320/JSF2_Eclipse_webxml.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; deployment and running.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This step is similar to steps 6 and 7 from &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;JSF 1.2 version&lt;/a&gt;. After deploying application on the server and starting the server, we have to open a browser and type in URL:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;http://localhost:8080/FirstJSF2&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's all. We should have working&lt;b&gt; &lt;/b&gt;JSF 2.0 application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note:&lt;/b&gt; make sure that &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;Java&lt;/a&gt;, &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;Eclipse&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;Tomcat&lt;/a&gt;  are properly installed and configured for running the project  (additional configuration may be required if different directories are  used).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/site/technologyforhuman/FirstJSF2.zip"&gt;here&lt;/a&gt; (with all required libraries). You can also download a war file located &lt;a href="https://sites.google.com/site/technologyforhuman/FirstJSF2.war"&gt;here&lt;/a&gt; (just copy it inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;webapps&lt;/span&gt; folder in Your Tomcat and start Tomcat with the script &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;startup.bat&lt;/span&gt;)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2475956165197252916?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2475956165197252916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2475956165197252916'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/09/jsf-20-hello-world-in-eclipse-with.html' title='JSF 2.0 - &quot;Hello World&quot; in Eclipse (with *.xhtml pages)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/S6EjzR3yuiI/AAAAAAAAEf0/kImZDPTX1Ic/s72-c/JSF2_Eclipse_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-1025429739839363585</id><published>2010-09-15T18:26:00.004+02:00</published><updated>2011-03-04T19:18:09.037+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 2.0 - "Hello World" in NetBeans (with *.xhtml pages)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Tomcat for the NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to create "Hello World" application in JSF 2.0 using NetBeans&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;Note 1: &lt;/b&gt;The following post and example show classic JSF 2.0  application with a view technology as .xhtml pages. I do not use any  additional libraries and extensions for the standard JSF libraries. JSF implementation used comes from Sun.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; I use standard capabilities of IDE platform to generate  the project, without those thousands automated plugins which do  everything for the user. Sometimes configuration and usage of a plugin  is a "pain in the ..." - in my opinion it is worth to know how to deal  with a standard set of tools, and after that there is always a time to  faciliate our life ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In a previous &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-netbeans-with-jsp.html"&gt;post&lt;/a&gt; I showed how to create a sample JSF 1.2 application using NetBeans. Creating JSF 2.0 application under NetBeans is almost the same as creating JSF 1.2 application - the main difference is just selecting JSF 2.0 version instead of 1.2.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I will show how to create JSF 2.0 sample application similar to JSF 1.2 application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 1:&lt;/span&gt; creating and configuring web application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t6xo66efI/AAAAAAAAEiI/27atyIHWZR8/s1600/JSF2_NetBeans_1.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452586767078816242" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t6xo66efI/AAAAAAAAEiI/27atyIHWZR8/s320/JSF2_NetBeans_1.PNG" style="cursor: pointer; display: block; height: 225px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we have to define project name and its location:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6t7C6ZOWQI/AAAAAAAAEiQ/Q0x-kG2xdrE/s1600/JSF2_NetBeans_2.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452587063827126530" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6t7C6ZOWQI/AAAAAAAAEiQ/Q0x-kG2xdrE/s320/JSF2_NetBeans_2.PNG" style="display: block; height: 225px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After pressing "Next" we have to configure target runtime and context name:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6t7KNPa_tI/AAAAAAAAEiY/8UI2BPd6-qk/s1600/JSF2_NetBeans_3.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452587189145370322" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6t7KNPa_tI/AAAAAAAAEiY/8UI2BPd6-qk/s320/JSF2_NetBeans_3.PNG" style="display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" in order to go to the JSF settings screen. Here we have to select JSF 2.0 version:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t7W-qd1vI/AAAAAAAAEig/6fc4wXFwClY/s1600/JSF2_NetBeans_4.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452587408570570482" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t7W-qd1vI/AAAAAAAAEig/6fc4wXFwClY/s320/JSF2_NetBeans_4.PNG" style="cursor: pointer; display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 2:&lt;/span&gt; project is configured. This is what NetBeans generated for us:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t7o3F97RI/AAAAAAAAEio/7dnoWBIHIuM/s1600/JSF2_NetBeans_5.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452587715776081170" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t7o3F97RI/AAAAAAAAEio/7dnoWBIHIuM/s320/JSF2_NetBeans_5.PNG" style="cursor: pointer; display: block; height: 195px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Just like for &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-netbeans-with-jsp.html"&gt;version 1.2&lt;/a&gt;, project contains all requires libraries and is ready to be deployed on the server. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 3:&lt;/span&gt; creating application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This will be the same application as for version 1.2 with some differences coming from JSF 2.0: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- pages extenstion will be &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.xhtml&lt;/span&gt; instead of &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;.jsp&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- we use annotations in backing beans&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;- there will be no &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file (now)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Everything should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6t8_9kYpkI/AAAAAAAAEiw/uH0wKz3D74o/s1600/JSF2_NetBeans_6.PNG"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452589212162893378" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6t8_9kYpkI/AAAAAAAAEiw/uH0wKz3D74o/s320/JSF2_NetBeans_6.PNG" style="cursor: pointer; display: block; height: 195px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 4:&lt;/span&gt; deploying on server and running.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This step is exactly the same as step 4 from previous &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-netbeans-with-jsp.html"&gt;post&lt;/a&gt; about sample JSF 1.2 application. We also don't have to start the browser manually to see the application. Browser  will be started automatically with proper URL pointing to our  application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;What next?&lt;/span&gt;  This simple working   project can be used as a base for further learning about JSF. For   example we can change the view technology from .jsp to facelets. We can   add libraries which extend our standard tags by adding tags with ajax   support, i.e&amp;nbsp;&lt;a href="http://livedemo.exadel.com/richfaces-demo/index.jsp"&gt;RichFaces&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-1025429739839363585?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1025429739839363585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1025429739839363585'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/09/jsf-20-hello-world-in-netbeans-with.html' title='JSF 2.0 - &quot;Hello World&quot; in NetBeans (with *.xhtml pages)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_JXxdCCKdTo0/S6t6xo66efI/AAAAAAAAEiI/27atyIHWZR8/s72-c/JSF2_NetBeans_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2574568243925743759</id><published>2010-09-02T22:25:00.002+02:00</published><updated>2011-03-04T19:20:03.583+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 1.2 - "Hello World" in NetBeans (with *.jsp pages)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Tomcat for the NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to create "Hello World" application in JSF 1.2 using NetBeans&lt;/li&gt;&lt;/ul&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;b&gt;Note 1: &lt;/b&gt;The following post and example show classic JSF 1.2  application with a view technology as .jsp pages. I do not use any  additional libraries and extensions for the standard JSF libraries.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; I use standard capabilities of IDE platform to generate  the project, without those thousands automated plugins which do  everything for the user. Sometimes configuration and usage of a plugin  is a "pain in the ..." - in my opinion it is worth to know how to deal  with a standard set of tools, and after that there is always a time to  faciliate our life ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In the &lt;a href="http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html"&gt;previous post&lt;/a&gt; I described how to generate working sample of JSF 1.2 application using Eclipse and its capabilities. I decided to check how it looks like using NetBeans. And this was a nice surprise for me - it is easier than in Eclipse. I will show how to generate a working JSF application similar to application created under Eclipse.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Assumptions: &lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;1. Installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;2. Installed and configured NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;3. Installed and configured Tomcat for the NetBeans (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 1:&lt;/span&gt; creating and configuring web application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6tu-kpjonI/AAAAAAAAEhI/962gc96joAQ/s1600/JSF_Netbeans_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452573795131040370" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6tu-kpjonI/AAAAAAAAEhI/962gc96joAQ/s320/JSF_Netbeans_1.PNG" style="cursor: pointer; display: block; height: 225px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" and on the next screen configure some basic options like name and directory for the project. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6tvQNR6mbI/AAAAAAAAEhQ/zWkSVx9qpxo/s1600/JSF_Netbeans_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452574098095511986" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6tvQNR6mbI/AAAAAAAAEhQ/zWkSVx9qpxo/s320/JSF_Netbeans_2.PNG" style="display: block; height: 225px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" and on the next screen configure runtime for the project.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6tvsFuHTaI/AAAAAAAAEhY/VNe0zeJjwR4/s1600/JSF_Netbeans_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452574577102638498" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6tvsFuHTaI/AAAAAAAAEhY/VNe0zeJjwR4/s320/JSF_Netbeans_3.PNG" style="cursor: pointer; display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" and on the next screen add JSF capabilities to the project. Select "JavaServer Faces" option and set up JSF 1.2 libraries.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6tv_RxWCNI/AAAAAAAAEhg/JK2rTJQzFpQ/s1600/JSF_Netbeans_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452574906754926802" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S6tv_RxWCNI/AAAAAAAAEhg/JK2rTJQzFpQ/s320/JSF_Netbeans_4.PNG" style="cursor: pointer; display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 2:&lt;/span&gt; project is configured.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Screenshot below shows the project structure generated by NetBeans. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6tw0LsOafI/AAAAAAAAEho/sAmIC5QyFwI/s1600/JSF_Netbeans_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452575815655909874" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6tw0LsOafI/AAAAAAAAEho/sAmIC5QyFwI/s320/JSF_Netbeans_5.PNG" style="cursor: pointer; display: block; height: 207px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's &lt;b&gt;all&lt;/b&gt;. Project is ready to deploy on the server. You don't need to add and configure JSF or JSTL libraries like under Eclipse. Those libraries are already in the project. Anyway in order to show that everything works the same we will modify generated project and write some piece of an application like under Eclipse.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 3:&lt;/span&gt; creating application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we are ready to implement some sample JSF application. First we should create a package named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;com.firstjsf.backingbeans&lt;/span&gt; in the "Source Packages" directory. Second we should create two classes inside the package named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;HelloMessageBean&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WelcomeBean&lt;/span&gt;.  Third we should modify generated &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file by adding there our classes and navigation rules. Everything should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6tyitFHrmI/AAAAAAAAEhw/Ci2OW2-7HLE/s1600/JSF_Netbeans_6.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452577714404306530" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6tyitFHrmI/AAAAAAAAEhw/Ci2OW2-7HLE/s320/JSF_Netbeans_6.PNG" style="cursor: pointer; display: block; height: 195px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file we created entries for the navigation rules for not existing yet web pages. Let's create those web pages (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;index.jsp&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;message.jsp&lt;/span&gt;) in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;Web Pages&lt;/span&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;directory: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6t0IXTM5zI/AAAAAAAAEh4/gJF74h4PYjE/s1600/JSF_Netbeans_7.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452579460904445746" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S6t0IXTM5zI/AAAAAAAAEh4/gJF74h4PYjE/s320/JSF_Netbeans_7.PNG" style="cursor: pointer; display: block; height: 195px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 4:&lt;/span&gt; deploying on server and running the application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We have to click only one icon - NetBeans will start the Tomcat with our application deployed:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6t0neQdEyI/AAAAAAAAEiA/sI_3zoBvDww/s1600/JSF_Netbeans_8.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5452579995347915554" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S6t0neQdEyI/AAAAAAAAEiA/sI_3zoBvDww/s320/JSF_Netbeans_8.PNG" style="cursor: pointer; display: block; height: 195px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Results of application running can be visible in the console. We don't have to directly tell the Tomcat what application to deploy like under Eclipse - this step is done automatically. Moreover we don't have to start the browser manually to see the application. Browser will be also started automatically with proper URL pointing to our application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;What next?&lt;/span&gt;  This simple working  project can be used as a base for further learning about JSF. For  example we can change the view technology from .jsp to facelets. We can  add libraries which extend our standard tags by adding tags with ajax  support, i.e&amp;nbsp;&lt;a href="http://livedemo.exadel.com/richfaces-demo/index.jsp"&gt;RichFaces&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2574568243925743759?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2574568243925743759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2574568243925743759'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-netbeans-with-jsp.html' title='JSF 1.2 - &quot;Hello World&quot; in NetBeans (with *.jsp pages)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/S6tu-kpjonI/AAAAAAAAEhI/962gc96joAQ/s72-c/JSF_Netbeans_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2332181253008170098</id><published>2010-09-01T20:45:00.018+02:00</published><updated>2011-07-26T21:22:22.901+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSF'/><title type='text'>JSF 1.2 - "Hello World" in Eclipse (with *.jsp pages)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;installed Java (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;installed and configured Tomcat for the Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;You will learn:&lt;/b&gt;&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;how to create "Hello World" application in JSF 1.2 using Eclipse&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;Note 1: &lt;/b&gt;The following post and example show classic JSF 1.2 application with a view technology as .jsp pages. I do not use any additional libraries and extensions for the standard JSF libraries.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note 2:&lt;/b&gt; I use standard capabilities of IDE platform to generate the project, without those thousands automated plugins which do everything for the user. Sometimes configuration and usage of a plugin is a "pain in the ..." - in my opinion it is worth to know how to deal with a standard set of tools, and after that there is always a time to faciliate our life ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Many publications and tutorials about JSF (Java Server Faces) very briefly descibe the configuration of development environment for the described examples. Many times I saw such situation: after few sentences about "how amazing is JSF" there was a simple list of JSF tags with their attributes described. Or at the beginning there was an example of "Hello World" application and every line of code was described and explained.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I think that is what is missing is the lack of an example of complete project with its directory structure and an information how to create this project and deploy on the web server. I saw some examples where the project structure was shown, but for the building and deploying application user had to use Ant and type some commands. Great, but we need Ant, when we have Ant, we need to be familiar with it to write build.xml file, then we need something else and so on and so on.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This is of course OK if we want to write everything from scratch by hand. But wouldn't it better just to start our IDE, make some clicks and have a complete and working project ready for further development?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's see how it looks like in Eclipse IDE. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; creating dynamic web project for the Tomcat.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Open menu  "File-&amp;gt;New-&amp;gt;Project" and in the "web" section find and choose "Dynamic Web Project" and press "Next":&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41bx3lSuqI/AAAAAAAAEdA/zwfjE9mC_gw/s1600-h/JSF_Eclipse_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444108436852882082" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41bx3lSuqI/AAAAAAAAEdA/zwfjE9mC_gw/s320/JSF_Eclipse_1.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Press "Next" to go further and set some basic project's properties:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41cMveDlqI/AAAAAAAAEdI/x4So28EkAgo/s1600-h/JSF_Eclipse_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444108898531514018" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41cMveDlqI/AAAAAAAAEdI/x4So28EkAgo/s320/JSF_Eclipse_2.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S41cW82nmcI/AAAAAAAAEdQ/uaaOpkithXg/s1600-h/JSF_Eclipse_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444109073922890178" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S41cW82nmcI/AAAAAAAAEdQ/uaaOpkithXg/s320/JSF_Eclipse_3.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 289px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After that we should have generated project structure for the web application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;Step 2:&lt;/span&gt; adding JSF capabilities for the generated project.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In order to do this just right click on the project and from the opened context menu choose "Properties" option. Locate the section "Project Facets" and check the option "JavaServer Faces".&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41dGYxDVRI/AAAAAAAAEdY/yn5_1h4tytk/s1600-h/JSF_Eclipse_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444109888869586194" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41dGYxDVRI/AAAAAAAAEdY/yn5_1h4tytk/s320/JSF_Eclipse_4.PNG" style="cursor: pointer; display: block; height: 229px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Choose "Further configuration required..." option below to configure JSF libraries:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41eCu39NRI/AAAAAAAAEdg/7kC4QUsE2TY/s1600-h/JSF_Eclipse_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444110925596275986" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41eCu39NRI/AAAAAAAAEdg/7kC4QUsE2TY/s320/JSF_Eclipse_5.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 213px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Choose "User Library" type and press marked icon to download JSF libraries. Eclipse Galileo allows to download two implementations of JSF: MyFaces anf from the Sun. Let's choose MyFaces: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S41epx0DOmI/AAAAAAAAEdo/KQKYLhOG82Q/s1600-h/JSF_Eclipse_6.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444111596400097890" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S41epx0DOmI/AAAAAAAAEdo/KQKYLhOG82Q/s320/JSF_Eclipse_6.PNG" style="cursor: pointer; display: block; height: 183px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that we created a special directory for libraries in the Eclipse workspace - libraries will be downloaded to this directory. After pressing "Next" we have to follow the library installer instructions:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41f4LAd65I/AAAAAAAAEdw/aj2MdHJ6M78/s1600-h/JSF_Eclipse_7.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444112943192861586" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41f4LAd65I/AAAAAAAAEdw/aj2MdHJ6M78/s320/JSF_Eclipse_7.PNG" style="cursor: pointer; display: block; height: 183px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After pressing "Finish", JSF libraries are visible and ready to use in the project.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41gDfHH3JI/AAAAAAAAEd4/CcnzupeR3II/s1600-h/JSF_Eclipse_8.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444113137568046226" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41gDfHH3JI/AAAAAAAAEd4/CcnzupeR3II/s320/JSF_Eclipse_8.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 298px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 3:&lt;/span&gt;  JSTL libraries.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;If JSP tags will be used in JSF application, JSTL libraries are required next to automatically downloaded JSF libraries. Unfortunately above automated solution for downloading JSF libraries does not download JSTL libraries, so we have to download them manually. I recommend to create another directory for JSTL libraries next to the JSF downloaded libraries in Eclipse's workspace directory. So create directory "libraries\JSTL" in Eclipse workspace directory, download JSTL libraries from &lt;a href="https://jstl.dev.java.net/download.html"&gt;there&lt;/a&gt; and put them into that directory. It should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41hFAFJJ3I/AAAAAAAAEeA/lIXw167_Sxc/s1600-h/JSF_Eclipse_9.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444114263109609330" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41hFAFJJ3I/AAAAAAAAEeA/lIXw167_Sxc/s320/JSF_Eclipse_9.PNG" style="display: block; height: 182px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we should create library from the downloaded JSTL files in the Eclipse in order to be able to use them in the project. It will be the similar operation to the creating JSF library - the difference is that we will do it manually. Just open the context menu for the whole project (right click) and go to the "Properties" screen. Then locate "Project Facets" section and find the "Add library" button.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41icOZpCxI/AAAAAAAAEeI/7ecdN0Cz2eI/s1600-h/JSF_Eclipse_10.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444115761602300690" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41icOZpCxI/AAAAAAAAEeI/7ecdN0Cz2eI/s320/JSF_Eclipse_10.PNG" style="cursor: pointer; display: block; height: 223px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that library list contains JSF libraries added in step 2. Now create new library named "JSTL" like it is shown above, and add .jar files from JSTL directory:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41jByr6dvI/AAAAAAAAEeQ/bhB6Mka6ctM/s1600-h/JSF_Eclipse_11.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444116406997776114" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41jByr6dvI/AAAAAAAAEeQ/bhB6Mka6ctM/s320/JSF_Eclipse_11.PNG" style="cursor: pointer; display: block; height: 247px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Then make sure that those two libraries (JSF i JSTL) are added to the project (application):&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41jV4PpHYI/AAAAAAAAEeY/NgoNF9znKfs/s1600-h/JSF_Eclipse_12.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444116752087195010" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41jV4PpHYI/AAAAAAAAEeY/NgoNF9znKfs/s320/JSF_Eclipse_12.PNG" style="cursor: pointer; display: block; height: 218px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;div style="color: red;"&gt;&lt;b&gt;Note:&lt;/b&gt; this configuration is &lt;b&gt;recommended&lt;/b&gt; in order to let the Code Assist for *.jsp pages work properly. Code Assist allows automatically complete JSF tags when typying by pressing CTRL + Space. Also access to beans, their methods or fields is possible directly from JSP page (by click on bean/field name).&lt;/div&gt;&lt;div style="color: black;"&gt;&lt;/div&gt;&lt;br /&gt;--------------------------------------------&amp;nbsp;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Steps 2 and 3 in an alternative way:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We do not have to download requires .jar files for JSF and JSTL, make user libraries from them in Eclipse and add those libraries to the generated project with "Project Facets" screen. The alternative way is to download all required .jar files and copy them into the generated "WebContent\WEB-INF\lib" directory. After that just refresh the whole project by pressing "F5" on the project's root and all libraries should appear in the section named "Web App Libraries" in the project's structure.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;b style="color: red;"&gt;Note:&lt;/b&gt;&lt;span style="color: red;"&gt;&amp;nbsp; this configuration (&lt;/span&gt;&lt;span style="color: red;"&gt;despite the fact it is faster&lt;/span&gt;&lt;span style="color: red;"&gt;) is &lt;b&gt;not recommended&lt;/b&gt;, because of Code Assist which does not work at all.&lt;/span&gt; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; 4:&lt;/span&gt;  the overview of a project.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;When steps 1-3 where done as described, the project structure should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41mg7YYgUI/AAAAAAAAEeg/QWcmcvvqLbI/s1600-h/JSF_Eclipse_13.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444120240442605890" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41mg7YYgUI/AAAAAAAAEeg/QWcmcvvqLbI/s320/JSF_Eclipse_13.PNG" style="cursor: pointer; display: block; height: 190px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Please note that JSF and JSTL .jar files are visible as user libraries in created in steps 2 and 3. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 5:&lt;/span&gt; "Hello World" application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we are ready to implement some sample JSF application. First we should create a package named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;com.firstjsf.backingbeans&lt;/span&gt; in the "src" directory. Second we should create two classes inside the package named &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;HelloMessageBean&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WelcomeBean&lt;/span&gt;.  Third we should modify generated &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file by adding there our classes and navigation rules. Everything should look like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41od1zWlJI/AAAAAAAAEeo/8_dVIjiR848/s1600-h/JSF_Eclipse_14.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444122386428761234" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41od1zWlJI/AAAAAAAAEeo/8_dVIjiR848/s320/JSF_Eclipse_14.PNG" style="cursor: pointer; display: block; height: 194px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Be careful about small and big letters - names should be exactly as shown above. In the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;faces-config.xml&lt;/span&gt; file we created entries for the navigation rules for not existing yet web pages. Let's create those web pages (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;index.jsp&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;message.jsp&lt;/span&gt;) in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;WebContent&lt;/span&gt;&lt;span style="font-style: italic;"&gt; &lt;/span&gt;directory: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41pm8d-N9I/AAAAAAAAEew/gkHBLzQFxnM/s1600-h/JSF_Eclipse_15.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444123642348582866" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41pm8d-N9I/AAAAAAAAEew/gkHBLzQFxnM/s320/JSF_Eclipse_15.PNG" style="cursor: pointer; display: block; height: 194px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Application is ready.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 6:&lt;/span&gt; deploying on Tomcat. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;At the bottom of a screen locate "Severs" tab. We should have already Tomcat there. Right click on server name to open its context menu, ten choose option "Add and Remove...":&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41rzCRThpI/AAAAAAAAEe4/3XndnfFxEY4/s1600-h/JSF_Eclipse_16.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444126049087751826" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41rzCRThpI/AAAAAAAAEe4/3XndnfFxEY4/s320/JSF_Eclipse_16.PNG" style="cursor: pointer; display: block; height: 194px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Choose our project and add it to the server by pressing "Add" button:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41r-uM9XwI/AAAAAAAAEfA/TglXqeiOe1I/s1600-h/JSF_Eclipse_17.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444126249859243778" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/S41r-uM9XwI/AAAAAAAAEfA/TglXqeiOe1I/s320/JSF_Eclipse_17.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 314px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 7:&lt;/span&gt; running the application.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Go back to the "Server" tab again and make sure that our project is visible on the server. Then click the marked icon to start the server:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41s3N3dNyI/AAAAAAAAEfI/iF28YnMhoW4/s1600-h/JSF_Eclipse_18.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444127220431664930" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S41s3N3dNyI/AAAAAAAAEfI/iF28YnMhoW4/s320/JSF_Eclipse_18.PNG" style="cursor: pointer; display: block; height: 92px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After starting the server we should see that the server state was changed:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41tZriijaI/AAAAAAAAEfQ/X-PA1VrRlGg/s1600-h/JSF_Eclipse_19.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5444127812512550306" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S41tZriijaI/AAAAAAAAEfQ/X-PA1VrRlGg/s320/JSF_Eclipse_19.PNG" style="display: block; height: 89px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After deploying application on the server and starting the server, we have to open a browser and type in URL:&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;http://localhost:8080/FirstJSF&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;What next?&lt;/span&gt;  This simple working project can be used as a base for further learning about JSF. For example we can change the view technology from .jsp to facelets. We can add libraries which extend our standard tags by adding tags with ajax support, i.e &lt;a href="http://livedemo.exadel.com/richfaces-demo/index.jsp"&gt;RichFaces&lt;/a&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Download source files:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note:&lt;/b&gt; make sure that &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;Java&lt;/a&gt;, &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;Eclipse&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html"&gt;Tomcat&lt;/a&gt; are properly installed and configured for running the project (additional configuration may be required if different directories are used).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Eclipse complete sample project is &lt;a href="https://sites.google.com/site/technologyforhuman/FirstJSF.zip"&gt;here&lt;/a&gt;. External libraries folder (with JSF and JSTL) is &lt;a href="https://sites.google.com/site/technologyforhuman/FirstJSF_libraries.zip"&gt;here&lt;/a&gt;. You can also download a war file located &lt;a href="https://sites.google.com/site/technologyforhuman/FirstJSF.war"&gt;here&lt;/a&gt; (just copy it inside &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;webapps&lt;/span&gt; folder in Your Tomcat and start Tomcat with the script &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;startup.bat&lt;/span&gt;)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2332181253008170098?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2332181253008170098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2332181253008170098'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/09/jsf-12-hello-world-in-eclipse-with-jsp.html' title='JSF 1.2 - &quot;Hello World&quot; in Eclipse (with *.jsp pages)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_JXxdCCKdTo0/S41bx3lSuqI/AAAAAAAAEdA/zwfjE9mC_gw/s72-c/JSF_Eclipse_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-7437794985417560770</id><published>2010-02-24T23:50:00.267+01:00</published><updated>2010-06-13T14:29:56.504+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>"My databse is slow" - part 3: some technical stuff</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;In the previous two posts I tried to show what can affect the overall &lt;a href="http://technology-for-human.blogspot.com/2009/10/baza-muli-czesc-1.html"&gt;performance&lt;/a&gt; of the database and how important are &lt;a href="http://technology-for-human.blogspot.com/2010/01/baza-muli-czesc-2.html"&gt;indexes&lt;/a&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If we assume that the database is normalized, memory settings for the server are ok and we have indexes, the only way to check the performance is monitoring the query plans. Therefore I would like to return once again to the query plans and look at them with more details.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;From the previous post, we know that we can generate plans for queries using two commands. These commands are:&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;&lt;b&gt;&lt;/b&gt;EXPLAIN SQL_command&lt;/li&gt;&lt;li&gt;EXPLAIN ANALYZE SQL_command - this command is a variant of the first with small difference: examined query is executed and EXPLAIN ANALYZE returns the real execuion time.&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Using the test database from the previous post, let's see the query plan for the following SQL command: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;select * from customers where lname = 'Cervantes';&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;To see the query plan, execute those two commands:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;vacuum analyze;&lt;br /&gt;explain select * from customers where lname = 'Cervantes';&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Query plan that has been generated for this query is as follows: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4V7gDhYG8I/AAAAAAAAEas/icoUK2dsqb4/s1600-h/cervantes_query_plan.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5441891515378441154" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4V7gDhYG8I/AAAAAAAAEas/icoUK2dsqb4/s320/cervantes_query_plan.PNG" style="cursor: pointer; display: block; height: 110px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Always we are most interested in &lt;b&gt;"the highest" line of displayed plan&lt;/b&gt; - it shows the &lt;b&gt;total cost of the query execution&lt;/b&gt;, after all other internal operations for more complex queries (eg joins, sorts, etc.).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In our case we have: (cost: 4.51 .. 59.47 rows = 33 width = 18). What does it mean?&lt;/div&gt;&lt;ol style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;&lt;b&gt;cost: 4.51 .. 59.47&lt;/b&gt; - this is an interval defining total execution time measured in special units called disk page fetches - these units are not seconds nor other units of time. First number estimates time needed to retrieve first row in the result, second estimates total cost of returning all rows in the result. The calculation of this value is "higher mathematics", especially if the query uses more techniques than primitive table sequential scanning - which is the easiest and can be easily calculated. Unfortunately, but only for primitive examples like "select * from some_table" (without the use of indices to be 100% sure that the scan will be performed sequentially and without any query conditions "where"), You can find over the Web some examples of calculating these values. Those who are interested in more details and technical stuff, should visit &lt;a href="http://doxygen.postgresql.org/costsize_8c.html"&gt;this page&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;b&gt;rows = 33&lt;/b&gt; - this is estimated number of rows returned by a query.&lt;/li&gt;&lt;li&gt;&lt;b&gt;width = 18&lt;/b&gt; - this is estimated size (in bytes) of all the returned rows&lt;/li&gt;&lt;/ol&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Above data are obtained on the basis of statistics located in a special system tables. There are two tables of statistics which are crucial for the query planner:&lt;/div&gt;&lt;ol style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;&lt;b&gt;pg_class &lt;/b&gt;- contains information about certain database relations (tables, indexes, etc.), i.e. their location and size.&lt;/li&gt;&lt;li&gt;&lt;b&gt;pg_stats&lt;/b&gt; - contains information about the data stored in tables, i.e. the most common values, the frequency of common values occurrence.&lt;/li&gt;&lt;/ol&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's see what are the statistics for the table "customers", and what is their impact on some elements of the query plan for above query about user "Cervantes".&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4WWAjPouxI/AAAAAAAAEa0/uBYIRB110lk/s1600-h/cervantes_pg_class.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5441920660952103698" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4WWAjPouxI/AAAAAAAAEa0/uBYIRB110lk/s320/cervantes_pg_class.PNG" style="cursor: pointer; display: block; height: 105px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Returned data mean that the table "cutomers" has 10.000 records and is located on 62 "pages".&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4WX-i5UhsI/AAAAAAAAEbE/DQmFuhW9mvQ/s1600-h/cervantes_pg_stats.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5441922825522022082" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4WX-i5UhsI/AAAAAAAAEbE/DQmFuhW9mvQ/s320/cervantes_pg_stats.PNG" style="cursor: pointer; display: block; height: 84px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Returned data are based on some statistical data for all the columns in the table "cusotmers" and their content. It is specified which values are most popular, what is their frequency, and amount of values which are different from each other.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;What is the meaning of this data in the context of our query about "Cervantes" user? &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;pg_class&lt;/b&gt; - is the basis in calculating the cost of the query execution. For our "Cervantes" query&amp;nbsp; in the case of sequential scan (if there were no index on the "lname" field in the Customers table), we would calculate the cost from the formula:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-style: italic;"&gt;(relpages * SEQ_PAGE_COST) +  (reltuples * CPU_TUPLE_COST) + (relpages * CPU_OPERATOR_COST)&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Capitalized names are costs of arbitrary operation - the are defined in postgresql.conf. Unfortunately (or "fortunately"), our query uses indexes, so the calculation of the cost is a bit more complicated (task for volunteers, formulas are &lt;a href="http://doxygen.postgresql.org/costsize_8c.html"&gt;here&lt;/a&gt;, You only have to to be familiar with the concepts of "last recently used buffers" (LRU) and Mackert-Lohman formula ;-)).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;pg_stats&lt;/b&gt; - allows to estimate the number of rows returned in a query using given logical condition (in our case: "where lname = 'Cervantes'"). In our case for the "Cervantes" query we are lucky - "Cervantes" occurs directly in the list of most common surnames, and also is known for its occurrence. The number of rows returned is calculated using the formula:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-style: italic;"&gt;relpages * selectivity&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;where:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-style: italic;"&gt;selectivity =  most_common_freqs["Cervantes"]&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Hence we get:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;10000 * 0,00333333 = 33&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;And what if we are looking for value which is not in the column "most_common_freqs"? Then the formula has a different form:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-style: italic;"&gt;selectivity = (1 -  sum(most_common_freqs))/(num_distinct - num_most_common_vals)&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Calculating selectivity value for the name "Smith", I leave for volunteers as usually ;-). Remember that first You have to execute "vacuum analyze" and then view statistics and then the query plan.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&amp;nbsp;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Some notes about the statistics:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The content of statistics tables is generated based on&lt;b&gt; random samples taken from the tables in the database&lt;/b&gt;. Generating (and therefore refreshing) full statistics takes place during the execution of the &lt;b&gt;VACUUM ANALYZE&lt;/b&gt; command. Hence, it is very important to &lt;b&gt;run this command periodically&lt;/b&gt; to ensure that statistics for the planner are up to date. Therefore, before showing the above example the first command executed by me was VACUUM ANALYZE in order to query plan be based on the most reliable statistics.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It should be noted that next execution of this command can generate a slightly different statistics, so query plan for the same query may be slightly different (in terms of cost and estimated number of rows). This is because of mentioned random samples taken for calculations.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;A few final notes about performance&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I can say that the general rule to optimize query execution time is as follows:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;"There is no certain way to increase performance in all cases. The best method is trial and error."&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In practice it means to try to &lt;b&gt;generate different query plans&lt;/b&gt; (in addition to that which is generated by default) and select those with the best execution time. These attempts usually involve forcing the query planner&amp;nbsp; to behave in different way which leads to a different query plan. This can be achieved through:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;1.&lt;/b&gt; Forcing the query planner to use an index (often the index exists but is not used by the planner). This can be done for example by:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;switching off a global sequential scans by setting enable_seqscan = off in postgresql.conf file&lt;/li&gt;&lt;li&gt;partial indexes (conditional) - You can create a conditional index for  the most frequently returned data in column&lt;/li&gt;&lt;li&gt;indexes using multiple fields (watch out for the order - the order of fields in  the index should be the same as the order of fields in queries)&lt;/li&gt;&lt;li&gt;some SQL tricks related to change the query selectivity, for example using LIMIT, ORDER BY or trailing condition AND TABLE_ID = TABLE_ID (where TABLE_ID is a master key in  the table)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;2. &lt;/b&gt;Changing the order of joining multiple tables, for example executing   "(A join B) join C" can be different than executing "A join (B join  C)" - this is similar to a problem of&amp;nbsp; "optmial matrix-chain  multiplication".&lt;br /&gt;&lt;b&gt;3.&lt;/b&gt; Using stored procedures, views, breaking huge query into a number of  smaller queries .&lt;br /&gt;&lt;b&gt; &lt;/b&gt;&lt;br /&gt;&lt;b&gt;Interesting fact (found over the Web): &lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In order to monitor the  progress of executing a long query to the database (a really long time,  not a few seconds) you can create a sequence with the value set to 1  (eg, the sequence "monitor_seq") and add it to executing query:&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;select nextval('monitor_seq'), column1, column2....&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Executing:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;select currval('monitor_seq');&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;at the time of running the long query will show us the progress.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-7437794985417560770?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7437794985417560770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7437794985417560770'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/02/baza-muli-czesc-3-czyli-ciekawostki.html' title='&quot;My databse is slow&quot; - part 3: some technical stuff'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_JXxdCCKdTo0/S4V7gDhYG8I/AAAAAAAAEas/icoUK2dsqb4/s72-c/cervantes_query_plan.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-5127090517447690545</id><published>2010-01-05T21:25:00.124+01:00</published><updated>2011-03-04T19:25:03.193+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>"My database is slow" - part 2: indexes.</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;This post is a continuation of &lt;a href="http://technology-for-human.blogspot.com/2009/10/baza-muli-czesc-1.html"&gt;previous entry&lt;/a&gt; about database performance.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Suppose we have a database that is normalized to our needs, the memory of the server was also quite reasonably allocated, we are using a connection pool and we did not change the default transaction isolation level for our database - but the database still is not a "speed daemon". What can You do in this situation? Did we miss something?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;You can look inside the database giva a closer look on specific operations performed on the data to determine which operations cause performance degradation and possibly "help" them perform faster. As the sample database I will use PostgreSQL - I will examine its specific mechanisms to check and improve performance. This will be only an outline of what can be done (based on crude example), because the topic is so large that it may well be placed on a separate dedicated blog.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;installed PostgreSQL (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-wersja-soft.html"&gt;here&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;a test database with &lt;b&gt;sample data&lt;/b&gt; - just to show how PostgreSQL performs a very simple SQL opeartions &lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;&lt;/b&gt;Let's consider a very simple database for some online store with two tables: customer table (called Customer) and customers' orders table (called Order). Just open pgAdmin and execute this SQL command:&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE DATABASE store ENCODING = 'UTF8';&lt;/pre&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Then connect to database "store" and run this SQL commands:&lt;/div&gt;&lt;br /&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE TABLE customers&lt;br /&gt;(&lt;br /&gt;customer_id INTEGER,    &lt;br /&gt;fname VARCHAR(32),&lt;br /&gt;lname VARCHAR(32) NOT NULL,&lt;br /&gt;CONSTRAINT customer_pk PRIMARY KEY(customer_id)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;CREATE TABLE orders&lt;br /&gt;(&lt;br /&gt;order_id INTEGER,&lt;br /&gt;customer_id INTEGRE NOT NULL CONSTRAINT customer_order_fk REFERENCES customers(customer_id),&lt;br /&gt;description TEXT,&lt;br /&gt;price NUMERIC(7,2),    &lt;br /&gt;CONSTRAINT order_pk PRIMARY KEY(order_id)    &lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;For simplicity, here I do not use a SERIAL field to hold primary keys - just ordinary integer with constraint. Now we should fill the database with some &lt;b&gt;sample data&lt;/b&gt;: lets put about 10 000 records to Customers table and 30 000 records to Orders table.&amp;nbsp; That is rather huge amount of data. How can we do it?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The best way is to write a Java program that generates a file with proper SQL INSERT statements for each table - this is homework for You ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;I wrote simple program which takes &lt;a href="http://names.mongabay.com/male_names.htm"&gt;popular first names for males&lt;/a&gt; and &lt;a href="http://names.mongabay.com/female_names.htm"&gt;popular first names for females&lt;/a&gt;, then takes popular &lt;a href="http://names.mongabay.com/data/1000.html"&gt;surnames&lt;/a&gt; from here and combines them together to produce 10.000 "people". Having those records and knowing their customer_id (that's why I used ordinary integer field - just to write a program) my program generated random 30 000 orders for those customers.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;And now suppose we want to &lt;b&gt;retrieve all customers named Smith&lt;/b&gt; and we want to &lt;b&gt;see all orders for each customer Smith&lt;/b&gt;. We need &lt;b&gt;two queries&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;select * from customers where lname = 'Smith';&lt;br /&gt;select * from orders join customers on orders.customer_id=customers.customer_id where customers.lname = 'Smith';&lt;/pre&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;In my case, the first query returns just 9 customers named Smith (from total of 10 000) and 30 orders (from total of 30 000) for all 9 "Smiths".&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Okay, we have SQL commands - but how can we check their &lt;b&gt;execution time&lt;/b&gt; on a database? PostgreSQL provides two commands that show details about executed commands:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;a) &lt;/b&gt;EXPLAIN SQL_command&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;b)&lt;/b&gt; EXPLAIN ANALYZE SQL_command - this command is a variant of the first with small difference: examined query is executed and EXPLAIN ANALYZE returns the real execuion time.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Before we show an example of above commands execution, some technical information about the process of executing the query by PostgreSQL: when the PostgreSQL server receives SQL command from client application, the &lt;b&gt;query string&lt;/b&gt; is passed to the &lt;b&gt;query parser&lt;/b&gt; that checks for syntax errors. If everything is ok, parser based on the query creates a structure called the &lt;b&gt;query tree&lt;/b&gt;. Then, this structure is passed to the &lt;b&gt;query planner&lt;/b&gt; which generates all possible &lt;b&gt;query plans&lt;/b&gt; and chooses the shortest one from them. This plan is passed to the &lt;b&gt;executor&lt;/b&gt; who performs the query and returns the records in the manner described in query plan.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Mentioned EXPLAIN command displays the details of the plan chosen by the planner as the shortest one. Let's see the result of executing EXPLAIN ANALYZE for the queries about users Smith: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S2XGE1OKqDI/AAAAAAAAEXY/FoSxlhH_KJE/s1600-h/PostgreSQL_smith_users_basic.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" height="112" id="BLOGGER_PHOTO_ID_5432966311800645682" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S2XGE1OKqDI/AAAAAAAAEXY/FoSxlhH_KJE/s400/PostgreSQL_smith_users_basic.PNG" style="display: block; margin: 0px auto 10px; text-align: center;" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S2XFx-iB64I/AAAAAAAAEXQ/xPOM4T790Wc/s1600-h/PostgreSQL_smith_orders_basic.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;/a&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/TLXw056P1PI/AAAAAAAAFaU/TkEkUyMr324/s1600/PostgreSQL_smith_orders_basic.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="138" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/TLXw056P1PI/AAAAAAAAFaU/TkEkUyMr324/s400/PostgreSQL_smith_orders_basic.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Because reading query plans and their details is a separate art, we will focus on the actual run time (visible as a &lt;b&gt;Total Runtime&lt;/b&gt;, respectively &lt;b&gt;1,482 ms for the first question&lt;/b&gt;, and &lt;b&gt;16,552 ms for the second question&lt;/b&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Lets provide &lt;b&gt;indexes&lt;/b&gt; for the fields we are searching for and for the fields where the join operation is performed. In our case it will be:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;a)&lt;/b&gt; the &lt;b&gt;lname&lt;/b&gt; column of the Customers table - create index with the command:&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE INDEX lname_index ON customers USING btree (lname);&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;b)&lt;/b&gt; the foreign key column in Orders table (the column &lt;b&gt;cutomer_id&lt;/b&gt;) - create an index using the command:&amp;nbsp; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE INDEX customer_fk_index ON orders USING btree (customer_id);&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b style="color: red;"&gt;Note:&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After You create indexes, You have to &lt;b&gt;refresh the statistics used by database planner&lt;/b&gt; to calculate the optimal query plan. This is done by running &lt;b&gt;VACUUM ANALYZE&lt;/b&gt; command. After executing this command, once again execute the EXPLAIN ANALYZE command for our "Smith" queries:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S2XQsXWZOWI/AAAAAAAAEXg/FR3Q0VOdTqY/s1600-h/PostgreSQL_smith_users_optimized.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5432977986093136226" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S2XQsXWZOWI/AAAAAAAAEXg/FR3Q0VOdTqY/s400/PostgreSQL_smith_users_optimized.PNG" style="cursor: pointer; display: block; height: 122px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S2XQ52UyPgI/AAAAAAAAEXo/nk3NAFSRVcY/s1600-h/PostgreSQL_smith_orders_optimized.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5432978217746185730" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S2XQ52UyPgI/AAAAAAAAEXo/nk3NAFSRVcY/s400/PostgreSQL_smith_orders_optimized.PNG" style="cursor: pointer; display: block; height: 155px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The results of the queries which are &lt;b&gt;several times faster than previously&lt;/b&gt;. They are respectively: &lt;b&gt;0,123 ms (1,482 ms previously)&lt;/b&gt;, and&lt;b&gt; 0,507 ms (16,552 ms previously)&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;The advantage is obvious. But whether the index will solve all our problems? Not always. There is no guarantee that the planner will benefit from the index. Sometimes it appears that the sequential table scan can be faster than using an index (such behavior may depend on the "selectivity" degree of certain query). In most cases it is good to have indexes - they can only help.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-5127090517447690545?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5127090517447690545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5127090517447690545'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2010/01/baza-muli-czesc-2.html' title='&quot;My database is slow&quot; - part 2: indexes.'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_JXxdCCKdTo0/S2XGE1OKqDI/AAAAAAAAEXY/FoSxlhH_KJE/s72-c/PostgreSQL_smith_users_basic.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-4781809560113773434</id><published>2009-10-12T20:18:00.256+02:00</published><updated>2010-06-08T20:00:51.666+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>"My database is slow" - part 1</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Perhaps You often heard complaints that some application is veeeery sloooow. Despite the technology used, bought another X GB of RAM and so on the problem still exists. Sometimes the cause can be very simple - &lt;b&gt;interaction with the database can be a bottleneck&lt;/b&gt; and a source of all problems. This can be checked and possibly improved.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Often the developer itself must change something in the database - do not be afraid to say it - hire a database magician cost a lot of money for the company and often the developer becomes a database specialist ;-). Therefore, anyone who changes something in the database must have some knowledge. Otherwise, some ad-hoc changes can cause a lot of performance problems.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;What can you do then? Having the database, You can take a closer look on some points:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;1. Database normalization (decomposition).&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;Simply said - making a database to be in the &lt;b&gt;n-th normal form&lt;/b&gt;. You may naively believe that "the database engine can handle" somehow our SQL query, without worrying ourselves about performance. Theoretically yes, even nightmarish database schema will work somehow - after all, a bit smarter (than the rest) people formed the principles of relational databases. The problem starts when our application is no longer a primitive data browser which executes the same "select" SQL query all the time. That's why the other smarter people have invented a normalization. For example this allows the database engine not to retrieve 20 columns from one table just to show us only those 2 which we are interested.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;For example let's assume that we have a company and we store &lt;b&gt;all the employees in a one big table&lt;/b&gt;: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;CREATE TABLE employees ( &lt;br /&gt;id                int4 PRIMARY KEY,&lt;br /&gt;active            boolean, &lt;br /&gt;first_name        varchar, &lt;br /&gt;middle_name       varchar, &lt;br /&gt;last_name         varchar, &lt;br /&gt;ssn               varchar, &lt;br /&gt;address1          varchar, &lt;br /&gt;address2          varchar, &lt;br /&gt;city              varchar, &lt;br /&gt;state             varchar(2), &lt;br /&gt;zip               varchar, &lt;br /&gt;home_phone        varchar, &lt;br /&gt;work_phone        varchar, &lt;br /&gt;cell_phone        varchar, &lt;br /&gt;fax_phone         varchar, &lt;br /&gt;pager_number      varchar, &lt;br /&gt;business_email    varchar, &lt;br /&gt;personal_email    varchar, &lt;br /&gt;salary            int4, &lt;br /&gt;vacation_days     int2, &lt;br /&gt;sick_days         int2, &lt;br /&gt;employee_number   int4, &lt;br /&gt;office_addr_1     varchar,&lt;br /&gt;office_addr_2     varchar, &lt;br /&gt;office_city       varchar, &lt;br /&gt;office_state      varchar(2), &lt;br /&gt;office_zip        varchar, &lt;br /&gt;department        varchar,&lt;br /&gt;title             varchar,&lt;br /&gt;supervisor_id     int4&lt;br /&gt;); &lt;br /&gt;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;And now some Secretary wants to find those &lt;b&gt;people who earn more than 5000&lt;/b&gt; USD:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre class="brush: sql" style="font-family: Verdana,sans-serif;"&gt;SELECT first_name, last_name from employees where salary &amp;gt; 5000 ;&lt;/pre&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Let's assume that the company is a big corporation which employs thousands of people. Database engine must scan entire table, retrieve all columns for people who earn more than 5000 and at the end pefrorm a projection and return only 2 columns - first name and last name.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Note: do not kid ourselves - &lt;b&gt;normalization is not an ideal remedy for performance problems&lt;/b&gt;, and sometimes may even contribute to decrease a performance. Why? For example let's take huge reporting queries that collect a lot of cross-sectional data. In the fully normalized database, the amount of join operations between tables can be very large and could have significant impact on performance. Sometimes it is better to have non-normalized parts of database schema, or even have non-normalized redundant data tables (for generating reports) next to normalized parts. There is &lt;b&gt;no silver bullet solution&lt;/b&gt; for that - the approach depends on specific problem.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2. Memory configuration for the server. &lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;The fact that Your hardware allows You to play latest games, does not mean that the database will work fast. Even 10-th normal form of a database schema and super-optimal queries will not help when server has total memory similar to required by old DOS games. Sooner or later because of lack of memory many I/O disk operation will be performed to compensate memory request. System resources are important. Unfortunately, at this point databases vary widely in terms of available configuration options. "&lt;b&gt;No silver bullet&lt;/b&gt;" also applies here - the only way to discover best performance is to tune database memory settings and test it against SQL queries.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;3. Opening connection to the database.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Although the authors of JDBC drivers maintain that connection cost is small and well optimized, we must not forget that after all this is some expense. As an example, consider a typical web application where in every moment a user clicks on different screens, which show him various data. We have to approaches here:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;/b&gt;maintaining an open connection during user's working time&lt;/li&gt;&lt;li&gt;opening connection for each request, performing some database query, returns the result (which is presented to the user) and closing the connection.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;First approach is expensive (in terms of resources and performance), second is much better. But when we take into account the large number of users and their actions, total cost of opening and closing connections may have considerable importance. It is worth here to consider using the so-called &lt;b&gt;connection pool&lt;/b&gt; - such as Apache DBCP or C3P0. Responsibility for creating/closing of connections goes to connection pool. The pool itself has various configuration options that can increase the efficiency of cooperation with the database application. For example some connections may have been opened after startup and ready to immediate use and so on.&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;4. Transaction isolation levels and locks.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Transaction isolation levels have a direct impact on the types of locks used. If You are not sure how to choose the level of transaction isolation, it is better to remain at the default level for a particular database. You have to remember one important thing: the higher isolation level you choose the more subtle and complex lock must be use by the database engine to provide concurrent access to data. Using higher levels of isolation can also cause &lt;span class="short_text" id="result_box"&gt;&lt;span title=""&gt;deadlock occurrence. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Note: &lt;/b&gt;You may not agree with mentioned points. They are only my personal subjective choice based on problems and observations during my work. Database performance is a &lt;span class="short_text" id="result_box"&gt;&lt;span style="background-color: white; color: black;" title=""&gt;very broad issue dependent  on many factors - I pointed only four general issues, but You may find another four or more &lt;/span&gt;&lt;/span&gt;&lt;span class="short_text" id="result_box"&gt;&lt;span style="background-color: white;" title=""&gt;which will be just as important and  necessary.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-4781809560113773434?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4781809560113773434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/4781809560113773434'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/10/baza-muli-czesc-1.html' title='&quot;My database is slow&quot; - part 1'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2513918842496832345</id><published>2009-05-04T20:37:00.174+02:00</published><updated>2011-07-27T18:10:28.152+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Tomcat'/><title type='text'>Installing and configuring Tomcat for Eclipse and NetBeans</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Probably You always wanted to &lt;b&gt;write your own web-based application in Java&lt;/b&gt; (ok, read: writing another Facebook-like portal and live in luxury in Dubai to the end of Your life ;-)). Of course it is possible, but before that inevitable moment occurs, You have to do much more simple thing - &lt;b&gt;configure the environment for developing web applications&lt;/b&gt; (unless You are headmaster in Your own company and someone else does it for you...).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;So let's look at how to configure &lt;b&gt;Apache Tomcat&lt;/b&gt; which is professionally defined as the &lt;b&gt;servlet container&lt;/b&gt; (i.e. for JSP). I will show how to configure it under Eclipse and NetBeans.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Eclipse:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Recall that so far we have managed to &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html"&gt;install Java&lt;/a&gt; and &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;set up Eclipse&lt;/a&gt; to work with it. It is time for Tomcat.&amp;nbsp; &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; download the Tomcat binary distribution (core version as a .zip file) from &lt;a href="http://tomcat.apache.org/download-60.cgi"&gt;here&lt;/a&gt; &lt;b&gt;(use current Tomcat 6.x version, 6.0.32 - edited on Tuesday, July 26, 2011)&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; Unpack the .zip from step 1 to the &lt;b&gt;C:\Development\Tomcat_Eclipse&lt;/b&gt; directory. We should get something like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FSwvkCIOI/AAAAAAAAEZo/VD3NH42PPP0/s1600-h/Tomcat_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440720822195069154" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FSwvkCIOI/AAAAAAAAEZo/VD3NH42PPP0/s320/Tomcat_1.PNG" style="display: block; height: 210px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; Open Eclipse IDE and the Java EE perspective (Window menu -&amp;gt; Open Perspective -&amp;gt; Other -&amp;gt; Java EE). This will be the default perspective for our work. Using this perspective, at the bottom in the "Servers" tab we add a new server:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Sf88pdbAUjI/AAAAAAAADj4/FXYlZIsoe3w/s1600-h/Tomcat_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5332047166800155186" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Sf88pdbAUjI/AAAAAAAADj4/FXYlZIsoe3w/s320/Tomcat_2.PNG" style="cursor: pointer; display: block; height: 112px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; Configure the new server. Select the type of the server in accordance with step 1 (Tomcat 6), and leave the name set to localhost:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/Sf89A1d_RFI/AAAAAAAADkA/r7i-mPEh3Jw/s1600-h/Tomcat_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5332047568392111186" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/Sf89A1d_RFI/AAAAAAAADkA/r7i-mPEh3Jw/s320/Tomcat_3.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 275px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; Further configuration of the new server. Select the server's installation directory and Java virtual machine which will be used - in this case it will be the same virtual machine which we configured to work with Eclipse (description &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;here&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FXxx-1kiI/AAAAAAAAEZw/HdeG48ZYqWY/s1600-h/Tomcat_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440726337582371362" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FXxx-1kiI/AAAAAAAAEZw/HdeG48ZYqWY/s320/Tomcat_4.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 286px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; Basic configuration of a server&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FYsGetVVI/AAAAAAAAEaA/Uqv0uDyse1M/s1600-h/Tomcat_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440727339517171026" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FYsGetVVI/AAAAAAAAEaA/Uqv0uDyse1M/s320/Tomcat_5.PNG" style="cursor: pointer; display: block; height: 189px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;First we allow the Eclipse to manage Tomcat installation (so we can start and stop the server directly from Eclipse). Second we change the "deploy-path" from proposed to the Tomcat default webapps directory (in our case &lt;b&gt;C:\Development\Tomcat\webapps&lt;/b&gt;) - it is the default directory where Tomcat keeps web applications. The third and final thing is to change the way Tomcat publish applications on the server - each application will have a separate xml configuration file in Tomcat (so-called "context" file).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Tomcat is &lt;b&gt;ready and configured to work&lt;/b&gt;. We can start and stop it using the icons on the right side in the "Servers" tab. The results of these operations (logs), are visible in the "Console" tab.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;NetBeans:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We do not need to install Tomcat under NetBeans  - provided that we followed instructions from &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html"&gt;this post&lt;/a&gt;. We should have Tomcat installed.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If we did not install Tomcat during NetBeans installation, we can do it similar like for Eclipse. Just unpack the Tomcat to specified directory, start NetBeans and go to the Tools -&amp;gt; Servers -&amp;gt; Add Server: &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FaVJjMopI/AAAAAAAAEaI/n5FvbRIsIdQ/s1600-h/NetBeans_Tomcat.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440729144227570322" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FaVJjMopI/AAAAAAAAEaI/n5FvbRIsIdQ/s320/NetBeans_Tomcat.PNG" style="cursor: pointer; display: block; height: 278px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The rest of the installation steps are similar to that of Eclipse and it should not cause trouble. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2513918842496832345?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2513918842496832345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2513918842496832345'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/05/konfiguracja-tomcata-w-eclipse.html' title='Installing and configuring Tomcat for Eclipse and NetBeans'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_JXxdCCKdTo0/S4FSwvkCIOI/AAAAAAAAEZo/VD3NH42PPP0/s72-c/Tomcat_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-3728034753407903954</id><published>2009-04-22T00:39:00.027+02:00</published><updated>2011-03-04T19:29:34.102+01:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Installing PostgreSQL (hard version)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;In a previous &lt;a href="http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-wersja-soft.html"&gt;post&lt;/a&gt; I showed how to install PostgreSQL using Windows installer. It was quite easy. But ...&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;There are people that do not play with such ease, what is more, they can not stand when the system is doing something for them in the background, when something is installed - some services, user accounts... They feel insecure, they are suspicious - only the execution of  all activities from the command line calms their nerves.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This time, I prepared the description for the people who love technical masturbation and who love to do everything manually and have everything under control. We'll become the PostgreSQL installer and manually execute all the installation steps to get an effect similar to using Windows Installer. So, let's get to work.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Requirements:&lt;/b&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;we are working on the account with Administrator rights (or we belong to the Administrators group)&lt;/li&gt;&lt;li&gt;database will be installed to &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;C:\Development\PostgreSQL&lt;/span&gt; (the same as when using Windows Installer)&lt;/li&gt;&lt;li&gt; disable all antivirus/firewall (this one from Windows too)&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; download the version of the installation file (.zip) of PostgreSQL from &lt;a href="http://www.postgresql.org/ftp/binary/v8.3.7/win32/"&gt;here&lt;/a&gt;. Download the file with the "binaries-no-installer" part in its name.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; extract the contents of the file from step 1, to &lt;b&gt;C:\Development\PostgreSQL&lt;/b&gt; (zip has the pgsql directory and rest of the folders inside it - I recommend to get rid of it and move all subfolders to C:\Development\PostgreSQL - we will have a shorter path). We should get something like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/Se5PKgc2l-I/AAAAAAAADiw/5mwug23ShJY/s1600-h/PostgreSQL_hard_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327282451154114530" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/Se5PKgc2l-I/AAAAAAAADiw/5mwug23ShJY/s320/PostgreSQL_hard_1.PNG" style="cursor: pointer; display: block; height: 248px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; we need to create an empty directory named "&lt;b&gt;data&lt;/b&gt;" in the directory C:\Development\PostgreSQL (along with the rest of the directories from the picture above).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; create and initialize the database cluster (remember that we are working on the account with Administrator rights). To do this go to the &lt;b&gt;console &lt;/b&gt;to the directory &lt;b&gt;C:\Development\PostgreSQL\bin&lt;/b&gt; and execute the command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5R2wZ_RWI/AAAAAAAADjI/AJmlBsiCjXQ/s1600-h/PostgreSQL_hard_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327285410374567266" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5R2wZ_RWI/AAAAAAAADjI/AJmlBsiCjXQ/s320/PostgreSQL_hard_5.PNG" style="cursor: pointer; display: block; height: 69px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Desription:&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;option "-U root" means the owner of the database named root - such user account will be created in database (as a superuser)&lt;/li&gt;&lt;li&gt;option "-W" means that You will be prompted for a password for this user&lt;/li&gt;&lt;li&gt;option "-D .. \ data" means the location of the files for generated database&lt;/li&gt;&lt;li&gt;option "- encoding = UTF8" means that the server will have UTF8 encoding by default (each newly created database too!) &lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;After executing this command, we should see sometling like this:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5TY7h39lI/AAAAAAAADjQ/Rt6B8o4DTz8/s1600-h/PostgreSQL_hard_6.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327287096987612754" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5TY7h39lI/AAAAAAAADjQ/Rt6B8o4DTz8/s320/PostgreSQL_hard_6.PNG" style="cursor: pointer; display: block; height: 286px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;At the bottom, PostgreSQL offers us to run a newly created database using two different commands. It &lt;b&gt;will not work&lt;/b&gt; (You can execute those command to see what error is generated) - remember that we are &lt;b&gt;working on account with Administrator rights&lt;/b&gt;, and for safety reasons, &lt;b&gt;we can not start and stop the PostgreSQL server&lt;/b&gt; on that account. We should create a &lt;b&gt;system service&lt;/b&gt; which will run PostgreSQL server process.&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;The short version:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; Perform the following command in the console:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/SpwrIWnigEI/AAAAAAAAEO4/BB-bsyVd610/s1600-h/PostgreSQL_hard_10.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5376219477683896386" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/SpwrIWnigEI/AAAAAAAAEO4/BB-bsyVd610/s400/PostgreSQL_hard_10.PNG" style="cursor: pointer; display: block; height: 78px; margin: 0px auto 10px; text-align: center; width: 400px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's all. You're done. The service will be created and registered for the &lt;b&gt;Local System Account&lt;/b&gt;. This is a special account which can run services, but it is not a typical account with administrator privileges (more info &lt;a href="http://msdn.microsoft.com/en-us/library/ms684190%28VS.85%29.aspx"&gt;here&lt;/a&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Do not run the service yet.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Long version:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; continue to imitate the installer. PostgreSQL installer creates a special account with no administrator privileges - so we will also create such account. Acount login and password will be both set to "postgres". We go to Computer Management, then Users:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/Se5QfAuh6oI/AAAAAAAADi4/GWCxzTGJ4Ys/s1600-h/PostgreSQL_hard_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327283902927202946" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/Se5QfAuh6oI/AAAAAAAADi4/GWCxzTGJ4Ys/s320/PostgreSQL_hard_2.PNG" style="cursor: pointer; display: block; height: 226px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now we add new user with login and password &lt;b&gt;postgres&lt;/b&gt;:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/Se5QpWsHLJI/AAAAAAAADjA/93nZM0GEIKQ/s1600-h/PostgreSQL_hard_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327284080621333650" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/Se5QpWsHLJI/AAAAAAAADjA/93nZM0GEIKQ/s320/PostgreSQL_hard_3.PNG" style="cursor: pointer; display: block; height: 320px; margin: 0px auto 10px; text-align: center; width: 310px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;For the security reason we &lt;b&gt;do not allow&lt;/b&gt; to change the password.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We would like now to &lt;b&gt;make "postgres" account able to run the PostgreSQL server&lt;/b&gt;. So we need to create and register a special service for this account, which will carry out these operations. Before we do that we need to assign to this account the &lt;b&gt;appropriate permissions&lt;/b&gt; to directories where database server is installed.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; Change the access permissions for the directory server for the postgres account.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;And so:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;1. Directory &lt;b&gt;C:\Development&lt;/b&gt; should &lt;b&gt;only have read permission&lt;/b&gt;. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;2. Directory &lt;b&gt;C:\Development\PostgreSQL&lt;/b&gt; (and its subdirectories) should have &lt;b&gt;all possible permissions&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 7:&lt;/b&gt; Registering the service.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Using the console go to the directory &lt;b&gt;C:\Development\PostgreSQL\bin&lt;/b&gt; and execute there this command:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5XTYRNjOI/AAAAAAAADjg/kuofrwajNmc/s1600-h/PostgreSQL_hard_7.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327291399669648610" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5XTYRNjOI/AAAAAAAADjg/kuofrwajNmc/s320/PostgreSQL_hard_7.PNG" style="cursor: pointer; display: block; height: 69px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Description:&lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;option -N "PostgreSQL Service" defines the service name&lt;/li&gt;&lt;li&gt;option -U postgres says on what account the service is launched&lt;/li&gt;&lt;li&gt;option -P postgres gives the password for service account&lt;/li&gt;&lt;li&gt;option -D "C:\Development\PostgreSQL\data" tells where database cluster is located (be careful it is very important here to give the &lt;b&gt;full path to the directory "data"&lt;/b&gt;) &lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;We do not run the service.&lt;/b&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;--------------------------------------------&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Configuration:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Before starting the service must change the basic settings. Move to the directory &lt;b&gt;C:\Development\PostgreSQL\database&lt;/b&gt; and open the file &lt;b&gt;postgresql.conf&lt;/b&gt;. In this file, You must find and &lt;b&gt;uncomment&lt;/b&gt; the following lines: &lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;listen_addresses = 'localhost'&lt;/li&gt;&lt;li&gt;port = 5432&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now You can start a service in the panel management services.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;If everything was done properly, the service should start. If we chose the longer version, in case of trouble with starting the service we should go to the configuration of a service, then select an account for this service and retype password for that service (in our case: postgres)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Theoretically we have the ability to log from the console to the database using the command line (marked red colour):&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5d9FB6PVI/AAAAAAAADjo/_DpvcQvsoXs/s1600-h/PostgreSQL_hard_9.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5327298713129467218" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Se5d9FB6PVI/AAAAAAAADjo/_DpvcQvsoXs/s320/PostgreSQL_hard_9.PNG" style="cursor: pointer; display: block; height: 200px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Thus we should get exactly the same result as using the Windows Installer.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Notes:&lt;/b&gt; a short way works ok under Windows XP Prof., should also works ok under Windows Vista - in both systems there is the Local System Account for services. For Windows 2000 You must perform the installation in a long way. For safety, PostgreSQL installer always chooses longer way - it creates an account for the service, then creates sevice itself and registers it to the created account.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-3728034753407903954?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3728034753407903954'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/3728034753407903954'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-hard.html' title='Installing PostgreSQL (hard version)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_JXxdCCKdTo0/Se5PKgc2l-I/AAAAAAAADiw/5mwug23ShJY/s72-c/PostgreSQL_hard_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-2564813730264176780</id><published>2009-04-19T19:17:00.016+02:00</published><updated>2010-05-31T23:25:08.237+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><title type='text'>Installing PostgreSQL (soft version)</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Installing PostgreSQL is theoretically piece of cake, but in my opinion there are some aspects worth saying a little more.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Those who installed MySQL database using the graphic installer on Windows, know that the installation process goes something like this: "Next, next, next, yes I want to have root access from remote machines, quit." This is almost the same as installing any program on Windows. PostgreSQL installer is not much more different in this case.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;So what's the point? In a slightly different philosophy of security model - different than in MySQL. Okay, enough of this pseudo-technological gibberish - let's install database.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; Download the PostgreSQL from &lt;a href="http://www.postgresql.org/ftp/binary/v8.3.7/win32/"&gt;here&lt;/a&gt;. Download a file named postgresql-8.3.7-1.zip.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; After unpacking the zip file, run the installer and choose English&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetiVRjdo1I/AAAAAAAADho/pijaSNSzL4Q/s1600-h/PostgreSQL_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326459101924664146" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetiVRjdo1I/AAAAAAAADho/pijaSNSzL4Q/s320/PostgreSQL_1.PNG" style="cursor: pointer; height: 246px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; after the splash screen and license information installer will ask us about the target installation directory. I suggest using directory &lt;b&gt;C:\Development\PostgreSQL&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/SetkYZImLeI/AAAAAAAADhw/uv2m_sAiE2Q/s1600-h/PostgreSQL_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326461354522324450" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/SetkYZImLeI/AAAAAAAADhw/uv2m_sAiE2Q/s320/PostgreSQL_2.PNG" style="cursor: pointer; height: 246px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; Configure account for the PostgreSQL service.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;It is convenient to install PostgreSQL as a service in Windows - the database server will always run at startup. We have something new in this point: PostgreSQL requires a special account in the system that &lt;b&gt;does not have  administrator rights&lt;/b&gt; in order to start the database service and initialize the database cluster. It is important to set a well-known password for this account, because in case of  problems with PostgreSQL we will be able to use this account to peform some fixes on database files.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/SetpgObkBAI/AAAAAAAADh4/wU8OX0rE4nM/s1600-h/PostgreSQL_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326466986646176770" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/SetpgObkBAI/AAAAAAAADh4/wU8OX0rE4nM/s320/PostgreSQL_3.PNG" style="cursor: pointer; display: block; height: 246px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 5:&lt;/b&gt; configure the settings of the database server, super user account (root) and access from remote machines.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;This is a step similar to step in the installation of MySQL, I recommend setting the server and client encoding to UTF-8 - this is the standard that should be use instead of some bizarre national encoding. Why? Because it gives us the flexibility - perhaps we want to store in our database accented Polish and German umlauts. In addition we will avoid potential problems with conversions etc.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/Setq1kqmQQI/AAAAAAAADiA/4Maku-NYGfU/s1600-h/PostgreSQL_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326468452903698690" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/Setq1kqmQQI/AAAAAAAADiA/4Maku-NYGfU/s320/PostgreSQL_4.PNG" style="cursor: pointer; display: block; height: 246px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 6:&lt;/b&gt; Installation.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Warning:&lt;/b&gt; before installation make sure that You have enabled and running Windows service named "Secondary Logon". Our system account "postgres" from step 4 needs that service. When it is not enabled, the installer will report an error:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; font-family: Verdana,sans-serif; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/TAQPh-PE8II/AAAAAAAAEkg/ipvsX5ouFsM/s1600/PostgreSQL_5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/TAQPh-PE8II/AAAAAAAAEkg/ipvsX5ouFsM/s320/PostgreSQL_5.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Just turn on the service and the trouble is gone. Then on next screens just click "Next" without changing anything until You get to the last screen - the final step in our installation process.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 7:&lt;/b&gt; The end of the installation.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetsPsUQYEI/AAAAAAAADiQ/_FgQssZ5OQ4/s1600-h/PostgreSQL_6.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326470001145700418" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetsPsUQYEI/AAAAAAAADiQ/_FgQssZ5OQ4/s320/PostgreSQL_6.PNG" style="cursor: pointer; display: block; height: 246px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The selected checkbox allows You to install additional software and extensions for PostgreSQL. At the moment we do not need them so we can safely uncheck it and complete the installation - voila, we have PostgresSQL :-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Okay, once we have database installed, let's take a look inside - just to write simple SELECT and be proud of Yourself that You still remember some SQL syntax ;-) Nothing could be more simple. Along with PostgreSQL was installed pgAdminIII - an advanced graphical client. Just find it in the windows start menu and run:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetxwJN6fJI/AAAAAAAADiY/aH0gwg-sE94/s1600-h/PostgreSQL_7.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326476056217681042" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SetxwJN6fJI/AAAAAAAADiY/aH0gwg-sE94/s320/PostgreSQL_7.PNG" style="cursor: pointer; display: block; height: 228px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;When You double-click the server, You will be asked for Your root password from step 5. After typing the correct password, You will be logged to the server as root (superuser):&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/SetylgY7EZI/AAAAAAAADig/5LWjZCQpVjg/s1600-h/PostgreSQL_8.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5326476972970938770" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/SetylgY7EZI/AAAAAAAADig/5LWjZCQpVjg/s320/PostgreSQL_8.PNG" style="cursor: pointer; display: block; height: 228px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;PostgreSQL creates a default database named "postgres". We can log in to this default database using command line. Of course, we can also delete this database. Then we have available two more so-called "service" databases that are hidden (they are not visible by default in pgAdmin tree view). The names of those databases are "template0" and "template1". PgAdmin allows us to configure the server, manage users, roles, databases, etc. For details, refer to the &lt;a href="http://www.pgadmin.org/docs/"&gt;documentation&lt;/a&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-2564813730264176780?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2564813730264176780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/2564813730264176780'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/instalacja-postgresql-wersja-soft.html' title='Installing PostgreSQL (soft version)'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_JXxdCCKdTo0/SetiVRjdo1I/AAAAAAAADho/pijaSNSzL4Q/s72-c/PostgreSQL_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-6445020709736739864</id><published>2009-04-18T00:40:00.030+02:00</published><updated>2011-07-26T21:21:08.978+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><title type='text'>IDE (Eclipse &amp; NetBeans) installation, configuring Java for both</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;Well ... There is really no big deal here.&amp;nbsp; But in order to follow the rules from initial post I will describe how to "install" (in this case is a strong word ;-)) Eclipse Galileo and NetBeans 6.8 and configure it to work with previously installed JDK (JDK install as described here). So:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;------------------------------------------- &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;Eclipse:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; Download the latest Eclipse. Download exactly the Eclipse IDE for Java EE Developers &lt;b&gt;(use current Eclipse Indigo version - edited on Tuesday, July 26, 2011)&lt;/b&gt;. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; Once we have the Eclipse, unpack the package to &lt;b&gt;C:\Development\Eclipse&lt;/b&gt; - and that's all Eclipse is installed :-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Now it's time for a basis configuration:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 1:&lt;/b&gt; After first startup Eclipse will ask us where we want to put the workspace directory. I suggest using this directory &lt;b&gt;C:\Development\Eclipse_Workspace&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekKyGXodLI/AAAAAAAADgY/QvlhsRqOvEw/s1600-h/Eclipse_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325799890161792178" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekKyGXodLI/AAAAAAAADgY/QvlhsRqOvEw/s320/Eclipse_1.PNG" style="height: 182px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 2:&lt;/b&gt; After closing welcome screen, Eclipse will stay with default Java EE view perspective. It is OK, now it's the time to configure JDK. go to the Window -&amp;gt; Preferences menu and select:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/SekLgwQC2UI/AAAAAAAADgg/FIpeclC35N4/s1600-h/Eclipse_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325800691678239042" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/SekLgwQC2UI/AAAAAAAADgg/FIpeclC35N4/s320/Eclipse_2.PNG" style="cursor: pointer; height: 226px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 3:&lt;/b&gt; adding new standard virtual machine (JVM).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekL2XMD6zI/AAAAAAAADgo/bAlk7HKp8f0/s1600-h/Eclipse_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325801062907767602" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekL2XMD6zI/AAAAAAAADgo/bAlk7HKp8f0/s320/Eclipse_3.PNG" style="cursor: pointer; height: 284px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 4:&lt;/b&gt; we show the location of our previously installed JDK (description of the installation here).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/SekMfFVfAFI/AAAAAAAADgw/7BltOtXJaB0/s1600-h/Eclipse_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325801762490089554" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/SekMfFVfAFI/AAAAAAAADgw/7BltOtXJaB0/s320/Eclipse_4.PNG" style="cursor: pointer; height: 320px; width: 313px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/SekMlvp3lZI/AAAAAAAADg4/hQt9SbJEnn8/s1600-h/Eclipse_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325801876929090962" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/SekMlvp3lZI/AAAAAAAADg4/hQt9SbJEnn8/s320/Eclipse_5.PNG" style="cursor: pointer; height: 320px; width: 266px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekM8I1wMCI/AAAAAAAADhA/IO4cbBAzpLE/s1600-h/Eclipse_6.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325802261646946338" src="http://4.bp.blogspot.com/_JXxdCCKdTo0/SekM8I1wMCI/AAAAAAAADhA/IO4cbBAzpLE/s320/Eclipse_6.PNG" style="cursor: pointer; height: 320px; width: 313px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 5:&lt;/b&gt; switch to the installed JDK.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/SekNGDDeOYI/AAAAAAAADhI/6l5w-iiJdd4/s1600-h/Eclipse_7.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325802431892568450" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/SekNGDDeOYI/AAAAAAAADhI/6l5w-iiJdd4/s320/Eclipse_7.PNG" style="cursor: pointer; height: 226px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Configuration Step 6:&lt;/b&gt; Configure Eclipse startup parameters.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Search for the &lt;b&gt;eclipse.ini&lt;/b&gt; file and &lt;b&gt;at the beginning of the file add these&lt;/b&gt; &lt;b&gt;two&lt;/b&gt; (yes two!) lines:&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;i&gt;-vm&lt;/i&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;i&gt;C:\Development\Java\bin&lt;/i&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;By doing this we set the default virtual machine which Eclipse uses. Please note that this is &lt;b&gt;exactly the same Java JDK which was configured in the above step 4&lt;/b&gt; (here in addition we point into directory "bin").&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Eclipse is installed and ready for use.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;-------------------------------------------  &lt;/div&gt;&lt;div style="color: red; font-family: Verdana,sans-serif;"&gt;NetBeans:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;NetBeans (unlike the Eclipse) has the &lt;b&gt;graphic installer&lt;/b&gt; which allows to configure this IDE during installation process. Let's see how it looks like:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; Download the latest NetBeans. Download the &lt;b&gt;exact version for Java&lt;/b&gt; (&lt;b&gt;not&lt;/b&gt; for Java SE).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; Run the installer:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FDyNiFXfI/AAAAAAAAEYg/8_WD-ZHjQK8/s1600-h/NetBeans_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440704354745409010" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FDyNiFXfI/AAAAAAAAEYg/8_WD-ZHjQK8/s320/NetBeans_1.PNG" style="cursor: pointer; display: block; height: 240px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;The installer shows us what we want to install, along with predefined servers. Let's change a bit this list by selecting "Customize":&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FEztADe1I/AAAAAAAAEYo/YAb91mK28Kw/s1600-h/NetBeans_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440705479884110674" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FEztADe1I/AAAAAAAAEYo/YAb91mK28Kw/s320/NetBeans_2.PNG" style="cursor: pointer; display: block; height: 249px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We throw support for Groovy, and we add &lt;b&gt;Tomcat 6.0.20&lt;/b&gt; (included with the NetBeans as GlassFish).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; Setting target installation directory for NetBeans, and setting Java installation directory which denotes what Java will be used to work with NetBeans - please note that this is &lt;b&gt;the same Java JDK like for Eclipse above&lt;/b&gt;. NetBeans automatically finds this JDK based on the variable &lt;b&gt;JAVA_HOME&lt;/b&gt; (we created this variable during JDK installation).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4FFnoHEv6I/AAAAAAAAEYw/TSIvmikIbBc/s1600-h/NetBeans_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440706371924574114" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/S4FFnoHEv6I/AAAAAAAAEYw/TSIvmikIbBc/s320/NetBeans_3.PNG" style="cursor: pointer; display: block; height: 240px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; Configure the installation directory for the installed servers (Tomcat 6.0.20 and GlassFish v3)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FJXFjZOBI/AAAAAAAAEY4/ZrJRqcMB018/s1600-h/NetBeans_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440710485816719378" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FJXFjZOBI/AAAAAAAAEY4/ZrJRqcMB018/s320/NetBeans_4.PNG" style="cursor: pointer; display: block; height: 240px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FJbteD7lI/AAAAAAAAEZA/boPwA7RJyc8/s1600-h/NetBeans_5.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5440710565251247698" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/S4FJbteD7lI/AAAAAAAAEZA/boPwA7RJyc8/s320/NetBeans_5.PNG" style="cursor: pointer; display: block; height: 240px; margin: 0px auto 10px; text-align: center; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;An that's all. The installer should install the IDE and notify us about successful installation at the end. After first startup it is worth to check installed plugins and if they are enabled or not (especially&lt;b&gt; Java Web and EE plugin&lt;/b&gt;). In order to do this, go to Tools -&amp;gt; Plugins -&amp;gt; Installed. Make sure that all plugins are &lt;b&gt;enabled&lt;/b&gt;.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-6445020709736739864?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/6445020709736739864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/6445020709736739864'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/instalacja-i-konfiguracja-ide-eclipse.html' title='IDE (Eclipse &amp; NetBeans) installation, configuring Java for both'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_JXxdCCKdTo0/SekKyGXodLI/AAAAAAAADgY/QvlhsRqOvEw/s72-c/Eclipse_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-1686064352566373009</id><published>2009-04-17T23:55:00.031+02:00</published><updated>2010-05-31T23:20:56.154+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><title type='text'>Installing Java</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;It may seem that installing Java is a piece of cake. Really? Let's see ...&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 1:&lt;/b&gt; Download the Java JDK from here. Download exactly Java SE Development Kit (JDK), without any additives inside (bundles) - just regular JDK.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 2:&lt;/b&gt; We start the installation. After two (or maybe three) screens we come to the screen where we choose the installation location. Let's change the target directory to &lt;b&gt;C:\Development\Java&lt;/b&gt;:&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div align="center"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej8wKveFAI/AAAAAAAADf4/xbGkGaqGmZM/s1600-h/Java_Install_1.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325784463812989954" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej8wKveFAI/AAAAAAAADf4/xbGkGaqGmZM/s320/Java_Install_1.PNG" style="cursor: pointer; height: 243px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div align="center"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej82VNdvEI/AAAAAAAADgA/tX2_xRR-ayw/s1600-h/Java_Install_2.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325784569702366274" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej82VNdvEI/AAAAAAAADgA/tX2_xRR-ayw/s320/Java_Install_2.PNG" style="height: 243px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 3:&lt;/b&gt; throw away the Java DB database  - we will use our database (it saves about 25MB on disk - better than nothing&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div align="center"&gt;&lt;a href="http://2.bp.blogspot.com/_JXxdCCKdTo0/Sej9bBzHM9I/AAAAAAAADgI/zl2nZw8ecl4/s1600-h/Java_Install_3.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325785200146723794" src="http://2.bp.blogspot.com/_JXxdCCKdTo0/Sej9bBzHM9I/AAAAAAAADgI/zl2nZw8ecl4/s320/Java_Install_3.PNG" style="height: 242px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Step 4:&lt;/b&gt; Install the virtual machine (JRE) for the browser - leave the default target unchanged (&lt;b&gt;C:\Program Files\...&lt;/b&gt;).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;div align="center"&gt;&lt;a href="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej97cIZ9iI/AAAAAAAADgQ/EAnv_ZfUTPE/s1600-h/Java_Install_4.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325785756971169314" src="http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej97cIZ9iI/AAAAAAAADgQ/EAnv_ZfUTPE/s320/Java_Install_4.PNG" style="height: 243px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;So far so good and suddenly ... I got the &lt;b&gt;magic error message at the last stage of installation (JRE)&lt;/b&gt; - something about a  broken installer. I ignored it by clicking OK. In theory, the  installation is completed. But I looked inside "Add/remove  programs" under Windows just to check my new JRE - and I see no JRE (although JDK was present)...&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;I uninstalled Java and I moved installer file from the desktop directly to the C drive. I repeated the whole installation procedure - this time without any problems. Perhaps it was something with white spaces in my path to the Desktop (&lt;b&gt;C:\Documents and Settings&lt;/b&gt;) where I run the JDK installer. Like I wrote here - it's better not to use paths with whitespaces.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;span style="font-weight: bold;"&gt;Step 5:&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;We create new system variable named &lt;span style="font-weight: bold;"&gt;JAVA_HOME&lt;/span&gt; and we set its value to &lt;span style="font-weight: bold;"&gt;C:\Development\Java&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-1686064352566373009?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1686064352566373009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/1686064352566373009'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/instalacja-java-jdk-prawie-bezbolesna.html' title='Installing Java'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_JXxdCCKdTo0/Sej8wKveFAI/AAAAAAAADf4/xbGkGaqGmZM/s72-c/Java_Install_1.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-5865708710246057818</id><published>2009-04-17T22:44:00.014+02:00</published><updated>2010-05-31T23:18:43.487+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tools'/><title type='text'>Gather all hammers inside toolbox.</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;As I wrote in my first post, we will start from installing the  &lt;b&gt;necessary tools&lt;/b&gt;. What are we going to install? For today, it will be  (when I get something new this post will be changed): &lt;/div&gt;&lt;ul style="font-family: Verdana,sans-serif;"&gt;&lt;li&gt;Java JDK&lt;/li&gt;&lt;li&gt;Eclipse IDE and NetBeans IDE&lt;/li&gt;&lt;li&gt;PostgreSQL database&lt;/li&gt;&lt;li&gt;Apache Tomcat and GlassFish&lt;/li&gt;&lt;/ul&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Some  comments why we need those tools. Well, for Java JDK comment is  probably redundant. I will use certain IDE I depending on the problem  and offered improvements&amp;nbsp; - and sometimes depending on my mood ;-).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;PostgreSQL  - why just this database ("everyone knows that MySQL is the best,  fastest and for free")? It is my &lt;b&gt;personal choice&lt;/b&gt; - I used those two  databases, but it seems to me that PostgreSQL is more polished and more  meets my needs. And most important: it is completely free (I am not sure  if MySQL is free for every case). Okay it is clear, but why do we need a  database? Just in case we would like to write some sophisticated data  storing application. Database will be very useful in such case ;-).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Okay,  but what about Tomcat or GlassFish? Do we need them? Yes we do - just  in case we would like to move our super data storing application into  the internet (meaning: create another online store and earn a lot of  money ;-)). For the most of examples (connected with web applications)  Tomcat will be sufficient, but when it's time for something complicated  and we need a real application server, GlassFish will be used (or maybe  even JBoss).&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Okay okay, but where should we install  those tools? In order to have consistent solution I suggest &lt;b&gt;put  everything in one directory&lt;/b&gt;, and create some subdirectory structure  inside.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="center" style="font-family: Verdana,sans-serif;"&gt;&lt;a href="http://3.bp.blogspot.com/_JXxdCCKdTo0/Sej0lPdk19I/AAAAAAAADfw/EWw70rgFkP0/s1600-h/katalogi.PNG" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img alt="" border="0" id="BLOGGER_PHOTO_ID_5325775480008529874" src="http://3.bp.blogspot.com/_JXxdCCKdTo0/Sej0lPdk19I/AAAAAAAADfw/EWw70rgFkP0/s320/katalogi.PNG" style="height: 273px; width: 320px;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;As  You see I decided to put everything inside directory named  "Development" on my C drive - &lt;b&gt;C:\Development&lt;/b&gt;.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;b&gt;Good  advice for the future:&lt;/b&gt; do &lt;b&gt;not&lt;/b&gt; use paths with whitespaces and any  national characters. This will save our time for searching and fixing  some X-Files problems ;-).&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-5865708710246057818?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5865708710246057818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/5865708710246057818'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/zbieramy-motki-do-skrzynki-narzedziowej.html' title='Gather all hammers inside toolbox.'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_JXxdCCKdTo0/Sej0lPdk19I/AAAAAAAADfw/EWw70rgFkP0/s72-c/katalogi.PNG' height='72' width='72'/></entry><entry><id>tag:blogger.com,1999:blog-160318223199333541.post-7220744110281231915</id><published>2009-04-17T22:03:00.008+02:00</published><updated>2010-05-31T23:17:35.261+02:00</updated><title type='text'>The Beginning</title><content type='html'>&lt;div style="font-family: Verdana,sans-serif;"&gt;First of all I would like to apologize for my english. I decided to  write this blog in english for one simple reason - more people will find  it and read it ;-)&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;You should already now  what is the idea of this blog (if not, You can read about it on the  left). I assume that You did something using Java and You have a minimum  knowledge of the language itself. But even if You do not, You may find  some articles useful for understanding the Java language and other  technologies. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;How will it look like? At the  beginning we need a &lt;b&gt;workshop and tools&lt;/b&gt;. I intend to show You how to  install everything from scratch in order to be able to do anything with  some frameworks, libraries, etc. In other words: I will start with  &lt;b&gt;well-known "Hello World"&lt;/b&gt;. After that I will add some bricks to build the  whole wall: extend existing threads by adding new issues, wrote about  the potential problems and so on - towards the complete solution. &lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;Why  do all of this on such elementary level? Because sometimes &lt;b&gt;the basics  are the worst problem to solve&lt;/b&gt; - it is often enough to discourage  someone and cause him to give up. Perhaps we loose potential genius...  who knows?&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;My goal is that all examples  shown here are possible to execute by Yourself. Their purpose is to  serve as a quick-start for something more serious.&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;&lt;/div&gt;&lt;div style="font-family: Verdana,sans-serif;"&gt;That's  all. Let the mortal combat begin...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/160318223199333541-7220744110281231915?l=technology-for-human.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7220744110281231915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/160318223199333541/posts/default/7220744110281231915'/><link rel='alternate' type='text/html' href='http://technology-for-human.blogspot.com/2009/04/na-poczatku-byo-sowo.html' title='The Beginning'/><author><name>Pawel</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='29' src='http://4.bp.blogspot.com/_JXxdCCKdTo0/Sejf3dBMgPI/AAAAAAAADfM/LmTZlY3OkSk/S220/pawel.PNG'/></author></entry></feed>
