<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I Like Parentheses (so get used to 'em) &#187; programming</title>
	<atom:link href="http://blog.josh-peters.name/category/left-brain/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.josh-peters.name</link>
	<description>“People who like this sort of thing will find it just the sort of thing they like.”—Abraham Lincoln</description>
	<lastBuildDate>Sat, 31 Jul 2010 05:04:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Javascript tip: hints for better minification</title>
		<link>http://blog.josh-peters.name/2010/05/31-javascript-tip-hints-for-better-minification/</link>
		<comments>http://blog.josh-peters.name/2010/05/31-javascript-tip-hints-for-better-minification/#comments</comments>
		<pubDate>Mon, 31 May 2010 17:10:04 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=720</guid>
		<description><![CDATA[Delivery of Javascript assets can be pretty expensive across the wire. A common way to combat the delivery cost is to minify your script before delivery. This technique is about as close as the web has come to compiling. However, &#8230; <a href="http://blog.josh-peters.name/2010/05/31-javascript-tip-hints-for-better-minification/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Delivery of Javascript assets can be pretty expensive across the wire. A common way to combat the delivery cost is to minify your script before delivery. This technique is about as close as the web has come to compiling. However, some good practices can actually get in the way of making your scripts well-minified.</p>
<p><span id="more-720"></span>
<p>A good practice worth sticking to is minimizing the use of the global namespace. The value of this is especially evident in shared libraries. Here&#8217;s an example you may see in a page validating a form:</p>
<div>
<pre><code>var MY_NS = window.MY_NS || {};
function init() {
  MY_NS.nameField = document.getElementById( "nameField" );
  MY_NS.phoneField = document.getElementById( "phoneField" );
  MY_NS.addressField = document.getElementById( "addressField" );
  &#8230;
  if ( null === MY_NS.nameField.value || "" === MY_NS.nameField.value ) {
    &#8230;
  }
  &#8230;
}
&#8230;
</code></pre>
</div>
<p>There are a few optimizations we can make that will help this script to compress well.</p>
<p>First off, the repeated calls to <samp>document.getElementById</samp> should be replaced with a local variable. The benefit of this is that the local variable will be reduced into a single letter during minification. I recommend replacing the &#8220;.&#8221; with a &#8220;_&#8221; character, since it leaves the source script fairly readable.</p>
<div>
<pre><code>MY_NS.nameField = document.getElementById( "nameField" );
MY_NS.phoneField = document.getElementById( "phoneField" );
MY_NS.addressField = document.getElementById( "addressField" );</code></pre>
</div>
<p>becomes</p>
<div>
<pre><code>var document_getElementById = document.getElementById;
MY_NS.nameField = document_getElementById( "nameField" );
MY_NS.phoneField = document_getElementById( "phoneField" );
MY_NS.addressField = document_getElementById( "addressField" );</code></pre>
</div>
<p>After minification you&#8217;ll get something like this (I&#8217;m leaving in the newlines though).</p>
<div>
<pre><code>var A = document.getElementById;
MY_NS.nameField = A( "nameField" );
MY_NS.phoneField = A( "phoneField" );
MY_NS.addressField = A( "addressField" );</code></pre>
</div>
<p>That tip saves 22 characters per use. Similarly, we can create local variables inside our <samp>init</samp> function to save us some characters when referring to the properly namespaced fields.</p>
<div>
<pre><code>MY_NS.nameField = document.getElementById( "nameField" );</code></pre>
</div>
<p>becomes</p>
<div>
<pre><code>MY_NS.nameField = document.getElementById( "nameField" );
var MY_NS_nameField = MY_NS.nameField;
&#8230;
if ( null === MY_NS_nameField.value || "" === MY_NS_nameField.value ) {
  &#8230;
}
</code></pre>
</div>
<p>after minification:</p>
<div>
<pre><code>MY_NS.nameField = document.getElementById( "nameField" );
var B = MY_NS.nameField;
&#8230;
if ( null === B.value || "" === B.value ) {
  &#8230;
}</code></pre>
</div>
<p>If you find yourself referring to an object more than a few times, it makes a bit of sense to create locally scoped variables here. It&#8217;s also important to note that this is allowable with <em>any</em> Javascript object, even the <samp>document</samp> object. Yahoo! uses this technique all over the place in their great <a href="http://developer.yahoo.com/yui">YUI library</a>.</p>
<p>Perhaps a future release of YUI minifier (or one of the other minifiers) will add a two-pass optimizer in the future to save the developer the hassle of defining extra locally-scoped variables, but I&#8217;ll not hold my breath.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2010/05/31-javascript-tip-hints-for-better-minification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 5 Enums Are Cool!</title>
		<link>http://blog.josh-peters.name/2010/05/19-java-5-enums-are-cool/</link>
		<comments>http://blog.josh-peters.name/2010/05/19-java-5-enums-are-cool/#comments</comments>
		<pubDate>Thu, 20 May 2010 02:19:51 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=718</guid>
		<description><![CDATA[Java 5 enums are powerful things. Anytime you need a limited list of values, you should consider an enum class (versus a String or int). Java 5 enums can have methods as well, which leads to some powerful combinations. As &#8230; <a href="http://blog.josh-peters.name/2010/05/19-java-5-enums-are-cool/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Java 5 enums are powerful things. Anytime you need a limited list of values, you should consider an enum class (versus a String or int). Java 5 enums can have methods as well, which leads to some powerful combinations.</p>
<p><span id="more-718"></span>
<p>As an example consider the following code:</p>
<div>
<pre><code>private static final int SPECIAL_CASE_1 = 1;
private static final int SPECIAL_CASE_2 = 2;
&#8230;
int someThing;
String param1;
String param2;
&#8230;
switch( someThing ) {
  case SPECIAL_CASE_1: {
    doSpecialCase1( param1 );
    break;
  }
  case SPECIAL_CASE_2: {
    doSpecialCase2( param2 );
  }
  default: doSomethingElse();
}</code></pre>
</div>
<p>There are some issues with the above code. <tt>case</tt> statements are easily screwed up (is <tt>SPECIAL_CASE_2</tt> <em>supposed</em> to also call <tt>doSomethingElse()</tt> or is that a bug? Also, adding new cases can lead to quite a lot of classes to update. For the times where a full-blown class hierarchy is overkill, an enum makes quite a lot of sense. Often, the methods <tt>doSpecialCase1</tt>, <tt>doSpecialCase2</tt>, <tt>doSomethingElse</tt> can be refactored into methods of the enumeration.</p>
<p>Here&#8217;s how we can accomplish this.</p>
<div>
<pre><code>public enum SpecialCaseHandler {
  SPECIAL_CASE_1,
  SPECIAL_CASE_2,
  DEFAULT_CASE
}</code></pre>
</div>
<p>This simple enum can be used to replace the type of the control variable <tt>someThing</tt>. Now the switch statement looks like this:</p>
<div>
<pre><code>SpecialCaseHandler someThing;
String param1;
String param2;
&#8230;
switch( someThing ) {
  case SPECIAL_CASE_1: {
    doSpecialCase1( param1 );
    break;
  }
  case SPECIAL_CASE_2: {
    doSpecialCase2( param2 );
  }
  default: doSomethingElse();
}</code></pre>
</div>
<p>On the surface, this doesn&#8217;t get us a whole lot. What would really be nice is if we could remove the <tt>switch</tt> statement altogether. To accomplish this will take a bit more magic.</p>
<p>We&#8217;ll begin our magic by defining an inner interface inside the <tt>enum</tt> itself. Since the above <tt>switch</tt> statement uses two separate String parameters, the interface will have to account for both parameters. In addition, our enum will need a field declared of that particular interface. It looks like this:</p>
<div>
<pre><code>public enum SpecialCaseHandler {
  &#8230;
  private MyRunnable myRunnable;
  &#8230;
  private interface MyRunnable {
    public void execute( String param1, String param2 );
  }
}</code></pre>
</div>
<p>Next, we&#8217;ll rework the enum members to use a non-default constructor that takes an instance of <tt>MyRunnable</tt>.</p>
<div>
<pre><code>public enum SpecialCaseHandler {
  SPECIAL_CASE_1( new MyRunnable() {
    public void execute( String param1, String param2 ) {
      // body of doSpecialCase1() goes here.
    }
  } ),
  SPECIAL_CASE_2( new MyRunnable() {
    public void execute( String param1, String param2 ) {
      // body of doSpecialCase2() goes here.
    }
  } ),
  DEFAULT_CASE( new MyRunnable() {
    public void execute( String param1, String param2 ) {
      // body of doSomethingElse() goes here.
    }
  } );
  &#8230;
}</code></pre>
</div>
<p>Now the original switch statement can be remove altogether, leaving this beautiful little call:</p>
<div>
<pre><code>someThing.execute( param1, param2 );</code></pre>
</div>
<p>But wait, you say, what if my caller class has some dependencies that prevent the methods <tt>doSpecialCase1</tt>, <tt>doSpecialCase2</tt>, and <tt> doSomethingElse</tt> from being refactored out of the caller class? The answer is simple, add additional input parameters to the <tt>MyRunnable</tt> <tt>execute</tt> method to take the dependencies as input.</p>
<p>That is, if <tt>doSomethingElse</tt> happens to use a database connection whereas <tt>doSpecialCase1</tt> uses a file handle, you&#8217;ll have to come up with some way to pass that off to the method call. I&#8217;ll leave that as an exercise to the reader.</p>
<p>I&#8217;m pretty pleased with the result: I&#8217;ve removed the <tt>switch</tt> block from my code and can pretty easily add in new cases to the enum. I think using enums really is a nice alternative to more rigorous inheritance in a lot of cases. Anytime a specific identifier is called for but not necessarily a super-reusable class, consider using an enum instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2010/05/19-java-5-enums-are-cool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiling JSPs in Tomcat</title>
		<link>http://blog.josh-peters.name/2010/02/20-compiling-jsps-in-tomcat/</link>
		<comments>http://blog.josh-peters.name/2010/02/20-compiling-jsps-in-tomcat/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 20:50:21 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring-framework]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=715</guid>
		<description><![CDATA[For some time now, I&#8217;ve been working with Spring MVC and Spring Web Flow to build web applications. One option that Spring MVC (and Web Flow by extension) offer is a view resolver that allows you to hide your JSP &#8230; <a href="http://blog.josh-peters.name/2010/02/20-compiling-jsps-in-tomcat/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For some time now, I&#8217;ve been working with Spring MVC and Spring Web Flow to build web applications. One option that Spring MVC (and Web Flow by extension) offer is a view resolver that allows you to hide your JSP files behind the magical WEB-INF folder. The <a href="http://static.springsource.org/docs/Spring-MVC-step-by-step/">excellent Spring MVC tutorial</a> started me on the practice of configuring my view resolver to stash JSPs behind the wall of WEB-INF.</p>
<p>The downside to this approach is that it becomes very difficult to compile those JSP files without walking through one&#8217;s application.</p>
<p><span id="more-715"></span>
<p>One of the nice things about GlassFish and WebLogic is that it allows you to compile your JSP files during deployment. Tomcat does not. Using Maven or Ant one can precompile the JSP files, but that approach hasn&#8217;t always worked for me (especially when a custom tag library is in use).</p>
<p>On Monday I&#8217;m launching an update to an application and we expect a bit of a rush on those first few minutes when the application goes live. Last time we had this, the first few sessions were incredibly bogged down by the JSP compilation.</p>
<p>Today I discovered the fix: move the JSP files to be in front of the WEB-INF wall and reconfigure my view resolver to look in the proper place. This allows me to then fetch those files individually via a simple <code>curl</code> call.</p>
<p>&#8230;</p>
<p>The downside to this approach is that I just CPU spiked my servers, as <code>curl</code> just fetched each JSP file individually causing a huge amount of compilation to occur. Sorry about that sysadmins <img src='http://blog.josh-peters.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Please ignore the huge spike in CPU usage this afternoon.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2010/02/20-compiling-jsps-in-tomcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YAGNI, Apple, and iPod</title>
		<link>http://blog.josh-peters.name/2010/02/06-yagni-apple-and-ipod/</link>
		<comments>http://blog.josh-peters.name/2010/02/06-yagni-apple-and-ipod/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 18:55:11 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[apple/mac/ipod]]></category>
		<category><![CDATA[best-practices]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ipod]]></category>
		<category><![CDATA[pragmatic programmers]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=711</guid>
		<description><![CDATA[As we all know, Apple recently introduced iPad to the world. Regardless of what you think about the device, I find myself really interested in the brief glimpses it offers about how Apple has been running its business. Back in &#8230; <a href="http://blog.josh-peters.name/2010/02/06-yagni-apple-and-ipod/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As we all know, Apple recently introduced iPad to the world. Regardless of what you think about the device, I find myself really interested in the brief glimpses it offers about how Apple has been running its business.</p>
<p><span id="more-711"></span>
<p>Back in 2001, Apple joined the fray of portable music device manufacturers with iPod. Of interest to some was a throwaway phrase mentioned about its engineering: &#8220;made with off-the-shelf parts.&#8221; That is to say, Apple used existing chips and hardware largely in creating its music player.</p>
<p>By designing iPod with pre-existing parts, Apple was offered a world of flexibility. If the device flopped, the company could recoup losses much quicker than if it had spent an extended amount of time putting its varying departments to work developing custom circuits, screens, etc. If the device proved successful, future revisions could include less off-the-shelf parts. Apple established a brand, getting their foot in the door. Over time, Apple switched from iPod components out gradually replacing them with their own, custom parts.</p>
<p>I am reminded of the software design principle of &#8220;Ya Ain&#8217;t Gonna Need It.&#8221; This principle basically says that one should not add functionality until it is required. In order to create a new product, Apple didn&#8217;t <em>require</em> all of the component design and maintenance headaches to start a project. Instead, YAGNI was in play, and Apple got their foot in the door.</p>
<p>When the time was right, the proper changes were made. By no longer using those same off-the-shelf parts, Apple could fine-tune and better control what it wanted, resulting in a more innovative player. The first iPod had a mechanical wheel, the next used a touch pad surface, the next a click-wheel, etc. However, without getting the brand started, Apple had no incentive to iterate its design. I think that is an important lesson.</p>
<p>In many ways, this has been the Apple <abbr title="modus operandi">m.o.</abbr> for some time. The iMac and Mac mini have frequently been test beds for engineering smaller parts that would eventually end up in its notebook computer line. The MacBook Air paved the way for the Unibody Aluminum MacBook Pro. Across the internal lines within the company exist some powerful cross-cutting concerns. Apple is wise enough to keep its eyes open and to identify those cross-cutting concerns and embrace them.</p>
<p>This brings me to the iPad. Apple made a lot of news with this device. I found it interesting as it featured a processor designed by a recently acquired processor designer. If the pattern Apple has applied in the past continues, I wouldn&#8217;t be surprised if Apple believes the time is right to switch to a similar custom system on a chip for its next iPhone model.</p>
<p>By embracing the principle of <abbr title="Ya Ain't Gonna Need It">YAGNI</abbr> Apple has reaped the benefits of flexibility. As a software developer, I live in a wondrous age where I can lease a score of servers from Amazon&#8217;s <abbr title="Elastic Compute Cloud">EC2</abbr> system and try out an idea without purchasing a operations center full of computers. If the idea fails, very little harm was done. If the idea takes off, a future purchase of dedicated servers can be arranged. The beauty of it all is that one will already have proof that the idea is viable. The question I&#8217;m left with is this one: why haven&#8217;t I created something to prove the concepts I am talking about?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2010/02/06-yagni-apple-and-ipod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things I learned from the Chrome OS demo.</title>
		<link>http://blog.josh-peters.name/2009/11/20-things-i-learned-from-the-chrome-os-demo/</link>
		<comments>http://blog.josh-peters.name/2009/11/20-things-i-learned-from-the-chrome-os-demo/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 00:45:02 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[netbooks]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=693</guid>
		<description><![CDATA[Today I watched the Google Chrome OS demonstration (11 minutes) video on YouTube®. Here is what I thought of it. Here are my thoughts as I had (time to type) them. Does the public care how fast a computer boots &#8230; <a href="http://blog.josh-peters.name/2009/11/20-things-i-learned-from-the-chrome-os-demo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I watched the <a href="http://www.youtube.com/watch?v=ANMrzw7JFzA">Google Chrome OS demonstration (11 minutes)</a> video on YouTube®. Here is what I thought of it.</p>
<p><span id="more-693"></span>
<p>Here are my thoughts as I had (time to type) them.</p>
<ul>
<li>Does the public care how fast a computer boots up? There&#8217;s got to be an acceptable tolerance that has already been met by the Google Chrome OS efforts.</li>
<li>The presenter has a Jeff Goldblum vibe going on.</li>
<li>The demo was from code checked into trunk? Wonder if the demo will fall on its face at some point &#8230;</li>
<li>I hope the UI changes for &#8220;application tabs&#8221;; favorite icons aren&#8217;t the best way to identify different properties. A plus will be that it becomes more useful for an app developer (I&#8217;m looking your way, <a href="http://www.atlassian.com/">Atlassian</a>) to use separate favicons for its products.</li>
<li>The favicons do have the benefit of being <abbr title="internationalization">i18n</abbr>-friendly.</li>
<li>Panels remind me of the old Google Notebook Firefox add-on. I wonder if Gmail will use panels for its chat window.</li>
<li>Note to self: games do not necessarily mean 3D.</li>
<li>Multiple windows feels a lot like virtual desktops.</li>
<li>I hope Google posts their use cases along with their source code. I doubt it will happen, but one can hope.</li>
<li>Google has got to be working hard to keep Microsoft Office online from breaking in Chrome.</li>
<li>The video sure ends abruptly.</li>
</ul>
<p>I think Google has a hard sell in front of them; I&#8217;d love to know who Chrome OS is for. I know <em>I</em> would love a fast, little netbook that is really good at the few things it should do, but we have a 25 year history of PCs that continue to reinforce comparisons between things that have keyboards, pointing devices, and monitors. Perhaps Google doesn&#8217;t want many folks actually using Chrome OS but want to leverage it as an experiment to create more markets for web applications. Maybe they were really inspired by the One-Laptop-Per-Child project and want a cheap, useful PC to be able to be disseminated.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2009/11/20-things-i-learned-from-the-chrome-os-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with JAR files in Maven</title>
		<link>http://blog.josh-peters.name/2009/07/13-working-with-jar-files-in-maven/</link>
		<comments>http://blog.josh-peters.name/2009/07/13-working-with-jar-files-in-maven/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 18:29:16 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/2009/07/13-working-with-jar-files-in-maven/</guid>
		<description><![CDATA[Apache Maven has become my build tool of choice at work. It seems that nearly every week I learn how to do something new with Maven (part of this is my inexperience, part is the plethora of awesome plug-ins). I&#8217;ve &#8230; <a href="http://blog.josh-peters.name/2009/07/13-working-with-jar-files-in-maven/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://maven.apache.org/">Apache Maven</a> has become my build tool of choice at work. It seems that nearly every week I learn how to do something new with Maven (part of this is my inexperience, part is the plethora of awesome plug-ins).</p>
<p>I&#8217;ve been working on a project lately that is a pretty simple management application that uses JPA in the data layer. One of the goals of this project is to provide a nightly process for parsing input files. I could have tackled this in a variety of ways. My first hope was to create an executable JAR file, but I quickly found that I couldn&#8217;t get very far due to a limitation/feature of JARs: one cannot modify the classpath via the command line interface. My project uses some platform-specific files, so I could not easily include them in the final package. My second attempt ended up working well: create a JAR file within my WAR and execute a class inside that particular JAR.</p>
<p>This project has quite a lot of dependencies: Spring MVC, Hibernate, JPA, Javamail, SQL Server, etc. If I were to create a command-line call to the java executable it would quickly fill up many, many lines in an editor. Fortunately, it&#8217;s easy to include the classpath inside the JAR manifest during the Maven package:</p>
<div>
<pre><code>
&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
  &lt;configuration&gt;
    &lt;archiveClasses&gt;true&lt;/archiveClasses&gt;
    &lt;archive&gt;
      &lt;manifest&gt;
        &lt;addClasspath&gt;true&lt;/addClasspath&gt;
        &lt;mainClass&gt;…&lt;/mainClass&gt;
      &lt;/manifest&gt;
    &lt;/archive&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;
</code></pre>
</div>
<p>The <code>&lt;addClassPath&gt;</code> bit tells Maven to include all of the other dependencies in the manifest file. This is a big deal, as it accomplishes two things: it takes care of me having to write a script to generate the classpath dynamically and it allows me to have a very reasonable length command line statement.</p>
<p>Thanks to letting Maven create a JAR file with its manifest managing the classpath, my resulting java command looks like this: <code>java -cp MyProject.jar:… MyProjectRunner</code> (where MyProjectRunner is a class that I want to execute).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2009/07/13-working-with-jar-files-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SLF4J</title>
		<link>http://blog.josh-peters.name/2009/01/12-slf4j/</link>
		<comments>http://blog.josh-peters.name/2009/01/12-slf4j/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 15:35:32 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/2009/01/12-slf4j/</guid>
		<description><![CDATA[One of the dependencies for dbUnit on it is SLF4J (a.k.a. the Simple Logging Facade for Java).&#160; SLF4J aims to be a wrapper replacement for Java Commons Logging similar to Log4j.&#160; The biggest bonus for using SLF4J is the fact &#8230; <a href="http://blog.josh-peters.name/2009/01/12-slf4j/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the dependencies for dbUnit on it is SLF4J (a.k.a. the Simple Logging Facade for Java).&nbsp; SLF4J aims to be a wrapper replacement for Java Commons Logging similar to Log4j.&nbsp; The biggest bonus for using SLF4J is the fact that at runtime you may use whatever logging implementation you choose.&nbsp; In addition, there&#8217;s a trick that one can do in a Maven build that will force all JCL commands to use SLF4J, which means that JCL can then be logged over Log4J!</p>
<p>Here&#8217;s how to replace JCL with SLF4J:</p>
<pre><code>&lt;dependency&gt;
  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
  &lt;version&gt;99.0-does-not-exist&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  &lt;version&gt;1.5.6&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
  &lt;version&gt;1.5.6&lt;/version&gt;
  &lt;scope&gt;runtime&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
  &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
  &lt;version&gt;1.5.6&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>
<p>Here&#8217;s an explanation of what&#8217;s going on:</p>
<ol>
<li>The first dependency tells Maven that commons logging will be using a non-existent version.&nbsp; You&#8217;ll need to use an empty JAR file or find a repository that will serve you such an empty JAR.&nbsp; The trick is that the version number is ridiculously high and trumps all other versions of JCL.
<li>The second dependency tells Maven to use SLF4J to provide the API for JCL.&nbsp; All Java commons logging calls will then use the SLF4J runtime implementation to provide logging.
<li>The third dependency is the runtime implementation of SLF4J over log4j. In essence, the only calls to log4j are made through SLF4J.
<li>Finally, we&#8217;ll bring in the SLF4J API so <em>our code</em> can use SLF4J instead of JCL or log4j.</li>
</ol>
<p>Here&#8217;s an example of replacing log4j with SLF4J:</p>
<p><strong>Old Version</strong></p>
<pre><code>private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger( Taco.class );</code></pre>
<p><strong>New Version</strong></p>
<pre><code>private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger( Taco.class );</code></pre>
<p>This one line change allows you to change out your runtime logger at will <img src='http://blog.josh-peters.name/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2009/01/12-slf4j/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Issue with the HTML 5 shi[m&#124;v]</title>
		<link>http://blog.josh-peters.name/2008/09/25-the-issue-with-the-html-5-workaround/</link>
		<comments>http://blog.josh-peters.name/2008/09/25-the-issue-with-the-html-5-workaround/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 14:12:51 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=619</guid>
		<description><![CDATA[I&#8217;ve been really interested in HTML 5 lately. I especially enjoy working with bridging existing HTML controls to the HTML 5 equivalents (e.g. making a script that will pick up on the video element and translate it to a HTML &#8230; <a href="http://blog.josh-peters.name/2008/09/25-the-issue-with-the-html-5-workaround/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been really interested in HTML 5 lately.  I especially enjoy working with bridging existing HTML controls to the HTML 5 equivalents (e.g. making a script that will pick up on the <code>video</code> element and translate it to a HTML 4.0.1 equivalent).</p>
<p>It&#8217;s no surprise that the biggest issue getting HTML 5 elements to work in a backwards compatible way is Internet Explorer.  Fortunately, there&#8217;s a world full of folks out there working hard to determine workarounds and hacks until the IE team builds real support into its product.</p>
<p>Cue the <a href="http://ejohn.org/blog/html5-shiv/">HTML 5 shiv</a>.  This workaround is great; elements get full CSS access in Internet Explorer 7.  This means that you can easily style the new elements without too much hassle.  Combine with <a href="http://www.quirksmode.org/css/condcom.html">Internet Explorer&#8217;s excellent conditional comments</a> and you can inject IE-specific javascript code into your page and expect it to work.</p>
<p>Here&#8217;s a problem with this method: the script elements <strong>must</strong> execute <em>prior</em> to when the style sheets are processed.  This is a serious issue that prevents the good coding practice of having your <code>script</code> elements exist at the end of your HTML document, right before the termination of the body element.</p>
<p>What to do?</p>
<p>The big answer is to put the IE-specific code right after the meta-charset element in your HTML 5 document, but this only works for pages that you&#8217;ve got full control over w.r.t. the header.  Not a good fix by most measures.</p>
<p>I&#8217;m still chewing on this one, but so far I&#8217;ve been unable to get IE to re-enable the appropriate style rules at the right time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2008/09/25-the-issue-with-the-html-5-workaround/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WAI-ARIA dynamic attributes?</title>
		<link>http://blog.josh-peters.name/2008/09/08-wai-aria-dynamic-attributes/</link>
		<comments>http://blog.josh-peters.name/2008/09/08-wai-aria-dynamic-attributes/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 13:44:35 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[best-practices]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[aria]]></category>
		<category><![CDATA[wai-aria]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/?p=603</guid>
		<description><![CDATA[I&#8217;ve got a question for the WAI-ARIA folks out there: can I add the attributes dynamically? I&#8217;m sure the best case is to set the attributes on the server, but let&#8217;s say I&#8217;ve got a JSP tag library that isn&#8217;t &#8230; <a href="http://blog.josh-peters.name/2008/09/08-wai-aria-dynamic-attributes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got a question for the WAI-ARIA folks out there: can I add the attributes dynamically?  I&#8217;m sure the best case is to set the attributes on the server, but let&#8217;s say I&#8217;ve got a JSP tag library that isn&#8217;t customizable w.r.t. custom attributes.</p>
<p>A technique I commonly use is to overload CSS classes and transform the elements via client-side Javascript.  For example, if I have a control with a class of &#8220;required&#8221; I can, via Javascript, enforce requirements on the control.  I would love it if I could also set the &#8220;aria-required&#8221; attribute in the same manner and have it work in screen readers.</p>
<p>Can anyone give me an idea of whether or not this works?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2008/09/08-wai-aria-dynamic-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Archetyping with Maven</title>
		<link>http://blog.josh-peters.name/2008/04/23-archetyping-with-maven/</link>
		<comments>http://blog.josh-peters.name/2008/04/23-archetyping-with-maven/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 19:56:44 +0000</pubDate>
		<dc:creator>Josh Peters</dc:creator>
				<category><![CDATA[best-practices]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://blog.josh-peters.name/2008/04/23-archetyping-with-maven/</guid>
		<description><![CDATA[These past two weeks have seen some quality time spent with Apache Maven.&#160; I spent a few days figuring out how to create a custom project archetype in order to streamline project creation in my department. Why Maven? I developed &#8230; <a href="http://blog.josh-peters.name/2008/04/23-archetyping-with-maven/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>These past two weeks have seen some quality time spent with <a href="http://maven.apache.org/">Apache Maven</a>.&nbsp; I spent a few days figuring out how to create a custom project archetype in order to streamline project creation in my department.</p>
<h2>Why Maven?</h2>
<p>I developed a similar system for building projects in <a href="http://ant.apache.org/">Apache Ant</a>.&nbsp; Ant is a great tool that continues to be very useful, but I ran into two issues that prevented me from <em>loving</em> Ant (three if you count the fact that Ant is a piece of software, not a person).</p>
<ol>
<li>Ant could not easily create a project.&nbsp; My old build system involved creating a project copy via <a href="http://subversion.tigris.org/">Subversion</a> and then renaming several resources to correspond.&nbsp; This kludge never really sit well with me.
<li>Ant didn&#8217;t provide me much with regards to profiles and rolling out fixes.&nbsp; A common occurrence I had was to check a project out from SVN, build it, deploy it locally, test it, roll it out to production again, and then check things back into SVN.&nbsp; This involved a lot of tweaking, much of which I was able to streamline, but I never did get everything down so that I could <em>really</em> <a href="http://www.joelonsoftware.com/articles/fog0000000043.html">build in one step</a>.</li>
</ol>
<h2>What Maven Got Me</h2>
<p>Maven addressed both of these issues for me with the notion of a project <samp>archetype</samp>. With a Maven archetype, one can create a &#8220;proto-project&#8221; and instantly create a &#8220;real&#8221; project using it as a base.&nbsp; During initial creation, you can specify the things <em>in one place </em>that I formerly had to follow a post-copy checklist in Subversion to accomplish.&nbsp; This was a huge gain, as it removed a huge portion of the human error that could be introduced in a more manual process.</p>
<p>This in itself wasn&#8217;t enough to really make me like Maven though.&nbsp; The real reason I wanted to use Maven was to solve #2 on the above list.&nbsp; Until I could do that, I would continue to use the checklist-based Ant+Subversion method since it was more widely used already (and I was used to it).</p>
<p>Then I discovered Maven&#8217;s support for build profiles.&nbsp; A profile is essentially a sub-environment for building (or whatever task you are accomplishing with Maven).&nbsp; Using a profile that could allow me to define separate build environments for a single project.&nbsp; Here&#8217;s what I came up with:</p>
<ul>
<li><em>development</em>: working on a project that would then be rolled out to my local machine
<li><em>staging</em>: once a project was sufficiently ready to show off to someone, I could build it using this profile and push it out to a staging server (originally I called this <em>test</em> but that term was way too overloaded already)
<li><em>production</em>: once a project matured from staging I could build it with production settings and push it out to the production server.</li>
</ul>
<p>I incorporated resource filtering in my Maven <samp>pom.xml</samp> file, so each build result would have its resources reflect the profile it was built under.&nbsp; For instance, I have <a href="http://www.ja-sig.org/products/cas/">a central authentication service</a> that my web applications use.&nbsp; Maven will filter the resources so that, at build time, the location of the CAS endpoint changes with the build profile.&nbsp; This is great, because I <em>no longer have to nanny this setting</em>.&nbsp; Huge gain to me, as all of my settings become streamlined.&nbsp; So long as I smartly set up my resources, each build gets the correct settings.</p>
<h2>Caveats</h2>
<p>Maven is still a moving target with regards to its plug-ins especially.&nbsp; Maven&#8217;s archetype plugin changed a lot from version 1 to version 2, and neither version exited the alpha stage.&nbsp; In order to correctly build on Windows, I had to upgrade to the bleeding edge 2.0-alpha-3 version, which I had to <a href="http://jira.codehaus.org/browse/ARCHETYPE">find via the JIRA site</a> and then build and install myself.&nbsp; This is a dependency that <em>should</em> be a non-issue over time, but YMMV.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.josh-peters.name/2008/04/23-archetyping-with-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
