<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>samaxes</title>
	
	<link>http://www.samaxes.com</link>
	<description>Ramblings about Open Source, Java and other Web technologies by Samuel Santos</description>
	<pubDate>Mon, 28 Dec 2009 19:50:04 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/samaxes" /><feedburner:info uri="samaxes" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Run PHP on Google App Engine</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/EaVugmPtYQ8/</link>
		<comments>http://www.samaxes.com/2009/12/php-on-google-app-engine/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 15:24:44 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[App Engine]]></category>

		<category><![CDATA[Google]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Quercus]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=209</guid>
		<description><![CDATA[By adding Java to their App Engine, Google has opened the door for a whole slew of languages that have been implemented on the JVM, now including PHP via Quercus.
This weekend I decided to give it a try and deploy a (very) old tutorial of mine - PHP Tutorial - on GAE.
I must admit that [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://blog.caucho.com/?p=187"><p>By adding Java to their App Engine, Google has opened the door for a whole slew of languages that have been implemented on the JVM, now including PHP via Quercus.</p></blockquote>
<p>This weekend I decided to give it a try and deploy a (very) old tutorial of mine - <a href="http://php-tutorials.appspot.com/">PHP Tutorial</a> - on <abbr title="Google App Engine">GAE</abbr>.</p>
<p>I must admit that I was very pleasantly surprised by how effortless it was. OK, it&#8217;s a very rudimentary PHP application, the only PHP code used was to run the examples described on the code blocks and do some includes; nevertheless I didn&#8217;t feel the need to change a single line of code.</p>
<p>Also, deploying a Java application to GAE is simpler than a Python one. Not only because you have a very handy Eclipse plugin, but you will also find configuring the file <code>appengine-web.xml</code> a lot easier when compared to <code>app.yaml</code>.</p>
<p>All you need to do in order to deploy a PHP application, at least as simple as the one I&#8217;ve tried, is to follow these steps:<br />
<span id="more-209"></span></p>
<ol>
<li>Install <a href="http://code.google.com/appengine/docs/java/tools/eclipse.html">Google Plugin for Eclipse</a>.</li>
<li>Create a Web Application Project in eclipse. The complete project directory looks like this:
<pre>Guestbook/
  src/
    <em>...Java source code...</em>
    META-INF/
      <em>...other configuration...</em>
  war/
    <em>...JSPs, images, data files...</em>
    WEB-INF/
      <em>...app configuration...</em>
      lib/
        <em>...JARs for libraries...</em>
      classes/
        <em>...compiled classes...</em>
</pre>
</li>
<li>Copy all your PHP and static files to <code>your-project/war</code>.</li>
<li>Download <a href="http://quercus.caucho.com/">Quercus binary</a> (WAR file).</li>
<li>Unzip it and copy all files inside <code>quercus.war/WEB-INF/lib</code> to <code>your-project/war/WEB-INF/lib</code>.</li>
<li>Edit your deployment descriptor file <code>web.xml</code>. Mine looks like this:

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=209&amp;download=web.xml">web.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2093"><td class="code" id="p209code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span> <span style="color: #000066;">xmlns:web</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>PHP Tutorial<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Quercus Servlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.caucho.quercus.servlet.GoogleQuercusServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Quercus Servlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>index.php<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/welcome-file-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>Edit your configuration file <code>appengine-web.xml</code>. Mine looks like this:

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=209&amp;download=appengine-web.xml">appengine-web.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2094"><td class="code" id="p209code4"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appengine-web-app</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://appengine.google.com/ns/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>php-tutorials<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Configure java.util.logging --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;java.util.logging.config.file&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WEB-INF/logging.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;static-files<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;600s&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.png&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;30d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.jpg&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;30d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.gif&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;30d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.ico&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;30d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.swf&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;30d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.css&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;7d&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.js&quot;</span> <span style="color: #000066;">expiration</span>=<span style="color: #ff0000;">&quot;2d 12h&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.inc&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/static-files<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-files<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/**.inc&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-files<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appengine-web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
</ol>
<p>Et voilà, you are done!</p>
<p>Now, run your application using the <code>Run As >> Web Application</code> command.<br />
And finally, press the &#8220;Deploy App Engine Project&#8221; button to deploy to GAE.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2007/07/jboss-web-and-php-install-tutorial/" title="JBoss Web and PHP Install Tutorial">JBoss Web and PHP Install Tutorial</a></li><li><a href="http://www.samaxes.com/2007/07/creating-offline-web-applications-with-dojo-offline-tutorial/" title="Creating Offline Web Applications with Dojo Offline Tutorial">Creating Offline Web Applications with Dojo Offline Tutorial</a></li><li><a href="http://www.samaxes.com/2007/05/more-on-offline-web-applications-google-gears/" title="More on offline web applications - Google Gears">More on offline web applications - Google Gears</a></li><li><a href="http://www.samaxes.com/2007/05/web-php-framework-symfony/" title="Web PHP framework - symfony">Web PHP framework - symfony</a></li><li><a href="http://www.samaxes.com/2006/12/birt-and-php-reporting/" title="BIRT and PHP Reporting">BIRT and PHP Reporting</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=EaVugmPtYQ8:xxtWeoxK5kM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=EaVugmPtYQ8:xxtWeoxK5kM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=EaVugmPtYQ8:xxtWeoxK5kM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=EaVugmPtYQ8:xxtWeoxK5kM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=EaVugmPtYQ8:xxtWeoxK5kM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=EaVugmPtYQ8:xxtWeoxK5kM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=EaVugmPtYQ8:xxtWeoxK5kM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=EaVugmPtYQ8:xxtWeoxK5kM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=EaVugmPtYQ8:xxtWeoxK5kM:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/EaVugmPtYQ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/12/php-on-google-app-engine/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/12/php-on-google-app-engine/</feedburner:origLink></item>
		<item>
		<title>W3C Widgets Compatibility Matrix for Packaging and Configuration</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/_Rjycu8vVY4/</link>
		<comments>http://www.samaxes.com/2009/11/w3c-widgets-compatibility-matrix/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 00:17:40 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Standards]]></category>

		<category><![CDATA[W3C]]></category>

		<category><![CDATA[Widgets]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=207</guid>
		<description><![CDATA[Daniel Silva, Marcos Caceres and myself have completed Phase 1 of Widgets 1.0: Packaging and Configuration compatibility testing. We have also detailed the results as part of the conformance matrix.
We would like to publish the results as a working group note. Phase 2 will begin in about 3 weeks, in which we are hoping to [...]]]></description>
			<content:encoded><![CDATA[<p>Daniel Silva, <a href="http://datadriven.com.au/">Marcos Caceres</a> and myself have completed Phase 1 of <a href="http://www.w3.org/TR/widgets/">Widgets 1.0: Packaging and Configuration</a> compatibility testing. We have also detailed the results as part of the conformance matrix.<br />
We would like to publish the results as a working group note. Phase 2 will begin in about 3 weeks, in which we are hoping to start working with vendors to improve overall conformance.</p>
<p>We need help with Phase 2: if you know a team contact for any of the targeted products that are claiming conformance to W3C Widgets, then would appreciate your help in making them aware of the results of the testing - <a href="http://samaxes.svn.beanstalkapp.com/widgets_compatibility_matrix/trunk/index.html">Widgets 1.0: Compatibility Matrix for Packaging and Configuration</a>.</p>
<h3  class="related_post_title">Popular Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2008/04/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/" title=".htaccess - gzip and cache your site for faster loading and bandwidth saving">.htaccess - gzip and cache your site for faster loading and bandwidth saving</a></li><li><a href="http://www.samaxes.com/2008/12/stripes-and-jquery-autocomplete/" title="Stripes and jQuery Autocomplete">Stripes and jQuery Autocomplete</a></li><li><a href="http://www.samaxes.com/2006/08/deploying-birt-report-engine-api-with-jakarta-struts/" title="Deploying BIRT Report Engine API with Jakarta Struts">Deploying BIRT Report Engine API with Jakarta Struts</a></li><li><a href="http://www.samaxes.com/2008/01/stripes-and-ejb3/" title="Stripes and EJB3">Stripes and EJB3</a></li><li><a href="http://www.samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/" title="More on compressing and caching your site with .htaccess">More on compressing and caching your site with .htaccess</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=_Rjycu8vVY4:Cbw7LQxXulw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_Rjycu8vVY4:Cbw7LQxXulw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_Rjycu8vVY4:Cbw7LQxXulw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_Rjycu8vVY4:Cbw7LQxXulw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_Rjycu8vVY4:Cbw7LQxXulw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_Rjycu8vVY4:Cbw7LQxXulw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_Rjycu8vVY4:Cbw7LQxXulw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_Rjycu8vVY4:Cbw7LQxXulw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_Rjycu8vVY4:Cbw7LQxXulw:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/_Rjycu8vVY4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/11/w3c-widgets-compatibility-matrix/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/11/w3c-widgets-compatibility-matrix/</feedburner:origLink></item>
		<item>
		<title>Java Web Development with Stripes</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/O4wvqo0EMbQ/</link>
		<comments>http://www.samaxes.com/2009/09/java-web-development-with-stripes/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 23:41:33 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Stripes]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=197</guid>
		<description><![CDATA[Stripes Framework presentation for the Portuguese Java User Group session on the JavaPT09 event.
The used source code is also available.
Java Web Development with Stripes
View more documents from Samuel Santos.

Related PostsStripes and jQuery AutocompleteStripes and jQuery: AJAX forms and HTTP Session ValidationBIRT/Stripes exampleStripes and EJB3Deploying BIRT Report Engine API with Stripes]]></description>
			<content:encoded><![CDATA[<p>Stripes Framework presentation for the Portuguese Java User Group session on the JavaPT09 event.</p>
<p>The used <a href="http://samaxes.appspot.com/zip/javapt09-stripes-code-example.zip">source code</a> is also available.</p>
<div style="width:425px;text-align:left" id="__ss_2014777"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/samaxes/java-web-development-with-stripes" title="Java Web Development with Stripes">Java Web Development with Stripes</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=stripes-javapt09-090917183807-phpapp01&#038;stripped_title=java-web-development-with-stripes" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=stripes-javapt09-090917183807-phpapp01&#038;stripped_title=java-web-development-with-stripes" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">documents</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/samaxes">Samuel Santos</a>.</div>
</div>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2008/12/stripes-and-jquery-autocomplete/" title="Stripes and jQuery Autocomplete">Stripes and jQuery Autocomplete</a></li><li><a href="http://www.samaxes.com/2008/10/stripes-and-jquery-ajax-forms-and-http-session-validation/" title="Stripes and jQuery: AJAX forms and HTTP Session Validation">Stripes and jQuery: AJAX forms and HTTP Session Validation</a></li><li><a href="http://www.samaxes.com/2008/06/birt-stripes-example/" title="BIRT/Stripes example">BIRT/Stripes example</a></li><li><a href="http://www.samaxes.com/2008/01/stripes-and-ejb3/" title="Stripes and EJB3">Stripes and EJB3</a></li><li><a href="http://www.samaxes.com/2007/04/deploying-birt-report-engine-api-with-stripes/" title="Deploying BIRT Report Engine API with Stripes">Deploying BIRT Report Engine API with Stripes</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=O4wvqo0EMbQ:y4zoil-KsS0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=O4wvqo0EMbQ:y4zoil-KsS0:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=O4wvqo0EMbQ:y4zoil-KsS0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=O4wvqo0EMbQ:y4zoil-KsS0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=O4wvqo0EMbQ:y4zoil-KsS0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=O4wvqo0EMbQ:y4zoil-KsS0:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=O4wvqo0EMbQ:y4zoil-KsS0:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=O4wvqo0EMbQ:y4zoil-KsS0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=O4wvqo0EMbQ:y4zoil-KsS0:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/O4wvqo0EMbQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/09/java-web-development-with-stripes/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/09/java-web-development-with-stripes/</feedburner:origLink></item>
		<item>
		<title>Unit Testing JBoss 5 Services</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/D7aViOk9_7s/</link>
		<comments>http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 13:02:45 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JBoss]]></category>

		<category><![CDATA[Microcontainer]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=196</guid>
		<description><![CDATA[The JBoss Microcontainer is a refactoring of JBoss&#8217;s JMX Microkernel to support direct POJO deployment and standalone use outside the JBoss application server.
It allows the creation of services using simple Plain Old Java Objects (POJOs) to be deployed into a standard Java SE runtime environment.
JBoss Microcontainer uses dependency injection to wire individual POJOs together to [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://jboss.org/jbossmc/">JBoss Microcontainer</a> is a refactoring of JBoss&#8217;s JMX Microkernel to support direct POJO deployment and standalone use outside the JBoss application server.<br />
It allows the creation of services using simple Plain Old Java Objects (POJOs) to be deployed into a standard Java SE runtime environment.</p>
<blockquote cite="http://jboss.org/file-access/default/members/jbossmc/freezone/docs/2.0.x/userGuide/overview.html"><p>JBoss Microcontainer uses dependency injection to wire individual POJOs together to create services. Configuration is performed using either annotations or XML depending on where the information is best located.</p></blockquote>
<p>The goal of this article is to show how easy it is to test these services using <a href="http://testng.org/">TestNG</a> testing framework.<br />
<span id="more-196"></span></p>
<h3>Configuring a service</h3>
<p><code>PersonService</code> is a simple POJO that doesn&#8217;t implement any special interfaces.<br />
It has two properties, <code>firstName</code> and <code>lastName</code>, that are inject through a XML deployment descriptor.<br />
The public method that clients will call is <code>getName()</code> and returns the person full name.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=196&amp;download=PersonService.java">PersonService.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19610"><td class="code" id="p196code10"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonService <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> firstName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> lastName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setFirstName<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> firstName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">firstName</span> = firstName<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> lastName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastName</span> = lastName<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> firstName + <span style="color: #0000ff;">&quot; &quot;</span> + lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Instances of this service are created by creating an XML deployment descriptor that contains a list of beans representing individual instances.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=196&amp;download=jboss-beans.xml">jboss-beans.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19611"><td class="code" id="p196code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deployment</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:jboss:bean-deployer:2.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bean</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;PersonService&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.samaxes.jboss.service.plain.PersonService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Samuel<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Santos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/deployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>We have just declared that we want to create an instance of the PersonService class and register it with the name <code>PersonService</code>. This file is passed to an XML deployer associated with the microcontainer at runtime to perform the actual deployment and instantiate the beans.</p>
<h3>Testing a service</h3>
<p>JBoss Microcontainer makes it extremely easy to unit test services.<br />
First, you need to create an <code>EmbeddedBootstrap</code> class and override the protected <code>bootstrap()</code> method.<br />
This allows you to created an instance of JBoss Microcontainer together with an XML deployer.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=196&amp;download=EmbeddedBootstrap.java">EmbeddedBootstrap.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19612"><td class="code" id="p196code12"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> EmbeddedBootstrap <span style="color: #000000; font-weight: bold;">extends</span> BasicBootstrap <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> BasicXMLDeployer deployer<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> EmbeddedBootstrap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Exception.html"><span style="color: #003399; font-weight: bold;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> bootstrap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Throwable.html"><span style="color: #003399; font-weight: bold;">Throwable</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        deployer = <span style="color: #000000; font-weight: bold;">new</span> BasicXMLDeployer<span style="color: #009900;">&#40;</span>getKernel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Runtime.html"><span style="color: #003399; font-weight: bold;">Runtime</span></a>.<span style="color: #006633;">getRuntime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">addShutdownHook</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Shutdown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> deploy<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/net/URL.html"><span style="color: #003399; font-weight: bold;">URL</span></a> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Workaround the fact that the BasicXMLDeployer does not handle redeployment correctly</span>
            <span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>deployer.<span style="color: #006633;">getDeploymentNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Service is already deployed.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            deployer.<span style="color: #006633;">deploy</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Throwable.html"><span style="color: #003399; font-weight: bold;">Throwable</span></a> t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error during deployment: &quot;</span> + url, t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> undeploy<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/net/URL.html"><span style="color: #003399; font-weight: bold;">URL</span></a> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000;  font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>deployer.<span style="color: #006633;">getDeploymentNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Service is already undeployed.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            deployer.<span style="color: #006633;">undeploy</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Throwable.html"><span style="color: #003399; font-weight: bold;">Throwable</span></a> t<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">warn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error during undeployment: &quot;</span> + url, t<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">class</span> Shutdown <span style="color: #000000; font-weight: bold;">extends</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Thread.html"><span style="color: #003399; font-weight: bold;">Thread</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Shutting down&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            deployer.<span style="color: #006633;">shutdown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Next, you need to bootstrap the microcontainer. This is done in <code>BaseTest</code> class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=196&amp;download=BaseTest.java">BaseTest.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19613"><td class="code" id="p196code13"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BaseTest<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/net/URL.html"><span style="color: #003399; font-weight: bold;">URL</span></a> url<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> EmbeddedBootstrap bootstrap<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/awt/image/Kernel.html"><span style="color: #003399; font-weight: bold;">Kernel</span></a> kernel<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> KernelController controller<span style="color: #339933;">;</span>
&nbsp;
    @BeforeSuite
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setUpSuite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Exception.html"><span style="color: #003399; font-weight: bold;">Exception</span></a> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Start JBoss Microcontainer</span>
        bootstrap = <span style="color: #000000; font-weight: bold;">new</span> EmbeddedBootstrap<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        bootstrap.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        kernel = bootstrap.<span style="color: #006633;">getKernel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        controller = kernel.<span style="color: #006633;">getController</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @AfterSuite
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> tearDownSuite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> deploy<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> url<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/ClassLoader.html"><span style="color: #003399; font-weight: bold;">ClassLoader</span></a> cl = <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/Thread.html"><span style="color: #003399; font-weight: bold;">Thread</span></a>.<span style="color: #006633;">currentThread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContextClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">url</span> = cl.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        bootstrap.<span style="color: #006633;">deploy</span><span style="color: #009900;">&#40;</span>cl.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #006600; font-weight: bold;">void</span> undeploy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        bootstrap.<span style="color: #006633;">undeploy</span><span style="color: #009900;">&#40;</span>url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @<a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/SuppressWarnings.html"><span style="color: #003399; font-weight: bold;">SuppressWarnings</span></a><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;unchecked&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> T getService<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ControllerContext context = controller.<span style="color: #006633;">getInstalledContext</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>context == <span style="color: #006600; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #006600; font-weight: bold;">null</span> : <span style="color: #009900;">&#40;</span>T<span style="color: #009900;">&#41;</span> context.<span style="color: #006633;">getTarget</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>All the test classes extend this one, this allows you to run the microcontainer only once before the test suite.<br />
Another benefit is to have all the utility methods used in every test class in a central place.</p>
<p>Now we can proceed to the last part, and that is to deploy the Person service.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=196&amp;download=PersonServiceTest.java">PersonServiceTest.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p19614"><td class="code" id="p196code14"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PersonServiceTest <span style="color: #000000; font-weight: bold;">extends</span> BaseTest<span style="color: #339933;">&lt;</span>PersonService<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/util/logging/Logger.html"><span style="color: #003399; font-weight: bold;">Logger</span></a> LOGGER = LoggerFactory.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>PersonServiceTest.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> PersonService service<span style="color: #339933;">;</span>
&nbsp;
    @BeforeClass
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        deploy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jboss-beans.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        service = getService<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PersonService&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @AfterClass
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> tearDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        undeploy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Test
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> getName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> name = service.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        LOGGER.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Name: {}&quot;</span>, name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Samuel Santos&quot;</span>, name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>To see it in action, get this <a href="http://samaxes.appspot.com/zip/pojo-service-1.0.zip">example source code</a> and run the <a href="http://maven.apache.org/">Maven</a> command <kbd>mvn test</kbd>.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2009/03/jboss-pojocache-configuration/" title="JBoss PojoCache configuration">JBoss PojoCache configuration</a></li><li><a href="http://www.samaxes.com/2008/12/jboss-as-50-is-out/" title="JBoss AS 5.0 is out!">JBoss AS 5.0 is out!</a></li><li><a href="http://www.samaxes.com/2007/06/maven-2-cobertura-plugin/" title="Maven 2 Cobertura Plugin">Maven 2 Cobertura Plugin</a></li><li><a href="http://www.samaxes.com/2007/05/jboss-stacking-login-modules/" title="JBoss - Stacking Login Modules">JBoss - Stacking Login Modules</a></li><li><a href="http://www.samaxes.com/2006/06/jboss-seam-10-released/" title="JBoss Seam 1.0 released">JBoss Seam 1.0 released</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=D7aViOk9_7s:WVN8t_tK-SM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=D7aViOk9_7s:WVN8t_tK-SM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=D7aViOk9_7s:WVN8t_tK-SM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=D7aViOk9_7s:WVN8t_tK-SM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=D7aViOk9_7s:WVN8t_tK-SM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=D7aViOk9_7s:WVN8t_tK-SM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=D7aViOk9_7s:WVN8t_tK-SM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=D7aViOk9_7s:WVN8t_tK-SM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=D7aViOk9_7s:WVN8t_tK-SM:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/D7aViOk9_7s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/</feedburner:origLink></item>
		<item>
		<title>Maven Minify Plugin using YUI Compressor</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/_QaEHSph3xU/</link>
		<comments>http://www.samaxes.com/2009/06/maven-minify-plugin-using-yuicompressor/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 23:08:04 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[Build]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Maven]]></category>

		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=193</guid>
		<description><![CDATA[Following the previous article Combine and minimize JavaScript and CSS files for faster loading, I implemented a similar solution as a Maven plugin.
This plugin combines and minimizes JavaScript and CSS files using YUI Compressor for faster page loading.
More details can be found on the Maven Minify Plugin page.
Related PostsMaven 2 Cobertura PluginUsing Maven 2, XDoclet [...]]]></description>
			<content:encoded><![CDATA[<p>Following the previous article <a href="/2009/05/combine-and-minimize-javascript-and-css-files-for-faster-loading/">Combine and minimize JavaScript and CSS files for faster loading</a>, I implemented a similar solution as a Maven plugin.</p>
<p>This plugin combines and minimizes JavaScript and CSS files using <a href="http://www.julienlecomte.net/yuicompressor/">YUI Compressor</a> for faster page loading.</p>
<p>More details can be found on the <a href="http://code.google.com/p/maven-samaxes-plugin/">Maven Minify Plugin</a> page.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2007/06/maven-2-cobertura-plugin/" title="Maven 2 Cobertura Plugin">Maven 2 Cobertura Plugin</a></li><li><a href="http://www.samaxes.com/2006/07/using-maven-2-xdoclet-2-and-hibernate-3/" title="Using Maven 2, XDoclet 2, and Hibernate 3">Using Maven 2, XDoclet 2, and Hibernate 3</a></li><li><a href="http://www.samaxes.com/2009/05/combine-and-minimize-javascript-and-css-files-for-faster-loading/" title="Combine and minimize JavaScript and CSS files for faster loading">Combine and minimize JavaScript and CSS files for faster loading</a></li><li><a href="http://www.samaxes.com/2009/09/java-web-development-with-stripes/" title="Java Web Development with Stripes">Java Web Development with Stripes</a></li><li><a href="http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/" title="Unit Testing JBoss 5 Services">Unit Testing JBoss 5 Services</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=_QaEHSph3xU:cMX7h0EOm6I:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_QaEHSph3xU:cMX7h0EOm6I:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_QaEHSph3xU:cMX7h0EOm6I:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_QaEHSph3xU:cMX7h0EOm6I:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_QaEHSph3xU:cMX7h0EOm6I:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_QaEHSph3xU:cMX7h0EOm6I:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_QaEHSph3xU:cMX7h0EOm6I:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=_QaEHSph3xU:cMX7h0EOm6I:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=_QaEHSph3xU:cMX7h0EOm6I:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/_QaEHSph3xU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/06/maven-minify-plugin-using-yuicompressor/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/06/maven-minify-plugin-using-yuicompressor/</feedburner:origLink></item>
		<item>
		<title>Combine and minimize JavaScript and CSS files for faster loading</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/RsXGAc689tU/</link>
		<comments>http://www.samaxes.com/2009/05/combine-and-minimize-javascript-and-css-files-for-faster-loading/#comments</comments>
		<pubDate>Mon, 25 May 2009 13:19:17 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[Ant]]></category>

		<category><![CDATA[Build]]></category>

		<category><![CDATA[Optimization]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=179</guid>
		<description><![CDATA[Reduce HTTP requests
On most sites, the major component of download time is not the base HTML file itself, but the number of subsequent HTTP requests to load the page&#8217;s supporting files - CSS, JavaScript, images, etc.
Each of those are extra HTTP requests, and each unique request takes a relatively long time.
The fewer requests to the [...]]]></description>
			<content:encoded><![CDATA[<h3>Reduce HTTP requests</h3>
<p>On most sites, the major component of download time is not the base HTML file itself, but the number of subsequent HTTP requests to load the page&#8217;s supporting files - CSS, JavaScript, images, etc.<br />
Each of those are extra HTTP requests, and each unique request takes a relatively long time.<br />
The fewer requests to the server that the browser has to make, the faster the page will load.<br />
There is an inherent overhead in each HTTP request. It takes substantially less time to serve one 60K file than it does three 20K files and a lot less than it does six 10K files.</p>
<h3>Combine and minimize files</h3>
<p>This post will explain how to combine and minimize CSS and JavaScript files using <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a> and <a href="http://ant.apache.org/">Ant</a>.</p>
<p>This can be done by just concatenating all files into two combined files (one for CSS and one for JavaScript) and minimize them. You can quickly go from 10 or more files down to 2, and their size can be greatly reduced.</p>
<p>To keep the modularity that comes with splitting these files out by section (or business unit), keep them split in your development process, and combine them in your build process. A first Ant task will combine them and a second task will generate their minimized versions.</p>
<p>This technique has been successfully used in libraries such as jQuery, MooTools, Dojo, ExtJS, YUI, etc, allowing developers to better organize their code.<br />
<span id="more-179"></span></p>
<h3>Tools</h3>
<dl>
<dt>Ant</dt>
<dd>
<blockquote cite="http://ant.apache.org/faq.html#what-is-ant"><p>
Ant is a Java-based build tool. In theory, it is kind of like Make, without Make&#8217;s wrinkles and with the full portability of pure Java code.
</p></blockquote>
</dd>
<dt>YUI Compressor</dt>
<dd>
<blockquote cite="http://www.julienlecomte.net/yuicompressor/README"><p>
The YUI Compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as &#8216;eval&#8217; or &#8216;with&#8217; (although the compression is not optimal in those cases). Compared to jsmin, the average savings is around 20%.</p>
<p>The YUI Compressor is also able to safely compress CSS files. The decision on which compressor is being used is made on the file extension (js or css).
</p></blockquote>
</dd>
</dl>
<h3>Build</h3>
<p>Download this build example <a href="http://samaxes.appspot.com/zip/minify-css-javascript.zip">source code</a>.</p>
<h4>Code example structure</h4>
<p>This code example has the following file organization:</p>
<pre>
root
|-- build
|   `-- yuicompressor-2.4.2.jar
|-- src
|   |-- css
|   |   |-- base.css
|   |   |-- fonts.css
|   |   |-- reset.css
|   |   `-- style.css
|   |-- js
|   |   |-- samaxesjs.core.js
|   |   `-- samaxesjs.toc.js
|   `-- index.html
`-- build.xml
</pre>
<p>The <code>build</code> folder contains all the files needed to build the project.<br />
The <code>src</code> folder contains all the project source files.<br />
Finally, the <code>build.xml</code> file is the Ant build script. Here&#8217;s where you configure your project build process.</p>
<h4>Build script</h4>
<p>Let&#8217;s take a look at the project build script.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=179&amp;download=build.xml">build.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17924"><td class="code" id="p179code24"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Build example&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Setup --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SRC_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;src&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Source folder&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SRC_CSS_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}/css&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;CSS source folder&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SRC_JS_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}/js&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;JavaScript source folder&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DIST_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;dist&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Output folder for build targets&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DIST_CSS_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}/css&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Output folder for CSS files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;DIST_JS_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}/js&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Output folder for JavaScript files&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BUILD_DIR&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;build&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Files needed to build&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;YUI&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${BUILD_DIR}/yuicompressor-2.4.2.jar&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;YUICompressor&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Files names for distribution --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CSS&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}/style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CSS_MIN&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}/style.min.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JS&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}/samaxesjs.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;JS_MIN&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}/samaxesjs.min.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- Targets --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Copy HTML files to the output folder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;css&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Concatenate CSS source files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${CSS}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${CSS}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;reset.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;fonts.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;base.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${CSS} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;css.min&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;css&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Minimize CSS files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${CSS_MIN}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apply</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;java&quot;</span> <span style="color: #000066;">parallel</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">verbose</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;${YUI}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;--charset&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ANSI&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;-o&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetfile</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapper</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;glob&quot;</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;style.min.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/apply<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${CSS_MIN} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;js&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Concatenate JavaScript source files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${JS}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${JS}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_JS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;samaxesjs.core.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_JS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;samaxesjs.toc.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${JS} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;js.min&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;js&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Minimize JavaScript files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${JS_MIN}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apply</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;java&quot;</span> <span style="color: #000066;">parallel</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">verbose</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;samaxesjs.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;${YUI}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;--charset&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ANSI&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;-o&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetfile</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapper</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;glob&quot;</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;samaxesjs.js&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;samaxesjs.min.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/apply<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${JS_MIN} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean, html, css, css.min, js, js.min&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Build complete.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>html</code> target creates a <code>dist</code> (distribution) folder and copies all the files under <code>src</code> folder into it.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code25'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17925"><td class="code" id="p179code25"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Copy HTML files to the output folder&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.*&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>css</code> target concatenates all CSS files under <code>scr/css</code> folder into the file <code>dist/css/style.css</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code26'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17926"><td class="code" id="p179code26"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;css&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Concatenate CSS source files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${CSS}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${CSS}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;reset.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;fonts.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;base.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_CSS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${CSS} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>css.min</code> target takes the <code>dist/css/style.css</code> file as the input, minimizes its content, and copies it to <code>dist/css/style.min.css</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code27'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17927"><td class="code" id="p179code27"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;css.min&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;css&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Minimize CSS files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${CSS_MIN}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apply</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;java&quot;</span> <span style="color: #000066;">parallel</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">verbose</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_CSS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;${YUI}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;--charset&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ANSI&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;-o&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetfile</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapper</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;glob&quot;</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;style.min.css&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/apply<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${CSS_MIN} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>js</code> target concatenates all JavaScript files under <code>scr/js</code> folder into the file <code>dist/js/samaxesjs.js</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code28'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17928"><td class="code" id="p179code28"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;js&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Concatenate JavaScript source files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${JS}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;concat</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${JS}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_JS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;samaxesjs.core.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${SRC_JS_DIR}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;samaxesjs.toc.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/concat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${JS} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>js.min</code> target takes the <code>dist/js/samaxesjs.js</code> file as the input, minimizes its content, and copies it to <code>dist/js/samaxesjs.min.js</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code29'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17929"><td class="code" id="p179code29"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;js.min&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;js&quot;</span> <span style="color: #000066;">description</span>=<span style="color: #ff0000;">&quot;Minimize JavaScript files&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Building ${JS_MIN}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;apply</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;java&quot;</span> <span style="color: #000066;">parallel</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">verbose</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_JS_DIR}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;samaxesjs.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-jar&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;${YUI}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;--charset&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;ANSI&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;-o&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;targetfile</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mapper</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;glob&quot;</span> <span style="color: #000066;">from</span>=<span style="color: #ff0000;">&quot;samaxesjs.js&quot;</span> <span style="color: #000066;">to</span>=<span style="color: #ff0000;">&quot;samaxesjs.min.js&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/apply<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;${JS_MIN} built.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>clean</code> target removes the <code>dist</code> folder.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code30'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17930"><td class="code" id="p179code30"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${DIST_DIR}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><code>all</code> is the default target and executes all the previous by the order defined in its <code>depends</code> attribute.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code31'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17931"><td class="code" id="p179code31"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean, html, css, css.min, js, js.min&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;echo</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;Build complete.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<h4>Execute script</h4>
<p>Now that you know the file organization and the build script details; the next step is to execute the script and have the production code ready to be deployed into your hosting/server.</p>
<p>To execute the script make sure you have <a href="http://ant.apache.org/">Ant</a> installed (requires <a href="http://www.java.com/">JRE</a>), go to the project root folder (the folder that contains the <code>build.xml</code> file), and type:<br />
<strong><kbd>ant</kbd></strong> (executes the default target: <code>all</code>)</p>
<p>Your project structure should now have a new folder <code>dist</code>:</p>
<pre>
root
|-- build
|   `-- yuicompressor-2.4.2.jar
<strong>|-- dist
|   |-- css
|   |   |-- style.css
|   |   `-- style.min.jcss
|   |-- js
|   |   |-- samaxesjs.js
|   |   `-- samaxesjs.min.js
|   `-- index.html</strong>
|-- src
|   |-- css
|   |   |-- base.css
|   |   |-- fonts.css
|   |   |-- reset.css
|   |   `-- style.css
|   |-- js
|   |   |-- samaxesjs.core.js
|   |   `-- samaxesjs.toc.js
|   `-- index.html
`-- build.xml
</pre>
<h3>HTML file</h3>
<p>If you take a look at the <code>header</code> section of the <code>index.html</code> file you&#8217;ll see that I&#8217;m only using the <code>style.min.css</code> and <code>samaxesjs.min.js</code> files.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p179code32'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p17932"><td class="code" id="p179code32"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;!-- Other header elements... --&gt;
&nbsp;
    &lt;!-- CSS --&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;css/style.min.css&quot; type=&quot;text/css&quot; /&gt;
    &lt;!-- JavaScript --&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/samaxesjs.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;!-- Other body elements... --&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>You don&#8217;t need to worry about the number of CSS and JavaScript files you have. As long as you add them to the build script the code will be added to the combined file.</p>
<h3>Debug</h3>
<p>Minimizing JavaScript files makes them nearly impossible to debug since the code will all be in one single line of code.<br />
If you look carefully to the <code>dist/js</code> folder you will see two files there - <code>samaxesjs.min.js</code> and <code>samaxesjs.js</code>. So in order to debug your JavaScript just change the line <code>&lt;script type="text/javascript" src="js/samaxesjs.min.js">&lt;/script></code> in your HTML file to <code>&lt;script type="text/javascript" src="js/samaxesjs.js">&lt;/script></code>.<br />
Easy!</p>
<h3>Compression results</h3>
<p>The following images are screenshots taken from the <a href="http://developer.yahoo.com/yslow/">YSlow</a> Statistics&#8217; report comparing the debug and minimized versions.</p>
<p>Debug version (combined but not minimized):<br />
<img src="http://samaxes.appspot.com/images/build-debug-statistics.png" alt="Previous theme" /></p>
<p>Minimized version (combined and minimized):<br />
<img src="http://samaxes.appspot.com/images/build-minimized-statistics.png" alt="Actual theme" /></p>
<p>In this example you have file size reduction gains of nearly <strong>48%</strong> for JavaScript files and <strong>59%</strong> for CSS files.<br />
As you can see the compression gains are quite considerable.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2009/06/maven-minify-plugin-using-yuicompressor/" title="Maven Minify Plugin using YUI Compressor">Maven Minify Plugin using YUI Compressor</a></li><li><a href="http://www.samaxes.com/2009/01/more-on-compressing-and-caching-your-site-with-htaccess/" title="More on compressing and caching your site with .htaccess">More on compressing and caching your site with .htaccess</a></li><li><a href="http://www.samaxes.com/2008/04/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/" title=".htaccess - gzip and cache your site for faster loading and bandwidth saving">.htaccess - gzip and cache your site for faster loading and bandwidth saving</a></li><li><a href="http://www.samaxes.com/2007/06/maven-2-cobertura-plugin/" title="Maven 2 Cobertura Plugin">Maven 2 Cobertura Plugin</a></li><li><a href="http://www.samaxes.com/2006/07/using-maven-2-xdoclet-2-and-hibernate-3/" title="Using Maven 2, XDoclet 2, and Hibernate 3">Using Maven 2, XDoclet 2, and Hibernate 3</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=RsXGAc689tU:ROD7c78opeY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=RsXGAc689tU:ROD7c78opeY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=RsXGAc689tU:ROD7c78opeY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=RsXGAc689tU:ROD7c78opeY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=RsXGAc689tU:ROD7c78opeY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=RsXGAc689tU:ROD7c78opeY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=RsXGAc689tU:ROD7c78opeY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=RsXGAc689tU:ROD7c78opeY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=RsXGAc689tU:ROD7c78opeY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/RsXGAc689tU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/05/combine-and-minimize-javascript-and-css-files-for-faster-loading/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/05/combine-and-minimize-javascript-and-css-files-for-faster-loading/</feedburner:origLink></item>
		<item>
		<title>Cross Browser Testing</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/dojLcdtrrEI/</link>
		<comments>http://www.samaxes.com/2009/04/cross-browser-testing/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 14:16:38 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=182</guid>
		<description><![CDATA[No matter how anxiously expected, the release of IE8 hasn&#8217;t resulted in the end of the support for the old, deprecated, IE6 rendering engine. Giving us, the web developers, need to test against yet another version of IE.
Hopefully the eighth version is going to be a lot easier to test and support since it&#8217;s more [...]]]></description>
			<content:encoded><![CDATA[<p>No matter how anxiously expected, the release of <a href="http://www.microsoft.com/ie8">IE8</a> hasn&#8217;t resulted in the end of the support for the old, deprecated, IE6 rendering engine. Giving us, the web developers, need to test against yet another version of IE.</p>
<p>Hopefully the eighth version is going to be a lot easier to test and support since it&#8217;s more standards compliant and in that perspective, much closer to the other modern browsers. It&#8217;s also comes with easier debugging functionality as it has an integrated set of <a href="http://msdn.microsoft.com/en-us/library/dd565628(VS.85).aspx">developer tools</a> available by pressing F12 or by clicking &#8216;Developer Tools&#8217; under Tools menu.</p>
<p>But right now, together with other major players (Firefox, Opera, Safari and Chrome) you can end up with a total of 7 browsers to test. You might even want to test different versions of individual browsers, transforming this task into a nightmare. Fortunately tools, allowing you to compare different rendering engines in a single unified interface, are emerging and can really save the day. Two great examples are:</p>
<ol>
<li>Microsoft <a href="http://expression.microsoft.com/en-us/dd565874.aspx">Expression Web SuperPreview</a></li>
<li>DebugBar <a href="http://www.my-debugbar.com/wiki/IETester">IETester</a></li>
</ol>
<p>For a complete list of browser’s compatibility, check the great <a href="http://www.quirksmode.org/compatibility.html">Compatibility Master Table</a> from QuirksMode.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/" title="Unit Testing JBoss 5 Services">Unit Testing JBoss 5 Services</a></li><li><a href="http://www.samaxes.com/2007/06/maven-2-cobertura-plugin/" title="Maven 2 Cobertura Plugin">Maven 2 Cobertura Plugin</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=dojLcdtrrEI:YmX1RJ11JvE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=dojLcdtrrEI:YmX1RJ11JvE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=dojLcdtrrEI:YmX1RJ11JvE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=dojLcdtrrEI:YmX1RJ11JvE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=dojLcdtrrEI:YmX1RJ11JvE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=dojLcdtrrEI:YmX1RJ11JvE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=dojLcdtrrEI:YmX1RJ11JvE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=dojLcdtrrEI:YmX1RJ11JvE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=dojLcdtrrEI:YmX1RJ11JvE:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/dojLcdtrrEI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/04/cross-browser-testing/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/04/cross-browser-testing/</feedburner:origLink></item>
		<item>
		<title>Axis 1.4 Read timed out and HTTP 1.1</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/XdSmM9GH-3o/</link>
		<comments>http://www.samaxes.com/2009/04/axis-14-read-timed-out-and-http-11/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 15:03:24 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[Axis]]></category>

		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=181</guid>
		<description><![CDATA[For those getting a SocketTimeoutException when calling an Axis 1.4 Web Service.
This may be a solution for your problem.
If your log show an error similar to this:

?View Code TEXT12:38:51,693 ERROR [TerminalSessionHelper] ; nested exception is: 
	java.net.SocketTimeoutException: Read timed out
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.SocketTimeoutException: Read timed out
 faultActor: 
 faultNode: 
 faultDetail: 
	{http://xml.apache.org/axis/}stackTrace:java.net.SocketTimeoutException: Read [...]]]></description>
			<content:encoded><![CDATA[<p>For those getting a <code>SocketTimeoutException</code> when calling an Axis 1.4 Web Service.<br />
This may be a solution for your problem.</p>
<p>If your log show an error similar to this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p181code37'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18137"><td class="code" id="p181code37"><pre class="text" style="font-family:monospace;">12:38:51,693 ERROR [TerminalSessionHelper] ; nested exception is: 
	java.net.SocketTimeoutException: Read timed out
AxisFault
 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
 faultSubcode: 
 faultString: java.net.SocketTimeoutException: Read timed out
 faultActor: 
 faultNode: 
 faultDetail: 
	{http://xml.apache.org/axis/}stackTrace:java.net.SocketTimeoutException: Read timed out
...</pre></td></tr></table></div>

<p>And your call looks like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p181code38'); return false;">View Code</a> JAVA5</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18138"><td class="code" id="p181code38"><pre class="java5" style="font-family:monospace;">TerminalSessionService terminalSessionService = <span style="color: #000000; font-weight: bold;">new</span> TerminalSessionServiceLocator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
TerminalSession_PortType terminalSession_PortType = terminalSessionService.<span style="color: #006633;">getTerminalSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TerminalSessionSOAPBindingStub<span style="color: #009900;">&#41;</span> terminalSession_PortType<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setTimeout</span><span style="color: #009900;">&#40;</span>15000<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Try to use <code>CommonsHTTPSender</code> as the Transport Sender of the Axis client:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p181code39'); return false;">View Code</a> JAVA5</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18139"><td class="code" id="p181code39"><pre class="java5" style="font-family:monospace;">BasicClientConfig basicClientConfig = <span style="color: #000000; font-weight: bold;">new</span> BasicClientConfig<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
SimpleChain simpleChain = <span style="color: #000000; font-weight: bold;">new</span> SimpleChain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
simpleChain.<span style="color: #006633;">addHandler</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> CommonsHTTPSender<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
basicClientConfig.<span style="color: #006633;">deployTransport</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http&quot;</span>, simpleChain<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
TerminalSessionService terminalSessionService = <span style="color: #000000; font-weight: bold;">new</span> TerminalSessionServiceLocator<span style="color: #009900;">&#40;</span>basicClientConfig<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
TerminalSession_PortType terminalSession_PortType = terminalSessionService.<span style="color: #006633;">getTerminalSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TerminalSessionSOAPBindingStub<span style="color: #009900;">&#41;</span> terminalSession_PortType<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setTimeout</span><span style="color: #009900;">&#40;</span>15000<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This also has the advantage to use HTTP 1.1 instead of HTTP 1.0.<br />
<strong>Note:</strong> You will need to add the <code>common-httpclient.jar</code> and <code>common.codec.jar</code> to the jar directory for this to work.</p>
<p>Still want to use HTTP 1.0? No problem, just add the following line of code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p181code40'); return false;">View Code</a> JAVA5</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p18140"><td class="code" id="p181code40"><pre class="java5" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>TerminalSessionSOAPBindingStub<span style="color: #009900;">&#41;</span> terminalSession_PortType<span style="color: #009900;">&#41;</span>._setProperty<span style="color: #009900;">&#40;</span>
        MessageContext.<span style="color: #006633;">HTTP_TRANSPORT_VERSION</span>, HTTPConstants.<span style="color: #006633;">HEADER_PROTOCOL_V10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Hope this can save your time. Axis can be really painful&#8230;</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2009/09/java-web-development-with-stripes/" title="Java Web Development with Stripes">Java Web Development with Stripes</a></li><li><a href="http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/" title="Unit Testing JBoss 5 Services">Unit Testing JBoss 5 Services</a></li><li><a href="http://www.samaxes.com/2009/06/maven-minify-plugin-using-yuicompressor/" title="Maven Minify Plugin using YUI Compressor">Maven Minify Plugin using YUI Compressor</a></li><li><a href="http://www.samaxes.com/2009/03/jboss-pojocache-configuration/" title="JBoss PojoCache configuration">JBoss PojoCache configuration</a></li><li><a href="http://www.samaxes.com/2008/12/stripes-and-jquery-autocomplete/" title="Stripes and jQuery Autocomplete">Stripes and jQuery Autocomplete</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=XdSmM9GH-3o:8_VgFOyHYJk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=XdSmM9GH-3o:8_VgFOyHYJk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=XdSmM9GH-3o:8_VgFOyHYJk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=XdSmM9GH-3o:8_VgFOyHYJk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=XdSmM9GH-3o:8_VgFOyHYJk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=XdSmM9GH-3o:8_VgFOyHYJk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=XdSmM9GH-3o:8_VgFOyHYJk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=XdSmM9GH-3o:8_VgFOyHYJk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=XdSmM9GH-3o:8_VgFOyHYJk:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/XdSmM9GH-3o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/04/axis-14-read-timed-out-and-http-11/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/04/axis-14-read-timed-out-and-http-11/</feedburner:origLink></item>
		<item>
		<title>JBoss PojoCache configuration</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/CoIKq1KOTmc/</link>
		<comments>http://www.samaxes.com/2009/03/jboss-pojocache-configuration/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 15:17:01 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Server Development]]></category>

		<category><![CDATA[Cache]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=161</guid>
		<description><![CDATA[Everyone knows that documentation is not one of JBoss strengths.
This article is meant to fill this gap. It describes and exemplifies how to configure JBoss PojoCache as a MBean service, using loadtime transformations with JBossAop framework, so you don&#8217;t need precompiled instrumentation.
Introduction
This section gives you an introduction about PojoCache and its advantages over TreeCache (a [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone knows that documentation is not one of JBoss strengths.<br />
This article is meant to fill this gap. It describes and exemplifies how to configure JBoss PojoCache as a MBean service, using loadtime transformations with JBossAop framework, so you don&#8217;t need precompiled instrumentation.</p>
<h3>Introduction</h3>
<p>This section gives you an introduction about PojoCache and its advantages over TreeCache (a plain cache system).</p>
<blockquote cite="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html#preface"><p>PojoCache is an in-memomy, transactional, and replicated POJO (plain old Java object) cache system that allows users to operate on a POJO transparently without active user management of either replication or persistency aspects. PojoCache, a component of JBossCache (uses PojoCache class as an internal implementation, the old implementation TreeCacheAop has been deprecated.), is the first in the market to provide a POJO cache functionality. JBossCache by itself is a 100% Java based library that can be run either as a standalone program or inside an application server.</p></blockquote>
<p>TreeCache limitations:</p>
<blockquote cite="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html#1">
<ul>
<li>Users will have to manage the cache specifically; e.g., when an object is updated, a user will need a corresponding API call to update the cache content.</li>
<li>If the object size is huge, even a single field update would trigger the whole object serialization. Thus, it can be unnecessarily expensive.</li>
<li>The object structure can not have a graph relationship. That is, the object can not have sub-objects that are shared (multiple referenced) or referenced to itself (cyclic). Otherwise, the relationship will be broken upon serialization.</li>
</ul>
</blockquote>
<p>PojoCache advantages:</p>
<blockquote cite="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html#1">
<ul>
<li>No need to implement Serializable interface for the POJOs.</li>
<li>Replication (or even persistency) is done on a per-field basis (as opposed to the whole object binary level).</li>
<li>The object relationship and identity are preserved automatically in a distributed, replicated environment. It enables transparent usage behavior and increases software performance.</li>
</ul>
</blockquote>
<p><span id="more-161"></span></p>
<h3>Use case</h3>
<p>We had a project at <a href="http://www.present-technologies.com/">Present Technologies</a> where we needed to load small amounts of information from external resources and save it during short periods.<br />
This information was read-only and could have a lot of concurrent read accesses. So we wanted a solution that was simpler, faster, and more scalable than saving the data in a traditional database.</p>
<p>Some thoughts we had before choosing PojoCache:</p>
<ul>
<li>The amount of information was really small, so keeping it in memory wasn&#8217;t a problem.</li>
<li>Since this data was mainly read-only, replication to other nodes wouldn&#8217;t kill our network.</li>
<li>We needed the object relationships and identities to be preserved automatically in a distributed, replicated environment. PojoCache enables transparent usage behavior and increases software performance.</li>
</ul>
<p>So the idea was simple. When JBoss AS starts and every once in a while, a service (PojoCache MBean) will kick in, retrieve the data from the external resources, and put it into the cache. As soon as the transaction commits the cache is replicated to all the other nodes in the cluster.</p>
<h3>Requirements</h3>
<p>This article is targeted to JBossCache version 1.4.1 &#8220;<em>Cayenne</em>&#8220;, which comes bundle with JBoss AS 4.2.3, and to JDK 5.</p>
<h3>Step by step configuration</h3>
<p>How to configure PojoCache as a MBean service:</p>
<ol>
<li>
<h4>JBoss Cache with Java 5 annotations</h4>
<p>        Copy the jar file <code>jboss-cache-jdk50.jar</code> from <code>&lt;JBOSS_HOME>/server/all/lib</code> to <code>&lt;JBOSS_HOME>/server/default/lib</code>.
    </li>
<li>
<h4>PojoCache MBean service configuration</h4>
<p>        Copy the PojoCache MBean service configuration file bellow to <code>&lt;JBOSS_HOME>/server/default/deploy</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=161&amp;download=example-pojocache-service.xml">example-pojocache-service.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16148"><td class="code" id="p161code48"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;server<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mbean</span> <span style="color: #000066;">code</span>=<span style="color: #ff0000;">&quot;org.jboss.cache.aop.PojoCache&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jboss.cache:service=PojoCache&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jboss:service=TransactionManager<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- Configure the TransactionManager --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;TransactionManagerLookupClass&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org.jboss.cache.JBossTransactionManagerLookup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Isolation level : SERIALIZABLE</span>
<span style="color: #808080; font-style: italic;">                               REPEATABLE_READ (default)</span>
<span style="color: #808080; font-style: italic;">                               READ_COMMITTED</span>
<span style="color: #808080; font-style: italic;">                               READ_UNCOMMITTED</span>
<span style="color: #808080; font-style: italic;">                               NONE</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IsolationLevel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>REPEATABLE_READ<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Valid modes are LOCAL, REPL_ASYNC and REPL_SYNC --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;CacheMode&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>REPL_SYNC<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Just used for async repl: use a replication queue --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UseReplQueue&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Replication interval for replication queue (in ms) --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ReplQueueInterval&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Max number of elements which trigger replication --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ReplQueueMaxElements&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Name of cluster. Needs to be the same for all clusters, in order to find each other --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ClusterName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>TreeCache-Cluster<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- JGroups protocol stack properties. Can also be a URL, e.g. file:/home/bela/default.xml</span>
<span style="color: #808080; font-style: italic;">             &lt;attribute name=&quot;ClusterProperties&quot;&gt;&lt;/attribute&gt; --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ClusterConfig&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- UDP: if you have a multihomed machine,</span>
<span style="color: #808080; font-style: italic;">                     set the bind_addr attribute to the appropriate NIC IP address, e.g bind_addr=&quot;192.168.0.2&quot;</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #808080; font-style: italic;">&lt;!-- UDP: On Windows machines, because of the media sense feature</span>
<span style="color: #808080; font-style: italic;">                     being broken with multicast (even after disabling media sense)</span>
<span style="color: #808080; font-style: italic;">                     set the loopback attribute to true</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UDP</span> <span style="color: #000066;">mcast_addr</span>=<span style="color: #ff0000;">&quot;228.1.2.3&quot;</span> <span style="color: #000066;">mcast_port</span>=<span style="color: #ff0000;">&quot;48866&quot;</span> <span style="color: #000066;">ip_ttl</span>=<span style="color: #ff0000;">&quot;64&quot;</span> <span style="color: #000066;">ip_mcast</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">mcast_send_buf_size</span>=<span style="color: #ff0000;">&quot;150000&quot;</span> <span style="color: #000066;">mcast_recv_buf_size</span>=<span style="color: #ff0000;">&quot;80000&quot;</span> <span style="color: #000066;">ucast_send_buf_size</span>=<span style="color: #ff0000;">&quot;150000&quot;</span> <span style="color: #000066;">ucast_recv_buf_size</span>=<span style="color: #ff0000;">&quot;80000&quot;</span> <span style="color: #000066;">loopback</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PING</span> <span style="color: #000066;">timeout</span>=<span style="color: #ff0000;">&quot;2000&quot;</span> <span style="color: #000066;">num_initial_members</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MERGE2</span> <span style="color: #000066;">min_interval</span>=<span style="color: #ff0000;">&quot;10000&quot;</span> <span style="color: #000066;">max_interval</span>=<span style="color: #ff0000;">&quot;20000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FD_SOCK</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VERIFY_SUSPECT</span> <span style="color: #000066;">timeout</span>=<span style="color: #ff0000;">&quot;1500&quot;</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pbcast.NAKACK</span> <span style="color: #000066;">gc_lag</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">retransmit_timeout</span>=<span style="color: #ff0000;">&quot;600,1200,2400,4800&quot;</span> <span style="color: #000066;">max_xmit_size</span>=<span style="color: #ff0000;">&quot;8192&quot;</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UNICAST</span> <span style="color: #000066;">timeout</span>=<span style="color: #ff0000;">&quot;600,1200,2400&quot;</span> <span style="color: #000066;">window_size</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">min_threshold</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pbcast.STABLE</span> <span style="color: #000066;">desired_avg_gossip</span>=<span style="color: #ff0000;">&quot;20000&quot;</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FRAG</span> <span style="color: #000066;">frag_size</span>=<span style="color: #ff0000;">&quot;8192&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pbcast.GMS</span> <span style="color: #000066;">join_timeout</span>=<span style="color: #ff0000;">&quot;5000&quot;</span> <span style="color: #000066;">join_retry_timeout</span>=<span style="color: #ff0000;">&quot;2000&quot;</span> <span style="color: #000066;">shun</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">print_local_addr</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pbcast.STATE_TRANSFER</span> <span style="color: #000066;">up_thread</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">down_thread</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Whether or not to fetch state on joining a cluster --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FetchStateOnStartup&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- The max amount of time (in milliseconds) we wait until the</span>
<span style="color: #808080; font-style: italic;">             initial state (ie. the contents of the cache) are retrieved from</span>
<span style="color: #808080; font-style: italic;">             existing members in a clustered environment</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;InitialStateRetrievalTimeout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>5000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Number of milliseconds to wait until all responses for a synchronous call have been received. --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SyncReplTimeout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>15000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Max number of milliseconds to wait for a lock acquisition --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;LockAcquisitionTimeout&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>10000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Name of the eviction policy class. --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EvictionPolicyClass&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mbean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/server<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>        <strong>Notes:</strong></p>
<ul>
<li>This example was taken from <a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html#xml">PojoCache User Documentation for Release 1.4.1 &#8220;<em>Cayenne</em>&#8220;</a>.</li>
<li>A lot more examples can be found in the folder <code>etc\META-INF</code> present in the <a href="http://www.jboss.org/community/docs/DOC-12844">JBoss Cache releases</a>.</li>
</ul>
</li>
<li>
<h4>Loadtime Instrumentation</h4>
<p>        Copy the jar file <code>pluggable-instrumentor.jar</code> from <code>&lt;JBOSS_HOME>/server/default/deploy/jboss-aop-jdk50.deployer</code> to <code>&lt;JBOSS_HOME>/bin</code>.
    </li>
<li>
<h4>&#8220;prepare&#8221; your POJOs</h4>
<p>        Declare your POJOs as &#8220;prepared&#8221; by adding the type level annotation <code>@org.jboss.cache.aop.annotation.PojoCacheable</code> to all that need to be put into cache management.
    </li>
<li>
<h4>AspectManager service configuration</h4>
<p>        Edit <code>jboss-service.xml</code> in <code>&lt;JBOSS_HOME>/server/default/deploy/jboss-aop-jdk50.deployer/META-INF</code> to enable loadtime transformations.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=161&amp;download=jboss-service.xml">jboss-service.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16149"><td class="code" id="p161code49"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- ===================================================================== --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--  JBoss Server Configuration                                                                                         --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- ===================================================================== --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;server<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #808080; font-style: italic;">&lt;!-- The code for the service is different for the different run scenarios</span>
<span style="color: #808080; font-style: italic;">      *** JBoss 4.0</span>
<span style="color: #808080; font-style: italic;">          * JDK 1.4 - org.jboss.aop.deployment.AspectManagerService</span>
<span style="color: #808080; font-style: italic;">          * JDK 5 (not using -javaagent switch) - org.jboss.aop.deployment.AspectManagerService</span>
<span style="color: #808080; font-style: italic;">          * JDK 5 (using -javaagent switch) - org.jboss.aop.deployment.AspectManagerServiceJDK5</span>
<span style="color: #808080; font-style: italic;">          * BEA JRockit 1.4.2 - org.jboss.aop.deployment.AspectManagerService</span>
<span style="color: #808080; font-style: italic;">      *** JBoss 3.2</span>
<span style="color: #808080; font-style: italic;">          * JDK 1.4 - org.jboss.aop.deployment.AspectManagerService32</span>
<span style="color: #808080; font-style: italic;">          * JDK 5 (not using -javaagent switch) - org.jboss.aop.deployment.AspectManagerService32</span>
<span style="color: #808080; font-style: italic;">          * JDK 5 (using -javaagent switch) - org.jboss.aop.deployment.AspectManagerService32JDK5</span>
<span style="color: #808080; font-style: italic;">          * BEA JRockit 1.4.2 - org.jboss.aop.deployment.AspectManagerService32</span>
<span style="color: #808080; font-style: italic;">   --&gt;</span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mbean</span> <span style="color: #000066;">code</span>=<span style="color: #ff0000;">&quot;org.jboss.aop.deployment.AspectManagerServiceJDK5&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jboss.aop:service=AspectManager&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;EnableLoadtimeWeaving&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!-- only relevant when EnableLoadtimeWeaving is true.</span>
<span style="color: #808080; font-style: italic;">           When transformer is on, every loaded class gets</span>
<span style="color: #808080; font-style: italic;">           transformed.  If AOP can't find the class, then it</span>
<span style="color: #808080; font-style: italic;">           throws an exception.  Sometimes, classes may not have</span>
<span style="color: #808080; font-style: italic;">           all the classes they reference.  So, the Suppressing</span>
<span style="color: #808080; font-style: italic;">           is needed.  (i.e. Jboss cache in the default configuration --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SuppressTransformationErrors&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Prune&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!--attribute name=&quot;Include&quot;&gt;org.jboss.test, org.jboss.injbossaop&lt;/attribute--&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Include&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>com.samaxes.example<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Exclude&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>org, com, net, bsh, javassist, antlr, com.arjuna<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #808080; font-style: italic;">&lt;!-- This avoids instrumentation of hibernate cglib enhanced proxies</span>
<span style="color: #808080; font-style: italic;">      &lt;attribute name=&quot;Ignore&quot;&gt;*$$EnhancerByCGLIB$$*&lt;/attribute&gt; --&gt;</span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Optimized&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Verbose&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mbean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mbean</span> <span style="color: #000066;">code</span>=<span style="color: #ff0000;">&quot;org.jboss.aop.deployment.AspectDeployer&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jboss.aop:service=AspectDeployer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mbean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/server<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>        Be sure to only include the packages that contains the POJOs to be aspectized and exclude all others.<br />
        <strong><em>Not doing so can really slowdown your server startup!</em></strong>
    </li>
<li>
<h4>AOP configuration</h4>
<p>        Enable your POJOs to be aspectized copying the AOP configuration file bellow to <code>&lt;JBOSS_HOME>/server/default/deploy</code>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=161&amp;download=example-aop.xml">example-aop.xml</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16150"><td class="code" id="p161code50"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE aop PUBLIC</span>
<span style="color: #00bbdd;">       &quot;-//JBoss//DTD JBOSS AOP 1.0//EN&quot;</span>
<span style="color: #00bbdd;">       &quot;http://labs.jboss.com/portal/jbossaop/dtd/jboss-aop_1_0.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;aop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- If a POJO has JDK5 PojoCacheable annotation, it will be aspectized. --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prepare</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;field(* @org.jboss.cache.aop.annotation.PojoCacheable-&gt;</span></span>*)&quot; /&gt;
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!-- If a POJO has JDK5 InstanceOfPojoCacheable annotation, it will be aspectized. --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;prepare</span> <span style="color: #000066;">expr</span>=<span style="color: #ff0000;">&quot;field(* $instanceof{@org.jboss.cache.aop.annotation.InstanceOfPojoCacheable}-&gt;</span></span>*)&quot; /&gt;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/aop<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</li>
<li>
<h4><code>JAVA_OPTS</code> environment variable</h4>
<p>        Edit <code>run.sh</code> or <code>run.bat</code> (depending on what OS you&#8217;re on) and add the following to the <code>JAVA_OPTS</code> environment variable:<br />
        <code>set JAVA_OPTS=%JAVA_OPTS% -javaagent:pluggable-instrumentor.jar</code>.
    </li>
</ol>
<h3>Usage</h3>
<p>How to use and interact with PojoCache.</p>
<ol>
<li>
<h4>Sample POJO</h4>
<p>        Create a simple POJO.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=161&amp;download=Person.java">Person.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16151"><td class="code" id="p161code51"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.samaxes.example</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jboss.cache.aop.annotation.PojoCacheable</span><span style="color: #339933;">;</span>
&nbsp;
@PojoCacheable
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> firstName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> lastName<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> getFirstName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setFirstName<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> firstName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">firstName</span> = firstName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> getLastName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #006600; font-weight: bold;">void</span> setLastName<span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/java/lang/String.html"><span style="color: #003399; font-weight: bold;">String</span></a> lastName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastName</span> = lastName<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>
<h4>Cache Helper Singleton</h4>
<p>        Create a singleton to interact with PojoCache.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.samaxes.com/wp-content/plugins/wp-codebox/wp-codebox.php?p=161&amp;download=CacheHelper.java">CacheHelper.java</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16152"><td class="code" id="p161code52"><pre class="java5" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.samaxes.example</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.management.MBeanServer</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.management.MalformedObjectNameException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jboss.cache.aop.PojoCacheMBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jboss.mx.util.MBeanProxyExt</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.jboss.mx.util.MBeanServerLocator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CacheHelper <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> CacheHelper INSTANCE = <span style="color: #000000; font-weight: bold;">new</span> CacheHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> PojoCacheMBean pojoCache<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> PojoCacheMBean getPojoCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> pojoCache<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> CacheHelper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            <a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/javax/management/MBeanServer.html"><span style="color: #003399; font-weight: bold;">MBeanServer</span></a> server = MBeanServerLocator.<span style="color: #006633;">locate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            pojoCache = <span style="color: #009900;">&#40;</span>PojoCacheMBean<span style="color: #009900;">&#41;</span> MBeanProxyExt.<span style="color: #006633;">create</span><span style="color: #009900;">&#40;</span>PojoCacheMBean.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;jboss.cache:service=PojoCache&quot;</span>,
                    server<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://java.sun.com/j2se/<span style="color: #cc66cc;">1</span>.<span style="color: #cc66cc;">5</span>.0/docs/api/javax/management/MalformedObjectNameException.html"><span style="color: #003399; font-weight: bold;">MalformedObjectNameException</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// log exception...</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>        <strong>Note:</strong> This step is optional but it allows to not have duplicated code and to have only one instance of the PojoCache MBean in the application context.
    </li>
<li>
<h4>Using PojoCache</h4>
<p>        And that&#8217;s it! Give it a try.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p161code53'); return false;">View Code</a> JAVA5</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16153"><td class="code" id="p161code53"><pre class="java5" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Puts Person object into cache management</span>
CacheHelper.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">getPojoCache</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">putObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/aop/person&quot;</span>, person<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Gets Person object from cache</span>
CacheHelper.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">getPojoCache</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getObject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/aop/person&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>        Every time you change a Person property, cache will manage its replication or persistency automatically.<br />
        As cited in the introduction, this is done on a per-field basis.
    </li>
</ol>
<h3>No MBean support</h3>
<p>It&#8217;s possible to use PojoCache without using MBeans.<br />
The examples available in the <a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html">PojoCache User Documentation</a> use the following strategy:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p161code54'); return false;">View Code</a> JAVA5</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p16154"><td class="code" id="p161code54"><pre class="java5" style="font-family:monospace;">cache = <span style="color: #000000; font-weight: bold;">new</span> PojoCache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
PropertyConfigurator config = <span style="color: #000000; font-weight: bold;">new</span> PropertyConfigurator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// configure tree cache.</span>
config.<span style="color: #006633;">configure</span><span style="color: #009900;">&#40;</span>cache, <span style="color: #0000ff;">&quot;META-INF/replSync-service.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Search under the classpath</span>
cache.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
<span style="color: #006633;">cache</span>.<span style="color: #006633;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Resources</h3>
<ul>
<li><a href="http://www.jboss.org/jbossaop/">JBoss AOP</a></li>
<li><a href="http://www.jboss.org/jbosscache/">JBoss Cache</a></li>
<li><a href="http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/1.4.1.SP4/PojoCache/en/html_single/index.html">PojoCache User Documentation for Release 1.4.1 &#8220;<em>Cayenne</em>&#8220;</a></li>
</ul>
<p><strong>Note:</strong> For questions about JBoss technologies please use <a href="http://www.jboss.org/index.html?module=bb">JBoss forums</a>.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2009/09/test-jboss-microcontainer-services/" title="Unit Testing JBoss 5 Services">Unit Testing JBoss 5 Services</a></li><li><a href="http://www.samaxes.com/2008/12/jboss-as-50-is-out/" title="JBoss AS 5.0 is out!">JBoss AS 5.0 is out!</a></li><li><a href="http://www.samaxes.com/2008/01/j2ee-cache-filter/" title="J2EE cache filter">J2EE cache filter</a></li><li><a href="http://www.samaxes.com/2007/05/jboss-stacking-login-modules/" title="JBoss - Stacking Login Modules">JBoss - Stacking Login Modules</a></li><li><a href="http://www.samaxes.com/2006/06/jboss-seam-10-released/" title="JBoss Seam 1.0 released">JBoss Seam 1.0 released</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=CoIKq1KOTmc:q7ED7zqbH4g:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=CoIKq1KOTmc:q7ED7zqbH4g:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=CoIKq1KOTmc:q7ED7zqbH4g:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=CoIKq1KOTmc:q7ED7zqbH4g:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=CoIKq1KOTmc:q7ED7zqbH4g:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=CoIKq1KOTmc:q7ED7zqbH4g:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=CoIKq1KOTmc:q7ED7zqbH4g:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=CoIKq1KOTmc:q7ED7zqbH4g:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=CoIKq1KOTmc:q7ED7zqbH4g:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/CoIKq1KOTmc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/03/jboss-pojocache-configuration/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/03/jboss-pojocache-configuration/</feedburner:origLink></item>
		<item>
		<title>Internationalization of the File Upload Form Field</title>
		<link>http://feedproxy.google.com/~r/samaxes/~3/iEQpmlnaxBw/</link>
		<comments>http://www.samaxes.com/2009/01/internationalization-of-the-file-upload-form-field/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 11:36:51 +0000</pubDate>
		<dc:creator>Samuel Santos</dc:creator>
		
		<category><![CDATA[Standards]]></category>

		<category><![CDATA[HTML5]]></category>

		<category><![CDATA[Internationalization]]></category>

		<guid isPermaLink="false">http://www.samaxes.com/?p=159</guid>
		<description><![CDATA[
Internationalization, or i18n, is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language. Localization refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a [...]]]></description>
			<content:encoded><![CDATA[<blockquote cite="http://dev.w3.org/2006/waf/widgets/i18n.html"><p>
<em>Internationalization</em>, or i18n, is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language. <em>Localization</em> refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a &#8220;locale&#8221;).
</p></blockquote>
<p>Adapting application to various languages is for me, as a Java and HTML developer, more than a common task. Usually the solution involves a set of supported locales, which is very often different from the system locale and/or browser configuration. Majority of such cases are covered by the scenario when user chooses particular language settings and the only place where the locale setting can be stored is the HTTP Session.</p>
<p>Support for this behavior is now handled by majority of frameworks; nevertheless there is still one HTML element that you can&#8217;t effectively change - the file upload form field.<br />
<span id="more-159"></span></p>
<p>And that&#8217;s not the only issue related to this element; it&#8217;s nearly completely inaccessible to CSS manipulation, making it impossible to style it as other form input fields (luckily there are some workarounds available - <a href="http://swfupload.org/">SWFUpload</a> or <a href="http://www.quirksmode.org/dom/inputfile.html">Styling an input type=&#8221;file&#8221;</a>).</p>
<p>To tackle the internationalization issues should be quite straightforward. However after discussion with the <a href="http://www.whatwg.org/">WHAT Working Group</a> members (community focused on development of the HTML 5 specification) I&#8217;ve recognized <a href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-November/017030.html">their concerns</a> about the styling of the upload field, mainly in regards to the security and privacy.</p>
<p>Following this, <a href="http://ian.hixie.ch/">Ian Hickson</a> - the editor and spokesman for the WHAT Working Group - came with the surprisingly easy suggestion how to address this problem. It seems like browsers should already handle this based on the lang=&#8221;" attribute:</p>
<blockquote cite="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-November/017047.html"><p>
It seems like browsers should do this already based on the lang=&#8221;" attribute. I recommend asking browser vendors to implement this.
</p></blockquote>
<p>And therefore I would like to endorse vendors to implement at least this behavior.</p>
<p>This way if user chooses the <code>pt</code> locale in his profile but the browser is configured only to support English (<code>en</code>), the developer can get the locale from user&#8217;s HTTP Session and propagate it through the attribute <code>lang="pt"</code> of the file upload field and have the button caption matching users preferences.</p>
<p>I would highly appreciate feedback on this topic, especially from the browser vendors willing to implement this feature.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.samaxes.com/2008/08/the-semantic-web-and-rdfa/" title="The Semantic Web and RDFa">The Semantic Web and RDFa</a></li><li><a href="http://www.samaxes.com/2008/06/html-5-media-2008/" title="HTML 5 @media 2008">HTML 5 @media 2008</a></li><li><a href="http://www.samaxes.com/2006/12/java-and-utf-8-encoding/" title="Java and UTF-8 encoding">Java and UTF-8 encoding</a></li><li><a href="http://www.samaxes.com/2006/05/localization-in-aspnet-20/" title="Localization in ASP.NET 2.0">Localization in ASP.NET 2.0</a></li><li><a href="http://www.samaxes.com/2006/04/how-to-build-multi-language-web-sites-with-aspnet-20-and-vsnet-2005/" title="How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005">How to build Multi-Language Web Sites with ASP.NET 2.0 and VS.Net 2005</a></li></ul><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/samaxes?a=iEQpmlnaxBw:dzB8jbt5XIM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/samaxes?i=iEQpmlnaxBw:dzB8jbt5XIM:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=iEQpmlnaxBw:dzB8jbt5XIM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/samaxes?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=iEQpmlnaxBw:dzB8jbt5XIM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/samaxes?i=iEQpmlnaxBw:dzB8jbt5XIM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=iEQpmlnaxBw:dzB8jbt5XIM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/samaxes?i=iEQpmlnaxBw:dzB8jbt5XIM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/samaxes?a=iEQpmlnaxBw:dzB8jbt5XIM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/samaxes?i=iEQpmlnaxBw:dzB8jbt5XIM:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/samaxes/~4/iEQpmlnaxBw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.samaxes.com/2009/01/internationalization-of-the-file-upload-form-field/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.samaxes.com/2009/01/internationalization-of-the-file-upload-form-field/</feedburner:origLink></item>
	</channel>
</rss>
