<?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>Jabbering Giraffe &#187; java</title>
	<atom:link href="http://happygiraffe.net/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 20:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>OSGI Intro</title>
		<link>http://happygiraffe.net/blog/2011/03/31/osgi-intro/</link>
		<comments>http://happygiraffe.net/blog/2011/03/31/osgi-intro/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 18:49:58 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[osgi]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1701</guid>
		<description><![CDATA[On Tuesday, I attended the OSGI: Let&#8217;s Get Started session with Simon Maple and Zoë Slattery, courtesy of SkillsMatter and LJC. I figured it&#8217;s time to figure out what I am supposed to be doing with it. For the last &#8230; <a href="http://happygiraffe.net/blog/2011/03/31/osgi-intro/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On Tuesday, I attended the <a href="http://skillsmatter.com/event/java-jee/osgi-lets-get-started">OSGI: Let&#8217;s Get Started</a> session with <a href="http://twitter.com/sjmaple">Simon Maple</a> and <a href="http://twitter.com/zoe_slattery">Zoë Slattery</a>, courtesy of <a href="http://skillsmatter.com/">SkillsMatter</a> and <a href="http://www.meetup.com/Londonjavacommunity/">LJC</a>.  I figured it&#8217;s time to figure out what I am <em>supposed</em> to be doing with it. <code> <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </code></p>
<p><!--TODO: presenter names--></p>
<p>For the last release I enabled OSGI headers for jslint4java.  I was hoping that this session would show me how I fared in that.</p>
<p>First, what is <a href="http://www.osgi.org/Main/HomePage" title="Open Systems Gateway Initiative">OSGI</a>?  At the most basic, it&#8217;s a way of providing some order and structure to the traditional Java classpath.  OSGI achieves this by using <em>bundles</em>.</p>
<p>A <em>bundle</em> is a regular jar file, but with additional metadata in <code>META-INF/MANIFEST.MF</code>.  Details like the name, version and dependencies.  The dependencies are interesting.  A bundle <em>can</em> depend directly on other bundles, but that&#8217;s discouraged.  A better approach is to specify that you depend on java packages.  That way you don&#8217;t have to tie yourself to a particular provider of a package.</p>
<p>When OSGI loads in a bundle, it gives each bundle a unique <a href="http://download.oracle.com/javase/6/docs/api/java/lang/ClassLoader.html">ClassLoader</a>.  This means that:</p>
<ul>
<li>
<p>You can have multiple versions of bundles loaded simultaneously.  You don&#8217;t have to force everything to the same version.</p>
<li>
<p>Each bundle can <em>only</em> see classes that have been explicitly exported by its dependencies, not the whole transitive closure.  This is very good for keeping your code clean.</p>
<p>This also leads to a pattern I&#8217;ve seen before in the maven world: separate artifacts for APIs vs implementation.  Pulling out interfaces is generally a good idea.  But by putting them in a separate OSGI bundle, you enforce that your implementation can remain invisible.  Even the “hello OSGI world” demo was shown this way.</p>
</ul>
<p>On top of this metadata, OSGI provides a runtime for loading and unloading bundles.  The runtime also supports the concept of <em>services</em>, where you can ask the runtime for various services.  This looks cool, but the dynamicity of it can be hard to deal with—that service you got from the runtime can disappear at any point.  There was a demo of something called <a href="http://www.ibm.com/developerworks/opensource/library/os-osgiblueprint/">blueprint</a>, which aims to help, but it looked almost exactly like “more Spring XML” to me.  If I was doing this, I&#8217;d look at <a href="http://code.google.com/p/peaberry/">peaberry</a> instead.</p>
<p>How do you go about getting started with OSGI?  Well, you could manage the bundle metadata yourself, but it&#8217;s much easier to use a tool to do it for you.  One such tool was demo&#8217;d: <a href="http://www.aqute.biz/Code/Bnd">bnd</a>.  The <a href="http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html">maven-bundle-plugin</a> that I used for jslint4java builds on bnd.</p>
<p>If you need a runtime for your app, there are two in common use: <a href="http://www.eclipse.org/equinox/">Equinox</a> and <a href="http://www.eclipse.org/equinox/">Felix</a>.  Equinox is the runtime used by Eclipse.</p>
<p>For followup detail, they recommended checking out anything by <a href="http://njbartlett.name/">Neil Bartlett</a>.  It&#8217;s a shame he couldn&#8217;t make it.</p>
<p>Overall I was pretty impressed.  It made me realise that I got the basics right, and I know where I need to go when I need more.  Thanks, guys!</p>
<p>Having written all this, I&#8217;ve just realised the the <a href="http://en.wikipedia.org/wiki/OSGi">wikipedia page on OSGI</a> demonstrates nearly all of it, and with examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2011/03/31/osgi-intro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Platform Encoding</title>
		<link>http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/</link>
		<comments>http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 13:45:37 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1624</guid>
		<description><![CDATA[This came up at $WORK recently. We had a java program that was given input through command line arguments. Unfortunately, it went wrong when being passed UTF-8 characters (U+00A9 COPYRIGHT SIGN [©]). Printing out the command line arguments from inside &#8230; <a href="http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This came up at <code>$WORK</code> recently.  We had a java program that was given input through command line arguments.  Unfortunately, it went wrong when being passed UTF-8 characters (U+00A9 COPYRIGHT SIGN [©]).  Printing out the command line arguments from inside Java showed that we had double encoded Unicode.</p>
<p>Initially, we just slapped <code>-Dfile.encoding=UTF-8</code> on the command line.  But that failed when the site that called this code went through an automatic restart.  So we investigated the issue further.</p>
<p>We quickly found that the presence of absence of the <code>LANG</code> environment variable had a bearing on the matter.</p>
<p><strong>NB:</strong> <code>ShowSystemProperties.jar</code> is very simple and just lists all system properties in sorted order.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ java <span style="color: #660033;">-version</span>
java version <span style="color: #ff0000;">&quot;1.6.0_16&quot;</span>
Java<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> SE Runtime Environment <span style="color: #7a0874; font-weight: bold;">&#40;</span>build 1.6.0_16-b01<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Java HotSpot<span style="color: #7a0874; font-weight: bold;">&#40;</span>TM<span style="color: #7a0874; font-weight: bold;">&#41;</span> Server VM <span style="color: #7a0874; font-weight: bold;">&#40;</span>build <span style="color: #000000;">14.2</span>-b01, mixed mode<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$LANG</span>
en_GB.UTF-<span style="color: #000000;">8</span>
$ java <span style="color: #660033;">-jar</span> ShowSystemProperties.jar <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> encoding
file.encoding=UTF-<span style="color: #000000;">8</span>
file.encoding.pkg=sun.io
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=UTF-<span style="color: #000000;">8</span>
$ <span style="color: #007800;">LANG</span>= java <span style="color: #660033;">-jar</span> ShowSystemProperties.jar <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> encoding
file.encoding=ANSI_X3.4-<span style="color: #000000;">1968</span>
file.encoding.pkg=sun.io
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=ANSI_X3.4-<span style="color: #000000;">1968</span></pre></div></div>

<p>So, setting <code>file.encoding</code> works, but there&#8217;s an internal property, <code>sun.jnu.encoding</code> as well.</p>
<p>Next, see what happens when we add the explicit override.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">LANG</span>= java -Dfile.encoding=UTF-<span style="color: #000000;">8</span> <span style="color: #660033;">-jar</span> ShowSystemProperties.jar <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> encoding
file.encoding=UTF-<span style="color: #000000;">8</span>
file.encoding.pkg=sun.io
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=ANSI_X3.4-<span style="color: #000000;">1968</span></pre></div></div>

<p>Hey!  <code>sun.jnu.encoding</code> isn&#8217;t changing!</p>
<p>Now, as far as I can see, sun.jnu.encoding isn&#8217;t actually documented anywhere.  So you have to go into the source code for Java (openjdk&#8217;s <a href="http://hg.openjdk.java.net/jdk6/jdk6/jdk/rev/536cbf2d9d0e">jdk6-b16</a> in this case) to figure out what&#8217;s up.</p>
<p>Let&#8217;s start in <code>main()</code>, which is in <a href="http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/536cbf2d9d0e/src/share/bin/java.c">java.c</a>.  Actually, it&#8217;s <code>JavaMain()</code> that we&#8217;re really interested in.  In there you can see:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> JNICALL
JavaMain<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span> _args<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  …
  jobjectArray mainArgs<span style="color: #339933;">;</span>
&nbsp;
  …
  <span style="color: #808080; font-style: italic;">/* Build argument array */</span>
  mainArgs <span style="color: #339933;">=</span> NewPlatformStringArray<span style="color: #009900;">&#40;</span>env<span style="color: #339933;">,</span> argv<span style="color: #339933;">,</span> argc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>mainArgs <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ReportExceptionDescription<span style="color: #009900;">&#40;</span>env<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">goto</span> leave<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  …
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><code>NewPlatformStringArray()</code> is defined in <code>java.c</code> and calls <code>NewPlatformString()</code> repeatedly with each command line argument.  In turn, that calls <code>new String(byte[], encoding)</code>.  It gets the encoding from <code>getPlatformEncoding()</code>.  That essentially calls <code>System.getProperty("sun.jnu.encoding")</code>.</p>
<p>So where does that property get set?  If you look in <a href="http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/536cbf2d9d0e/src/share/native/java/lang/System.c"><code>System.c</code></a>, <code>Java_java_lang_System_initProperties()</code> calls:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">    PUTPROP<span style="color: #009900;">&#40;</span>props<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;sun.jnu.encoding&quot;</span><span style="color: #339933;">,</span> sprops<span style="color: #339933;">-&gt;</span>sun_jnu_encoding<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>sprops appears to get set in <code>GetJavaProperties()</code> in <a href="http://hg.openjdk.java.net/jdk6/jdk6/jdk/file/536cbf2d9d0e/src/solaris/native/java/lang/java_props_md.c">java_props_md.c</a>.  This interprets various environment variables including the one that control the locale.  It appears to pull out everything after the period in the <code>LANG</code> environment variable as the encoding in order to get <code>sun_jnu_encoding</code>.</p>
<p>Phew.  So we now know that there is a special property which gets used for interpreting &#8220;platform&#8221; strings like:</p>
<p>* Command line arguments<br />
* Main class name<br />
* Environment variables</p>
<p>And it <em>can</em> be overridden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">LANG</span>= java -Dsun.jnu.encoding=UTF-<span style="color: #000000;">8</span> -Dfile.encoding=UTF-<span style="color: #000000;">8</span> <span style="color: #660033;">-jar</span> ShowSystemProperties.jar <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> encoding
file.encoding=UTF-<span style="color: #000000;">8</span>
file.encoding.pkg=sun.io
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=UTF-<span style="color: #000000;">8</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The importance of Central</title>
		<link>http://happygiraffe.net/blog/2009/08/23/the-importance-of-central/</link>
		<comments>http://happygiraffe.net/blog/2009/08/23/the-importance-of-central/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 22:33:05 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1588</guid>
		<description><![CDATA[One of the selling points of maven is it&#8217;s dependency mechanism. You say what code you need, and maven makes sure it&#8217;s there for you. The magic behind this is called central. It&#8217;s a phenomenal collection of software (much akin &#8230; <a href="http://happygiraffe.net/blog/2009/08/23/the-importance-of-central/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the selling points of maven is it&#8217;s dependency mechanism.  You say what code you need, and maven makes sure it&#8217;s there for you.  The magic behind this is called <a href="http://repo1.maven.org/maven2/">central</a>.  It&#8217;s a phenomenal collection of software (much akin to Perl&#8217;s <a href="http://search.cpan.org/">CPAN</a>).</p>
<p>This is useful enough that other projects have sprung up that also use central, like <a href="http://ant.apache.org/ivy/">apache ivy</a>.</p>
<p>Central also has source code jars (most of the time).  This means it&#8217;s possible to jump from your piece of code seamlessly into 3rd party code that&#8217;s available on central.  I can&#8217;t imagine getting up to speed with other people&#8217;s code anywhere near as quickly without this sort of facility available.  Sure, the source is available, but is it a single click away from your code?  Not likely.  <a href="http://m2eclipse.sonatype.org/">m2eclipse</a> and <a href="http://www.netbeans.org/community/releases/67/">NetBeans 6.7</a> make this trivial.</p>
<p>So, having your open source project on central is a really good idea.  It lets your users get at it easily and automatically.  You really want to do this.</p>
<p>However, getting your projects on to central isn&#8217;t simple (see <a href="http://maven.apache.org/guides/mini/guide-central-repository-upload.html">Guide to uploading artifacts to the Central Repository</a>).  It boils down to two choices:</p>
<ul>
<li>Package up your code using <a href="http://maven.apache.org/plugins/maven-repository-plugin/bundle-create-mojo.html"><code>mvn repository:bundle-create</code></a> and file a <a href="http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&#038;&#038;pid=10367&#038;resolution=-1&#038;sorter/field=updated&#038;sorter/order=DESC">Jira issue</a> for it.  This can take four weeks or more.</li>
<li>Set up and host an <a href="http://www.samba.org/rsync/">rsync</a>able repository somewhere.  This can be automatically pulled into central.</li>
</ul>
<p>Both of these options are fairly painful.  That&#8217;s why for the latest release of <a href="http://code.google.com/p/jslint4java/">jslint4java</a>, I was pleased to see that <a href="http://www.sonatype.com/">Sonatype</a> are offering an alternative: <a href="https://docs.sonatype.com/display/NX/OSS+Repository+Hosting">oss.sonatype.org</a>.  This is much simpler because you can just use the usual maven deployment mechanism (or presumably ivy equivalent).  A short while later, oss.sonatype.org will sync up with central.</p>
<p>However, the sonatype guys are (rightly) concerned with the quality of artifacts on central.  You have to jump extra hoops to go down this road with your open source projects.  The main one that tripped me up was requiring all artifacts be GPG signed, which entailed learning <a href="http://www.gnupg.org/">GPG</a> and the <a href="http://maven.apache.org/plugins/maven-gpg-plugin/">maven-gpg-plugin</a>.  This took me some time.  However, subsequent releasing to central is much easier now I&#8217;ve been through all the hoops.</p>
<ul>
<li>If you want to get your open source project on central, I&#8217;d definitely recommend checking out oss.sonatype.org.</li>
<li>If you want to contribute to an open source project, offering to help get it on to central could be very useful.  You&#8217;ll not just be helping that project, you&#8217;ll also be helping all users of central.  The bigger it gets the more useful it is.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/08/23/the-importance-of-central/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using JavaRebel with Cocoon</title>
		<link>http://happygiraffe.net/blog/2009/07/31/javarebel-with-cocoon/</link>
		<comments>http://happygiraffe.net/blog/2009/07/31/javarebel-with-cocoon/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 19:58:20 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cocoon]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1580</guid>
		<description><![CDATA[Normally, the cocoon-maven-plugin includes a reloading classloader, so that changes to class files are automatically picked up when do mvn jetty:run. Just hit refresh and your changes get picked up. It&#8217;s just like working in PHP. This is OK, but &#8230; <a href="http://happygiraffe.net/blog/2009/07/31/javarebel-with-cocoon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Normally, the <a href="http://cocoon.apache.org/2.2/maven-plugins/maven-plugin/1.0/1295_1_1.html">cocoon-maven-plugin</a> includes a reloading classloader, so that changes to class files are automatically picked up when do <code>mvn jetty:run</code>. Just hit refresh and your changes get picked up.  It&#8217;s just like working in PHP.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is OK, but it&#8217;s not foolproof.  This morning, I saw a few errors of the form &#8220;expected class SearchManager, but got class SearchManager&#8221;.  This is a case of the same class being loaded by a different ClassLoader.  Annoyingly, I can no longer reproduce this.</p>
<p>There&#8217;s a commercial product, <a href="http://www.zeroturnaround.com/javarebel">JavaRebel</a>, that aims to do a much better reloading ClassLoader.  So, I thought I&#8217;d give it a try.</p>
<p>The basic idea to use it is twofold:</p>
<ul>
<li>Include the javarebel jar as an <a href="http://java.sun.com/javase/6/docs/api/java/lang/instrument/package-summary.html">agent</a>.</li>
<li>Stop jetty from auto-reloading.</li>
</ul>
<p>Of course, this being cocoon, we also have to stop the cocoon-maven-plugin from using its reloading classloader.</p>
<p>The <a href="http://www.zeroturnaround.com/javarebel/installation/">javarebel documentation</a> is quite clear on how to configure maven and jetty.  But it makes no mention of cocoon (understandably).</p>
<p>Thankfully, it&#8217;s all fairly simple to configure with a maven profile.  This makes it easy to call from the command line.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;profile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javarebel<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- Disable Jetty's auto-reload --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.mortbay.jetty<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-jetty-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scanIntervalSeconds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scanIntervalSeconds<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- Disable cocoon's RCL. --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.cocoon<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cocoon-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reloadingClassLoaderEnabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reloadingClassLoaderEnabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;reloadingSpringEnabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/reloadingSpringEnabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugins<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/build<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/profile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>With that in place, all that remains is a teeny-tiny shell script to augment the normal call to maven.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">javarebel_jar</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/javarebel.jar&quot;</span>
<span style="color: #007800;">MAVEN_OPTS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$MAVEN_OPTS</span> -noverify -javaagent:<span style="color: #007800;">$javarebel_jar</span>&quot;</span> mvn <span style="color: #660033;">-Pjavarebel</span> <span style="color: #ff0000;">&quot;$@&quot;</span></pre></div></div>

<p>With this, you can immediately see that javarebel is enabled, as it spits out a big message at startup time.  But more importantly, as soon as I change a spring bean (and reload the page that uses it), I get this on the console:</p>

<div class="wp_syntax"><div class="code"><pre class="none" style="font-family:monospace;">JavaRebel: Reloading class 'com.example.Spigot'.
JavaRebel-Spring: Reconfiguring bean 'spigot' [com.example.Spigot]</pre></div></div>

<p>Hurrah — no errors!  It all seems to work rather well.  I should probably purchase a licence. <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Update:</strong> I&#8217;ve seen the error again:</p>
<blockquote><p>
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:<br />
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.example.MyService] to required type [com.example.MyService] for property &#8216;myService&#8217;; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [com.example.MyService] to required type [com.example.MyService] for property &#8216;myService&#8217;: no matching editors or conversion strategy found<br />
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:104)<br />
	at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)<br />
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1198)<br />
	&#8230; 101 more
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/07/31/javarebel-with-cocoon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solr&#039;s Lucene Source</title>
		<link>http://happygiraffe.net/blog/2009/07/16/solrs-lucene-source/</link>
		<comments>http://happygiraffe.net/blog/2009/07/16/solrs-lucene-source/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 22:15:19 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lucene]]></category>
		<category><![CDATA[solr]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1558</guid>
		<description><![CDATA[I&#8217;m debugging a plugin for Solr. I&#8217;ve just about got the magic voodoo set up so that I can make Eclipse talk to tomcat and stick breakpoints in and so on. But I&#8217;ve immediately run into a problem. Even though &#8230; <a href="http://happygiraffe.net/blog/2009/07/16/solrs-lucene-source/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m debugging a plugin for <a href="http://lucene.apache.org/solr/">Solr</a>.  I&#8217;ve just about got the magic voodoo set up so that I can make Eclipse talk to tomcat and stick breakpoints in and so on.  But I&#8217;ve immediately run into a problem.</p>
<p>Even though Solr itself comes with <code>-sources</code> jars, the bundled copy of lucene that they&#8217;ve used <em>doesn&#8217;t</em>.  Needless to say, this is a bit of a hindrance.</p>
<p>Thankfully, the apache people have set up <a href="http://git.apache.org/">git.apache.org</a>, which makes this situation a lot less annoying than it could be.</p>
<p>First, I checked out copies of lucene &#038; solr.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>git.apache.org<span style="color: #000000; font-weight: bold;">/</span>solr.git
$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>git.apache.org<span style="color: #000000; font-weight: bold;">/</span>lucene.git</pre></div></div>

<p>Now, I need to go into solr and figure out <em>which</em> version of lucene is in use.  Unfortunately, it&#8217;s not a released version, it&#8217;s a snapshot of the lucene trunk at a point in time.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> …<span style="color: #000000; font-weight: bold;">/</span>solr
$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-r</span>
  origin<span style="color: #000000; font-weight: bold;">/</span>HEAD -<span style="color: #000000; font-weight: bold;">&gt;</span> origin<span style="color: #000000; font-weight: bold;">/</span>trunk
  origin<span style="color: #000000; font-weight: bold;">/</span>branch-<span style="color: #000000;">1.1</span>
  origin<span style="color: #000000; font-weight: bold;">/</span>branch-<span style="color: #000000;">1.2</span>
  origin<span style="color: #000000; font-weight: bold;">/</span>branch-<span style="color: #000000;">1.3</span>
  origin<span style="color: #000000; font-weight: bold;">/</span>sandbox
  origin<span style="color: #000000; font-weight: bold;">/</span>solr-ruby-refactoring
  origin<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span>release-1.1.0
  origin<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span>release-1.2.0
  origin<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span>release-1.3.0
  origin<span style="color: #000000; font-weight: bold;">/</span>trunk
$ <span style="color: #c20cb9; font-weight: bold;">git</span> whatchanged origin<span style="color: #000000; font-weight: bold;">/</span>tags<span style="color: #000000; font-weight: bold;">/</span>release-1.3.0 lib
…
commit 904e378b7b4fd18232f657c9daf484a3e63b272c
Author: Yonik Seeley <span style="color: #000000; font-weight: bold;">&lt;</span>yonik<span style="color: #000000; font-weight: bold;">@</span>apache.org<span style="color: #000000; font-weight: bold;">&gt;</span>
Date:   Wed Sep <span style="color: #000000;">3</span> <span style="color: #000000;">20</span>:<span style="color: #000000;">31</span>:<span style="color: #000000;">42</span> <span style="color: #000000;">2008</span> +0000
&nbsp;
    lucene update <span style="color: #000000;">2.4</span>-dev r691741
&nbsp;
    git-svn-id: https:<span style="color: #000000; font-weight: bold;">//</span>svn.apache.org<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>asf<span style="color: #000000; font-weight: bold;">/</span>lucene<span style="color: #000000; font-weight: bold;">/</span>solr<span style="color: #000000; font-weight: bold;">/</span>branches<span style="color: #000000; font-weight: bold;">/</span>branch-<span style="color: #000000;">1.3</span><span style="color: #000000; font-weight: bold;">@</span>691758 13f79535-47bb-0310-<span style="color: #000000;">9956</span>-ffa450edef68
&nbsp;
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> a297b74... 54442dc... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-analyzers-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> 596625b... 5c6e003... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-core-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> db13718... f0f93a7... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-highlighter-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> 50c8cb4... a599f43... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-memory-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> aef3fb8... 79feaef... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-queries-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> 1c733b9... 440fa4e... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-snowball-<span style="color: #000000;">2.4</span>-dev.jar
:<span style="color: #000000;">100644</span> <span style="color: #000000;">100644</span> 0195fa2... b5ff08b... M  lib<span style="color: #000000; font-weight: bold;">/</span>lucene-spellchecker-<span style="color: #000000;">2.4</span>-dev.jar
…</pre></div></div>

<p>So, the last change to lucene was taking a copy of r691741 of lucene&#8217;s trunk.  So, lets go over there.  And see what that looks like.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> …<span style="color: #000000; font-weight: bold;">/</span>lucene
$ <span style="color: #c20cb9; font-weight: bold;">git</span> log <span style="color: #660033;">--grep</span>=<span style="color: #000000;">691741</span></pre></div></div>

<p>Except that doesn&#8217;t return anything.  Because there was no lucene commit at that revision in the original repository (it was <a href="http://svn.apache.org/viewvc?view=rev&#038;revision=691741">something to do with geronimo</a>).  So we need to search backwards for the commit nearest to that revision.  Thankfully, <a href="http://www.kernel.org/pub/software/scm/git/docs/git-svn.html">git svn</a> includes the original subversion revision numbers of each commit.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> …<span style="color: #000000; font-weight: bold;">/</span>lucene
$ <span style="color: #c20cb9; font-weight: bold;">git</span> log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-lne</span> <span style="color: #ff0000;">'if (m/git-svn-id:.*@(\d+)/ &amp;&amp; $1 &lt;= 691741){print $1; exit}'</span>
<span style="color: #000000;">691694</span></pre></div></div>

<p>So now we can go back and find the git commit id that corresponds.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> …<span style="color: #000000; font-weight: bold;">/</span>lucene
$ <span style="color: #c20cb9; font-weight: bold;">git</span> log <span style="color: #660033;">--grep</span>=<span style="color: #000000;">691694</span>
commit 71afff2cebd022fe63bdf2ec4b87aaa0cee41dc8
Author: Michael McCandless <span style="color: #000000; font-weight: bold;">&lt;</span>mikemccand<span style="color: #000000; font-weight: bold;">@</span>apache.org<span style="color: #000000; font-weight: bold;">&gt;</span>
Date:   Wed Sep <span style="color: #000000;">3</span> <span style="color: #000000;">17</span>:<span style="color: #000000;">34</span>:<span style="color: #000000;">29</span> <span style="color: #000000;">2008</span> +0000
&nbsp;
    LUCENE-<span style="color: #000000;">1374</span>: fix <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #000000; font-weight: bold;">case</span> to close reader<span style="color: #000000; font-weight: bold;">/</span>writer <span style="color: #000000; font-weight: bold;">in</span> try<span style="color: #000000; font-weight: bold;">/</span>finally; add assert b<span style="color: #000000; font-weight: bold;">!</span>=null <span style="color: #000000; font-weight: bold;">in</span> RAMOutputStream.writeBytes <span style="color: #7a0874; font-weight: bold;">&#40;</span>matches FSIndexOutput <span style="color: #c20cb9; font-weight: bold;">which</span> hits NPE<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    git-svn-id: https:<span style="color: #000000; font-weight: bold;">//</span>svn.apache.org<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>asf<span style="color: #000000; font-weight: bold;">/</span>lucene<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">@</span>691694 13f79535-47bb-0310-<span style="color: #000000;">9956</span>-ffa450edef68</pre></div></div>

<p>Hurrah!  Now I can checkout the same version of Lucene that&#8217;s in Solr.  But, probably more useful for Eclipse, is just to zip it up somewhere.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> …<span style="color: #000000; font-weight: bold;">/</span>lucene
$ <span style="color: #c20cb9; font-weight: bold;">git</span> archive <span style="color: #660033;">--format</span>=<span style="color: #c20cb9; font-weight: bold;">zip</span> 71afff2 <span style="color: #000000; font-weight: bold;">&gt;/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>lucene-<span style="color: #000000;">2.4</span>-r691741.zip</pre></div></div>

<p>Excellent.  Now I can resume my debugging session. <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>NB: I <em>could</em> have just used subversion to check out the correct revision of Lucene.  But, I find it quicker to use git to clone the repository, and I get the added benefit that I now have the whole lucene history available.  So I can quickly see <em>why</em> something was changed.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/07/16/solrs-lucene-source/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The Maven Ecosystem</title>
		<link>http://happygiraffe.net/blog/2009/06/18/the-maven-ecosystem/</link>
		<comments>http://happygiraffe.net/blog/2009/06/18/the-maven-ecosystem/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 11:31:14 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javawug]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1541</guid>
		<description><![CDATA[Last night I went to see Jason van Zyl of sonatype talking about various bits of the maven ecosystem, and where they&#8217;re going. The main bit for me was what&#8217;s coming up in maven 3.0. There was a great deal &#8230; <a href="http://happygiraffe.net/blog/2009/06/18/the-maven-ecosystem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night I went to see <a href="http://twitter.com/jvanzyl">Jason van Zyl</a> of <a href="http://www.sonatype.com/">sonatype</a> talking about various bits of <a href="http://www.jroller.com/javawug/entry/javawug_bof_49_maven_3">the maven ecosystem</a>, and where they&#8217;re going.  The main bit for me was what&#8217;s coming up in maven 3.0.  There was a great deal of talk about <a href="http://www.osgi.org/">OSGI</a> related issues, but it reinforced my belief that whilst there&#8217;s some good technology in there, it&#8217;s still quite complicated to use and manage.  Steps are being taken to address this (better tooling support), but they&#8217;re not there yet.  Also, for the kind of things I do (simple, content-driven, somewhat static webapps), it doesn&#8217;t seem to be necessary anyway.</p>
<p>So what&#8217;s coming up in maven 3.0?  Fundamentally, there won&#8217;t be that many new user-visible features (wait for 3.1!).  Internally, there have been <em>huge</em> refactorings by the sound of things (along with integration tests to ensure no user-visible regressions).  They&#8217;re switching away from <a href="http://plexus.codehaus.org/">plexus</a> and towards <a href="http://code.google.com/p/google-guice/">guice</a> + <a href="http://code.google.com/p/peaberry/">peaberry</a>.  But that&#8217;s internal detail.  And in theory, it shouldn&#8217;t matter even if you&#8217;re a plugin author.</p>
<p>What sounded really nice was the focus on making life much easier for users of the embedded maven.  Primarily, this means IDE authors.  Things like plugin &#038; lifecycle extension points, and incremental build support should allow m2eclipse to be much, much more intelligent about the work they do.  Jason mentioned that a version of m2eclipse which builds on the trunk of maven 3.0 can now build the trunk of maven in seconds rather than minutes.  Why?  Because it&#8217;s not duplicating work that&#8217;s already been done by Eclipse.</p>
<p>The main change is to the artifact resolution system.  It&#8217;s been one of the main source of bugs in maven 2.0.  It&#8217;s been completely junked in 3.0 and replaced with <a href="http://maven.apache.org/mercury/index.html">mercury</a>, which handles both transport and resolving artifacts.  It should be better tested, and things like version ranges much closer to how OSGI does things.</p>
<p>One (minor) change is that the error messages should be much better.  That&#8217;s a welcome relief.</p>
<p>There are other tidbits that I <em>think</em> are scheduled for 3.1 that should be really nice:</p>
<ul>
<li>everybody&#8217;s favourite: versionless parent elements</li>
<li>attributes in the POM — hooray, that should make POMs vastly smaller.</li>
<li>mixin POMs — should allow much more flexibility in constructing dependencies on both groups of artifacts and groups of plugins.</li>
</ul>
<p>There were further talks about <a href="https://hudson.dev.java.net/">hudson</a> &#038; <a href="http://nexus.sonatype.org/">nexus</a>, but I&#8217;m fairly familiar with these, so I didn&#8217;t see much of news to me.</p>
<p>My thanks go to <a href="http://www.jroller.com/peter_pilgrim/">Peter Pilgrim</a> for organising and <a href="http://www.conchango.com/">EMC/Comchango</a> for hosting.<a href="http://www.conchango.com/"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/18/the-maven-ecosystem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>dependency complexity</title>
		<link>http://happygiraffe.net/blog/2009/06/01/dependency-complexity/</link>
		<comments>http://happygiraffe.net/blog/2009/06/01/dependency-complexity/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 20:52:04 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1521</guid>
		<description><![CDATA[I love the google-collections library. It&#8217;s got some really nice features. But, it’s not stable yet. They&#8217;ve explicitly stated that until they hit 1.0 it’s not going to be a stable API. So there are changes each release. Nothing major, &#8230; <a href="http://happygiraffe.net/blog/2009/06/01/dependency-complexity/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I love the <a href="http://code.google.com/p/google-collections/">google-collections</a> library. It&#8217;s got some <a href="http://happygiraffe.net/blog/2008/07/22/google-collections-to-the-rescue/">really nice features</a>. But, it’s not stable yet. They&#8217;ve explicitly stated that until they hit 1.0 it’s not going to be a stable API. So there are changes each release. Nothing major, but changes.</p>
<p>As an example, in the jump from <a href="http://code.google.com/p/google-collections/wiki/Releases#Release_0.9_(snapshot_20090211)">0.9</a> to <a href="http://code.google.com/p/google-collections/wiki/Releases#Release_1.0_(RC1_-_20090406)">1.0rc1</a>, the static methods on the Join class became the fluent API on the <a href="http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Joiner.html">Joiner</a> class.</p>
<p>(as an aside, could we have some <a href="http://google-collections.googlecode.com/svn/tags/">tags</a>, please?)</p>
<p>Following this change is simple.</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;"><span style="color: #440088;">@@ -310,7 +310,7 @@</span>
         <span style="">&#125;</span> catch <span style="">&#40;</span>KeyStoreException e<span style="">&#41;</span> <span style="">&#123;</span>
             throw new RuntimeException<span style="">&#40;</span>e<span style="">&#41;</span>;
         <span style="">&#125;</span>
<span style="color: #991111;">-        return Join.join<span style="">&#40;</span>&quot; | &quot;, principals<span style="">&#41;</span>;</span>
<span style="color: #00b000;">+        return Joiner.on<span style="">&#40;</span>&quot; | &quot;<span style="">&#41;</span>.join<span style="">&#40;</span>principals<span style="">&#41;</span>;</span>
     <span style="">&#125;</span>
&nbsp;
     /**</pre></div></div>

<p>But the knock-on effect comes when you start getting lots of things which have google-collections dependencies.  At <code>$WORK</code>, I&#8217;ve got a project whose dependencies look like this.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/06/dc2-deps-before.png" alt="dc2-deps-before.png" border="0" width="264" height="380" /></div>
<p>I wanted to extract a part of DC2 into its own library, <code>commslib</code>.  This was pretty easy as the code was self contained.  Naturally, I wanted it to use the latest version of everything, so I upgraded google-collections to 1.0rc1.  Again, fairly simple.</p>
<p>This is what I ended up with.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/06/dc2-deps-after.png" alt="dc2-deps-after.png" border="0" width="293" height="380" /></div>
<p>Except that now there&#8217;s a problem.</p>
<ul>
<li>commslib uses <code>Joiner</code>, so it&#8217;ll blow up unless it upgrade <code>DC2</code>&#8216;s google-collections to 1.0rc1.</li>
<li>GSK uses <code>Join</code>, so it&#8217;ll blow up if I upgrade <code>DC2</code>&#8216;s google-collections to 1.0rc1.</li>
</ul>
<p>And thus have I painted myself into a corner.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As it happens, <code>DC2</code> had a <a href="http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management">dependencyManagement</a> section forcing everything to use google-collections 0.8.  &rarr; Instant <em>BOOM</em>.</p>
<p>The solution is to upgrade all my dependencies to use google-collections 1.0rc1.  But this turns out to be a much larger change than I had originally envisaged, as now I have to create releases for two dependent projects.  This isn&#8217;t too much of a hassle in this case (yay for the <a href="http://maven.apache.org/plugins/maven-release-plugin/">maven-release-plugin</a>), but it could be a large undertaking if either of those projects is not presently in a releasable state.</p>
<p>I&#8217;m not trying to pick on google-collections (I still love it).  I&#8217;m just marvelling at how quickly complexity can blossom from something so simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/06/01/dependency-complexity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>java -jar blats your classpath</title>
		<link>http://happygiraffe.net/blog/2009/04/30/java-jar-blats-your-classpath/</link>
		<comments>http://happygiraffe.net/blog/2009/04/30/java-jar-blats-your-classpath/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 19:13:26 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1517</guid>
		<description><![CDATA[This tripped up a colleague today. When he mentioned it, about three other people (myself included) piped up with oh yeah, that caught me out a while back. java -cp 'a.jar:b.jar' -jar foo.jar This completely ignores the classpath. It&#8217;s not &#8230; <a href="http://happygiraffe.net/blog/2009/04/30/java-jar-blats-your-classpath/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This tripped up a colleague today.  When he mentioned it, about three other people (myself included) piped up with <q>oh yeah, that caught me out a while back</q>.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  java <span style="color: #660033;">-cp</span> <span style="color: #ff0000;">'a.jar:b.jar'</span> <span style="color: #660033;">-jar</span> foo.jar</pre></div></div>

<p>This completely ignores the classpath.  It&#8217;s not blindingly obvious that this is going on.  If you manage to wind your way down to <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html#standard">java(1)</a>, you do see:</p>
<blockquote>
<dl>
<dt><strong>-jar</strong></dt>
<dd>
<p>Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form <strong>Main-Class: <em>classname</em></strong>. Here, <em>classname</em> identifies the class having the <code>public static void main(String[] args)</code> method that serves as your application&#8217;s starting point. See the <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/jar.html">Jar tool reference page</a> and the Jar trail of the <a href="http://java.sun.com/docs/books/tutorial/jar">Java Tutorial</a> for information about working with Jar files and Jar-file manifests.</p>
<p><u>When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.</u></p>
<p>Note that JAR files that can be run with the &#8220;java -jar&#8221; option can have their execute permissions set so they can be run without using &#8220;java -jar&#8221;. Refer to <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/index.html">Java Archive (JAR) Files</a>.</p>
</dd>
</dl>
</blockquote>
<p>(underlining mine)</p>
<p>This is fairly clear, but unless you&#8217;re used to looking for man pages, this might well not be found.  In particular, some indication on the <code>java -help</code> output would be a boon.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/04/30/java-jar-blats-your-classpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Java Memory Analysis</title>
		<link>http://happygiraffe.net/blog/2009/04/13/more-java-memory-analysis/</link>
		<comments>http://happygiraffe.net/blog/2009/04/13/more-java-memory-analysis/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 19:21:24 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mat]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1503</guid>
		<description><![CDATA[If you found Heap Dump Analysis interesting, you might also be interested in Identifying ThreadLocal Memory Leaks in JavaEE Web Apps from Igo Molnar. I saw this a day or so after my original post. He uses The eclipse memory &#8230; <a href="http://happygiraffe.net/blog/2009/04/13/more-java-memory-analysis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you found <a href="http://happygiraffe.net/blog/2009/04/02/heap-dump-analysis/">Heap Dump Analysis</a> interesting, you might also be interested in <a href="http://blog.igorminar.com/2009/03/identifying-threadlocal-memory-leaks-in.html">Identifying ThreadLocal Memory Leaks in JavaEE Web Apps</a> from <a href="http://blog.igorminar.com/">Igo Molnar</a>.  I saw this a day or so after my original post.  He uses The <a href="http://www.eclipse.org/mat/">eclipse memory analysis tool (MAT)</a> to figure out what&#8217;s going on.</p>
<p>In his case, he <a href="http://blog.igorminar.com/2009/03/identifying-threadlocal-memory-leaks-in.html?showComment=1238593380000#c2003539858355670950">couldn&#8217;t use visualvm</a> as the heap dump was too large.</p>
<p>I downloaded MAT for my problem and had a look at it.  It seems like it does much more than visualvm (there are may &#8220;pre-canned&#8221; queries available, plus an &#8220;object query language&#8221;).  But that makes it correspondingly harder to use.  I spent a while going through the tutorials to get the hang of it, whereas visualvm seemed to come together quickly for me.  I suspect that if I ploughed more time into it, I&#8217;d get a lot more out of it.  It seems to be something that I should learn <em>before</em> I get to need it again.  <img src='http://happygiraffe.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/04/13/more-java-memory-analysis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heap Dump Analysis</title>
		<link>http://happygiraffe.net/blog/2009/04/02/heap-dump-analysis/</link>
		<comments>http://happygiraffe.net/blog/2009/04/02/heap-dump-analysis/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 08:30:40 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[visualvm]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1498</guid>
		<description><![CDATA[As part of the investigation into cocoon memory usage, I had to try and understand what was going on inside the JVM. The best way to do that is a heap dump. The general idea is to dump out the &#8230; <a href="http://happygiraffe.net/blog/2009/04/02/heap-dump-analysis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As part of the investigation into cocoon memory usage, I had to try and understand what was going on inside the JVM.  The best way to do that is a heap dump.  The general idea is to dump out the contents of the JVM&#8217;s memory into a file, then analyse it using a tool.</p>
<p>First, getting a heap dump.  This used to be something of a pain, but Java 6 now includes the <a href="http://java.sun.com/javase/6/docs/technotes/tools/share/jmap.html">jmap -dump</a> command.  This allows you to (relatively) easily extract a heap dump from a running JVM.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #007800;">pid</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>some<span style="color: #000000; font-weight: bold;">/</span>where<span style="color: #000000; font-weight: bold;">/</span>pid.txt<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #007800;">jmap</span>=<span style="color: #007800;">$JAVA_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>jmap
  <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #007800;">$jmap</span> <span style="color: #660033;">-F</span> -dump:live,<span style="color: #007800;">format</span>=b,<span style="color: #007800;">file</span>=mla-post-cache-clear.hprof <span style="color: #007800;">$pid</span></pre></div></div>

<p>That takes a little while (a minute or two) to run, and ended up with a 500Mb file.  It&#8217;s best to bring it back to your workstation in order to look through.  Thankfully it compresses quite nicely.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">time</span> rsync <span style="color: #660033;">-avz</span> server:mla-post-cache-clear.hprof .
  receiving <span style="color: #c20cb9; font-weight: bold;">file</span> list ... <span style="color: #000000; font-weight: bold;">done</span>
  mla-post-cache-clear.hprof
&nbsp;
  sent <span style="color: #000000;">42</span> bytes  received <span style="color: #000000;">72988157</span> bytes  <span style="color: #000000;">3105880.81</span> bytes<span style="color: #000000; font-weight: bold;">/</span>sec
  total <span style="color: #c20cb9; font-weight: bold;">size</span> is <span style="color: #000000;">580115453</span>  speedup is <span style="color: #000000;">7.95</span>
  rsync <span style="color: #660033;">-avz</span> server:mla-post-cache-clear.hprof .  8.42s user 2.85s system <span style="color: #000000;">47</span><span style="color: #000000; font-weight: bold;">%</span> cpu <span style="color: #000000;">23.643</span> total</pre></div></div>

<p>Now things get interesting.  We can fire up <a href="https://visualvm.dev.java.net/">visualvm</a>.  Inside visualvm, do File &rarr; Load… and point it at the heap dump file we just obtained.  You should end up with something like this:</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/04/visualvm-heap-dump-summary.png" alt="VisualVM 1.1 heap dump summary" border="0" width="444" height="409" /></div>
<p>Now this is interesting, but not <em>that</em> useful.  If you click on the classes button, you see this:</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/04/visualvm-11-classes-in-heap-dump.png" alt="VisualVM 1.1 classes in heap dump" border="0" width="680" height="487" /></div>
<p>What&#8217;s really interesting about that is the <code>byte[]</code> line.  Those instances are only 2% of objects, but are taking up 67% of memory!  If you double click on that line, you get taken through to the instances view.</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/04/visualvm-11-instances-inheap-dump.png" alt="VisualVM 1.1 instances inheap dump" border="0" width="686" height="518" /></div>
<p>There are three panels here:</p>
<ol>
<li>The left hand view is a list of all the instances, ordered by size.  In this case the top instances are the same size, which is quite suspicious.</li>
<li>The top right hand view is a breakdown of the fields in the object.  Not that useful for a <code>byte[]</code>.</li>
<li>The bottom right hand view is the useful one — it lists all references to this instance.  Here it&#8217;s showing that thi <code>byte[]</code> is linked to a ByteArrayOutputStream.</li>
</ol>
<p>Now, you can expand the references to that <code>byte[]</code> to find out where it&#8217;s being referenced.  But there&#8217;s a really nifty trick.  If you right-click, you get an option to &#8220;Show Nearest GC Root&#8221;.  And this is what it shows (after a little while).</p>
<div style="text-align:center;"><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/04/visualvm-11-nearest-gc-root.png" alt="VisualVM 1.1 nearest GC root" border="0" width="800" height="301" /></div>
<p>This isn&#8217;t the simplest thing to interpret.  But, it does show that the <a href="https://svn.apache.org/repos/asf/cocoon/trunk/subprojects/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/HttpServletResponseBufferingWrapper.java">HttpServletResponseBufferingWrapper</a> is holding the <code>byte[]</code> itself.  Whilst that servlet response is held by a <a href="http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-components/src/main/java/org/apache/cocoon/transformation/TraxTransformer.java">TraxTransformer</a>.  That sounds like a good place to begin investigating.  Why is TraxTransformer holding on to ServletResponses?</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/04/02/heap-dump-analysis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

