<?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>And now here&#039;s something… &#187; java</title>
	<atom:link href="http://christiansons.net/mike/blog/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://christiansons.net/mike/blog</link>
	<description>Java, Ant, SVN, Jetty, cygwin and other stuff…</description>
	<lastBuildDate>Fri, 02 Dec 2011 16:53:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java 7 : Fork and Join</title>
		<link>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/</link>
		<comments>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 17:38:22 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[forkjoin]]></category>
		<category><![CDATA[java7]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=747</guid>
		<description><![CDATA[Check out Julien Ponge&#8217;s article on Fork and Join in Java 7.]]></description>
			<content:encoded><![CDATA[<p>Check out Julien Ponge&#8217;s article on <a href="http://www.oracle.com/technetwork/articles/java/fork-join-422606.html">Fork and Join in Java 7</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2011/08/java-7-fork-and-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes on Java&#8217;s Date class</title>
		<link>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/</link>
		<comments>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 21:55:07 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=560</guid>
		<description><![CDATA[Every so often I get myself confused about Java&#8217;s often-obtuse handling of dates and timezones. So, for my future self&#8217;s benefit, here are some reminder notes&#8230; Please leave a comment if you have corrections or additional tips! (And, preemptively, yes, some day I&#8217;ll give Joda Time a try.) Dates do not have timezones; they reflect <a href='http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Every so often I get myself confused about Java&#8217;s often-obtuse handling of dates and timezones.  So, for my future self&#8217;s benefit, here are some reminder notes&#8230;  <span id="more-560"></span></p>
<p>Please leave a comment if you have corrections or additional tips!  (And, preemptively, yes, some day I&#8217;ll give <a href="http://joda-time.sourceforge.net/">Joda Time</a> a try.)</p>
<ul>
<li><tt>Date</tt>s do not have timezones; <a href="http://download.oracle.com/javase/6/docs/api/java/util/Date.html"> they reflect UTC</a>.</li>
<li><a href="http://download.oracle.com/javase/6/docs/api/java/util/Date.html#toString()"><tt>Date.toString()</tt></a> returns a <tt>String</tt> representation based on the local machine&#8217;s default timezone.  This makes people think that <tt>Date</tt>s have timezones.</li>
<li>You cannot convert a <tt>Date</tt> from one timezone to another.</li>

<div class="wp_syntax"><div class="code"><pre class="java5" style="font-family:monospace;"><span style="color: #003399; font-weight: bold;">Calendar</span> c = <span style="color: #003399; font-weight: bold;">Calendar</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTime</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399; font-weight: bold;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">Date</span> utc = c.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
c.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399; font-weight: bold;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;America/Phoenix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399; font-weight: bold;">Date</span> mst = c.<span style="color: #006633;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #339933;">!</span>utc.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>mst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//throws AssertionError</span></pre></div></div>

<li>However, you <em>can</em> use <tt>DateFormat</tt> to affect the <tt>String</tt> representation of a <tt>Date</tt>, including the timezone.</li>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Date</span> date <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">SimpleDateFormat</span> utcFormat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ddHHmm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">SimpleDateFormat</span> mstFormat <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SimpleDateFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ddHHmm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
utcFormat.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UTC&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
mstFormat.<span style="color: #006633;">setTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">TimeZone</span>.<span style="color: #006633;">getTimeZone</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;America/Phoenix&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> utc <span style="color: #339933;">=</span> utcFormat.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> mst <span style="color: #339933;">=</span> mstFormat.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> <span style="color: #339933;">!</span>utc.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>mst<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//should not throw AssertionError</span></pre></div></div>

</ul>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/09/notes-on-javas-date-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun Java 6 on Ubuntu 10.04 10.10 and later</title>
		<link>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/</link>
		<comments>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 16:17:04 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=512</guid>
		<description><![CDATA[Post updated 2011 Jan 19: Given the opportunity to install 10.10, I have added different instructions for Ubuntu 10.10 (Maverick Meerkat). Much to my surprise, but probably not those of the Open Source Ruling Class, Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse. Apparently the Ubuntu folks have started putting some weight behind <a href='http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><em><strong>Post updated 2011 Jan 19</strong>: Given the opportunity to install 10.10, I have added <a href="#1010">different instructions for Ubuntu 10.10</a> (Maverick Meerkat).</em></p>
<p>Much to my surprise, but probably not those of the Open Source Ruling Class, <a href="https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Sun%20Java%20moved%20to%20the%20Partner%20repository">Sun&#8217;s Java 6 has been removed from the Ubuntu Multiverse</a>.  Apparently the Ubuntu folks have started putting some weight behind their recommendations for switching to the &#8220;OpenJDK.&#8221;  Fortunately, the official, &#8220;proprietary&#8221; Java is still available through another Ubuntu repository.</p>
<h2 id="1010">Ubuntu 10.10</h2>
<p>To install Sun&#8217;s Java 6 JDK on Ubuntu 10.10, add the <a href="https://launchpad.net/~sun-java-community-team/+archive/sun-java6">Sun Java6 Community PPA</a> and install: </p>
<pre>
add-apt-repository ppa:sun-java-community-team/sun-java6
apt-get update
apt-get install sun-java6-jdk
update-java-alternatives -s java-6-sun
</pre>
<h2>Ubuntu 10.04</h2>
<p>To make Sun&#8217;s Java 6 JDK available on Ubuntu 10.04 add the new repository like so:</p>
<pre>
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
aptitude update
aptitude install sun-java6-jdk
update-java-alternatives -s java-6-sun
</pre>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/07/sun-java-6-on-ubuntu-10-04-10-10-and-later/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Shutting down ehcache properly</title>
		<link>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/</link>
		<comments>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:37:29 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[ehcache]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[persistence]]></category>
		<category><![CDATA[shutdownhook]]></category>

		<guid isPermaLink="false">http://christiansons.net/mike/blog/?p=422</guid>
		<description><![CDATA[If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to shut down ehcache properly. To do so when using ehcache within a webapp, simply add its ShutdownListener as a listener in web.xml. &#60;listener&#62; &#60;listener-class&#62;net.sf.ehcache.constructs.web.ShutdownListener&#60;/listener-class&#62; &#60;/listener&#62; Alternatively, or when not using ehcache inside a webapp, instruct ehcache <a href='http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using ehcache&#8217;s disk persistence feature, which allows the cache to survive across JVM restarts, be sure to <a href="http://ehcache.org/documentation/shutdown.html">shut down ehcache properly</a>.</p>
<p>To do so when using ehcache within a webapp, simply add its <tt>ShutdownListener</tt> as a <tt>listener</tt> in <tt>web.xml</tt>.</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;listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.sf.ehcache.constructs.web.ShutdownListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Alternatively, or when not using ehcache inside a webapp, instruct ehcache to register its own <a href="http://java.sun.com/developer/TechTips/2000/tt0711.html">shutdown hook</a> by setting a system property.</p>
<pre>net.sf.ehcache.enableShutdownHook=true</pre>
<p>If you forget one of the above, your persisted cache may not be up-to-date, or worse, not persisted at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2010/01/shutting-down-ehcache-properly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Advanced Installer licensing within a Java application</title>
		<link>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/</link>
		<comments>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 03:31:34 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[advancedinstaller]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=108</guid>
		<description><![CDATA[Advanced Installer 6.7 has a new licensing and registration feature which allows for time-limited demos/trials and registration of installed software. Caphyon, the maker of Advanced Installer, provides code samples and documentation on licensing integration for C++ and C# applications. To use this feature, the application must make a call into an Advanced Installer library and <a href='http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.advancedinstaller.com/"><img alt="" src="http://www.caphyon.com/img/index/biglogo_ai.gif" title="Advanced Installer" class="alignleft" width="69" height="99" /></a>Advanced Installer 6.7 has a <a href="http://www.advancedinstaller.com/user-guide/licensing.html">new licensing and registration feature</a> which allows for time-limited demos/trials and registration of installed software.</p>
<p>Caphyon, the maker of Advanced Installer, provides code samples and <a href="http://www.advancedinstaller.com/user-guide/qat-trial.html">documentation on licensing integration</a> for C++ and C# applications.  To use this feature, the application must make a call into an Advanced Installer library and handle its return code.  </p>
<p>The library is a gatekeeper to the rest of the application, effectively deciding whether or not the application is allowed to run.  It determines the software&#8217;s trial status and displays a registration dialog, terminates the application, or returns a code, accordingly.  The Java implementation of this feature works a little differently.</p>
<p>For those using the <a href="http://www.advancedinstaller.com/user-guide/native-java-launcher.html">Java Launcher</a>, integrating the licensing feature is easy: simply add the Java Product on the <a href="http://www.advancedinstaller.com/user-guide/licensing-settings.html">Licensing Options</a> tab.  But, what about those who don&#8217;t use Java Launcher?  Or those that wish to enable users to register from within the application?</p>
<p>There is no official documentation which answers these questions, but based on a discussion following a <a href="http://www.advancedinstaller.com/forums/viewtopic.php?f=2&#038;t=8538">request for help I posted on the Advanced Installer forums</a>, I was able integrate AI&#8217;s licensing feature into my Java application without using the Java Launcher.<span id="more-108"></span></p>
<p>My solution mirrors the C++ implementation and is remarkably simple.  Thanks to Cosmin, a member of the Advanced Installer support team, for sending me in the right direction.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LicenseChecker <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> LIBRARY_KEY <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Replace this String with the Trialware/Registration Library Key&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> TrialLibrary.<span style="color: #006633;">INSTANCE</span>.<span style="color: #006633;">ReadSettingsStr</span><span style="color: #009900;">&#40;</span>LIBRARY_KEY, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//http://www.advancedinstaller.com/user-guide/qa-trial-using.html</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for registering this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank you for trying this program.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Program will continue.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// ...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">interface</span> TrialLibrary <span style="color: #000000; font-weight: bold;">extends</span> Library <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">final</span> TrialLibrary INSTANCE <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TrialLibrary<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">Native</span>.<span style="color: #006633;">loadLibrary</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Trial&quot;</span>, TrialLibrary.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// loads Trial.dll</span>
        <span style="color: #000066; font-weight: bold;">int</span> ReadSettingsStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> DisplayRegistrationStr<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> keyCode, HWND hwnd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Note: The above uses <a href="https://jna.dev.java.net/">Java Native Access (JNA)</a> to invoke the Advanced Installer library.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/02/use-advanced-installer-licensing-within-a-java-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obfuscating a webapp .war file with yGuard and Ant</title>
		<link>http://christiansons.net/mike/blog/2009/02/obfuscating-a-webapp-war-file-with-yguard-and-ant/</link>
		<comments>http://christiansons.net/mike/blog/2009/02/obfuscating-a-webapp-war-file-with-yguard-and-ant/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 19:07:03 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[ant]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[yguard]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=178</guid>
		<description><![CDATA[One way to protect Java software from casual reverse engineering is obfuscation. Essentially, an obfuscator renames classes, variables, and packages with random/meaningless names. The application still functions correctly; the decompiled code becomes difficult to read. There are quite a few obfuscators for Java &#8212; at least a dozen when I looked &#8212; most of which <a href='http://christiansons.net/mike/blog/2009/02/obfuscating-a-webapp-war-file-with-yguard-and-ant/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>One way to protect Java software from casual reverse engineering is obfuscation.  Essentially, an obfuscator renames classes, variables, and packages with random/meaningless names.  The application still functions correctly; the decompiled code becomes difficult to read.</p>
<p>There are quite a few obfuscators for Java &#8212; at least a dozen when I looked &#8212; most of which are easily used from an Ant script.  </p>
<p>For my use I selected one with a ready-to-use Ant task: <a href="http://www.yworks.com/en/products_yguard_about.html">yGuard</a>.  Unfortunately, yGuard operates on .jar files only, not individual .class files or webapp .war files.  Thus, I have written my own Ant script which uses yGuard and built-in Ant tasks to obfuscate .war files.<span id="more-178"></span></p>
<p style="border: thin dashed;"><em>Update 2009-12-11</em>: If I had to do it over again, I would obfuscate my classes/jars before creating the .war file.</p>
<p>Before you try using my Ant script, read <a href="http://www.yworks.com/products/yguard/yguard_ant_howto.html">yGuard&#8217;s documentation</a> and be sure you fully understand how it works.  You should pay special attention to the <a href="http://www.yworks.com/products/yguard/yguard_ant_howto.html#inoutpairs">inoutpairs</a>, <a href="http://www.yworks.com/products/yguard/yguard_ant_howto.html#keep">keep</a>, and <a href="http://www.yworks.com/products/yguard/yguard_ant_howto.html#hints">hints and troubleshooting</a> sections.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- prepare a temporary directory in which the war file is expanded and obfuscated --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tempfile</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;unwar.dir&quot;</span> <span style="color: #000066;">destdir</span>=<span style="color: #ff0000;">&quot;${java.io.tmpdir}&quot;</span> <span style="color: #000066;">deleteonexit</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;unwar</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;webapp.war&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${unwar.dir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- create a jar of webapp classes (required by yguard) for obfuscation --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jar</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib/webapp.jar&quot;</span> <span style="color: #000066;">whenempty</span>=<span style="color: #ff0000;">&quot;fail&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/classes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/classes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- create a fileset of internal libraries to be obfuscated --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;internal.lib.set&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myLibrary.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;myOtherLibrary.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- move the internal libraries to a temporary directory and make a fileset out of them --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tempfile</span> <span style="color: #000066;">property</span>=<span style="color: #ff0000;">&quot;obfuscation.dir&quot;</span> <span style="color: #000066;">destDir</span>=<span style="color: #ff0000;">&quot;${java.io.tmpdir}&quot;</span> <span style="color: #000066;">deleteonexit</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${obfuscation.dir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;move</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${obfuscation.dir}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;internal.lib.set&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/move<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- create a jar of web.xml (required by yguard) for obfuscation --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jar</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;${obfuscation.dir}/web.xml.jar&quot;</span> <span style="color: #000066;">whenempty</span>=<span style="color: #ff0000;">&quot;fail&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;zipfileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;web.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jar<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/web.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- make a fileset of all jars to be obfuscated --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${obfuscation.dir}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;*.jar&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;in-out.set&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- make a fileset of the remaining libraries, these are not obfuscated --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;external.lib.path&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;*.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/path<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;yguard&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;com.yworks.yguard.YGuardTask&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">classpath</span>=<span style="color: #ff0000;">&quot;yguard.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;yguard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inoutpairs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #808080; font-style: italic;">&lt;!-- these filesets are inputs to be obfuscated --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;in-out.set&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inoutpairs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;externalclasses</span> <span style="color: #000066;">refid</span>=<span style="color: #ff0000;">&quot;external.lib.path&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  <span style="color: #808080; font-style: italic;">&lt;!-- external libs, not obfuscated --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adjust</span> <span style="color: #000066;">replaceContent</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;web.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>  <span style="color: #808080; font-style: italic;">&lt;!-- modified to reference the obfuscated Servlet --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adjust<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;keep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #808080; font-style: italic;">&lt;!-- classes, packages, methods, and fields which should not obfuscated are specified here --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/keep<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/yguard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- move our newly obfuscated classes back into the lib area --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;move</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${obfuscation.dir}&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;*_obf.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/move<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- unjar the adjusted web.xml --&gt;</span> 
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;unzip</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib/web.xml_obf.jar&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;patternset</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;web.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/unzip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}/WEB-INF/lib&quot;</span> <span style="color: #000066;">includes</span>=<span style="color: #ff0000;">&quot;web.xml*.jar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/delete<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- rebuild the war file --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;war</span> <span style="color: #000066;">destfile</span>=<span style="color: #ff0000;">&quot;webapp_obf.war&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;${unwar.dir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p><a href="http://www.yworks.com/">yWorks</a>, the creator of yGuard, is perhaps best known for <a href="http://www.yworks.com/en/products_ydoc.html">yDoc a UML diagram generator for JavaDocs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/02/obfuscating-a-webapp-war-file-with-yguard-and-ant/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>GCViewer, garbage collection and heap analysis tool</title>
		<link>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/</link>
		<comments>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 23:46:48 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[gcviewer]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=94</guid>
		<description><![CDATA[One month ago I wrote about the benefits of using Java&#8217;s built-in garbage collection logging.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221; There is, of course, a hitch: for any non-trivial application or <a href='http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>One month ago I wrote about the benefits of using <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java&#8217;s built-in garbage collection logging</a>.  With it, you can find answers to important important questions such as &#8220;how much memory is my app using&#8221; and &#8220;how much time is being spent doing garbage collection.&#8221;</p>
<p>There is, of course, a hitch: for any non-trivial application or problem, you will be quickly buried by a mountainous log file.  The longer your application runs, the larger the log file.  It keeps growing, and growing, and&#8230;</p>
<div id="attachment_98" class="wp-caption alignright" style="width: 160px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot.png"><img class="size-thumbnail wp-image-98" title="gcviewer-screenshot" src="/mike/blog/wp-content/uploads/2009/01/gcviewer-screenshot-150x150.png" alt="GCViewer" width="150" height="150" /></a><p class="wp-caption-text">GCViewer</p></div>
<p>What will you do?  Write a second Java app, one that parses the log file &#8212; attempt a homegrown analysis tool?  No!  Instead, I suggest you use <a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a>, a free open-source tool for visualizing the <a href="http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/">Java gc log file</a>.</p>
<p><a title="GCViewer homepage" href="http://www.tagtraum.com/gcviewer.html">GCViewer</a> helps you get a quick and comprehensive look at how your application is behaving.  Things like total heap vs. heap used and full GC events become very apparent.  Useful statistics such as time spent during GC are calculated for your convenience.</p>
<p>GCViewer is created by <a href="http://www.tagtraum.com/">tagtraum industries</a> and is available under an <a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a> license.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ant on Ubuntu without GCJ</title>
		<link>http://christiansons.net/mike/blog/2009/01/ant-on-ubuntu-without-gcj/</link>
		<comments>http://christiansons.net/mike/blog/2009/01/ant-on-ubuntu-without-gcj/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 22:23:33 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[ant]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[gcj]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=76</guid>
		<description><![CDATA[You may be surprised to learn Ant requires GCJ when installed through Synaptic or apt on Ubuntu.  GCJ is GNU&#8217;s Java compiler.  When you&#8217;re using Sun&#8217;s JDK and compiler, GCJ can get in the way &#8212; at worst it creates conflicts; at best it causes confusion. Here&#8217;s how I installed Ant on Ubuntu without GCJ. <a href='http://christiansons.net/mike/blog/2009/01/ant-on-ubuntu-without-gcj/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://christiansons.net/mike/blog/wp-content/uploads/2009/01/ant_logo_large.gif"><img class="alignleft size-medium wp-image-88" title="Ant logo" src="/mike/blog/wp-content/uploads/2009/01/ant_logo_large.gif" alt="" width="190" height="120" /></a>You may be surprised to learn <a title="Ant website" href="http://ant.apache.org/">Ant</a> requires GCJ when installed through Synaptic or <tt>apt</tt> on Ubuntu.  GCJ is <a title="GCJ homepage" href="http://gcc.gnu.org/java/">GNU&#8217;s Java compiler</a>.  When you&#8217;re using Sun&#8217;s JDK and compiler, GCJ can get in the way &#8212; at worst it creates conflicts; at best it causes confusion.</p>
<p>Here&#8217;s how I installed Ant on Ubuntu without GCJ.<span id="more-76"></span>  <em>Be sure to check out (easier) alternatives suggested in the <a href="#comments">comments, below</a></em>.</p>
<ol>
<li>Download the current <tt>.tar.bz2</tt> distribution of Ant from <a title="Ant mirror" href="http://www.ibiblio.org/pub/mirrors/apache/ant/binaries/">http://www.ibiblio.org/pub/mirrors/apache/ant/binaries/</a>.</li>
<li>Unpack archive using <tt>tar</tt>.</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xjvf</span> apache-ant-<span style="color: #000000; font-weight: bold;">*</span>-bin.tar.bz2</pre></div></div>

<li>Move the unpacked directory to <tt>/usr/local/ant</tt>.</li>
<li>Change that directory&#8217;s owner to <tt>root</tt>.</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> root:root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>ant</pre></div></div>

<li>Add the following lines to <tt>/etc/bash.bashrc</tt>.</li>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ANT_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>ant
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #800000;">${PATH}</span>:<span style="color: #800000;">${ANT_HOME}</span><span style="color: #000000; font-weight: bold;">/</span>bin</pre></div></div>

</ol>
<p>From a new shell, run <tt>ant</tt>.  You should see the following:</p>
<pre>Buildfile: build.xml does not exist!
Build failed</pre>
<p>Yes, it&#8217;s a failure message.  But it means Ant is working as expected.  <img src='http://christiansons.net/mike/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2009/01/ant-on-ubuntu-without-gcj/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SeaFlow, Java app for Seattle traffic conditions</title>
		<link>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 20:41:45 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[seattle]]></category>
		<category><![CDATA[traffic]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=64</guid>
		<description><![CDATA[Late in 1999, UltiMeth Systems created SeaFlow, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of WSDOT&#8217;s web-based traffic map.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic. SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density <a href='http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_67" class="wp-caption alignleft" style="width: 310px"><a href="http://christiansons.net/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1.png"><img class="size-medium wp-image-67" title="SeaFlow screenshot" src="/mike/blog/wp-content/uploads/2008/12/seaflow-screenshot1-300x179.png" alt="SeaFlow screenshot from Dec. 18, 2008." width="300" height="179" /></a><p class="wp-caption-text">SeaFlow screenshot from Dec. 18, 2008.</p></div>
<p>Late in 1999, <a title="homepage of UltiMeth Systems" href="http://www.ultimeth.com/">UltiMeth Systems</a> created <a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a>, a Java-based application for monitoring Seattle-area traffic conditions.  SeaFlow is a powerful desktop version of <a title="WSDOT Seattle traffic" href="http://www.wsdot.wa.gov/traffic/seattle/">WSDOT&#8217;s web-based traffic map</a>.  It uses the same WSDOT data but shows greater detail, allows customization, and reduces network traffic.</p>
<p>SeaFlow displays vehicle speeds, density, and count metrics.  (WSDOT&#8217;s map shows only density which is certainly useful, but not a complete picture.)  The visual color representation of each metric can be customized in SeaFlow.</p>
<p>In times of peak demand, such as <a title="WSDOT blog post for 2008-12-18" href="http://wsdotblog.blogspot.com/2008/12/december-8-2008.html">December 18, 2008</a>, WSDOT&#8217;s website may become overwhelemed and yield partial or missing maps.  SeaFlow&#8217;s use of the smaller WSDOT data file &#8212; with maps rendered on the client-side &#8212; reduces demand on WSDOT&#8217;s site and can provide more reliable and complete updates.</p>
<p><a title="SeaFlow homepage" href="http://www.ultimeth.com/traffic/">SeaFlow</a> is a great Java desktop app &#8212; small, efficient, and cross-platform.  Its license is <a title="homepage of GNU GPL" href="http://www.gnu.org/licenses/gpl.html">GPL</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/seaflow-java-app-for-seattle-traffic-conditions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java garbage collection logging</title>
		<link>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/</link>
		<comments>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 08:00:56 +0000</pubDate>
		<dc:creator>Mike Christianson</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[garbagecollection]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.christiansons.net/?p=28</guid>
		<description><![CDATA[Java&#8217;s built-in garbage collection logging provides a quick, easy, and free way to profile or troubleshoot your Java application.  It can help you understand your application in terms of: memory usage (object count and size) heap size (initial and over time) GC metrics (frequency, pause time, and amount freed) So, now you can answer questions <a href='http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Java&#8217;s built-in garbage collection logging provides a quick, easy, and <em>free</em> way to profile or troubleshoot your Java application.  It can help you understand your application in terms of:</p>
<ul>
<li> memory usage (object count and size)</li>
<li>heap size (initial and over time)</li>
<li>GC metrics (frequency, pause time, and amount freed)</li>
</ul>
<p>So, now you can answer questions like &#8220;how much memory is my app using,&#8221; &#8220;how much time is being spent doing garbage collection,&#8221; and &#8220;how big is the heap over time.&#8221;</p>
<p style="border: thin dashed;">
<em>For help analyzing and visualizing a GC log file, be sure to check out <a href="http://christiansons.net/mike/blog/2009/01/gcviewer-garbage-collection-and-heap-analysis/">GCViewer, a garbage collection and heap analysis tool</a>.</em>
</p>
<p>GC logging is enabled using JVM arguments; below are the arguments I use.  <span id="more-28"></span>(Note: the log file specified as <em>file</em> is reset each time the VM starts.)</p>
<p><code>-verbose:gc -Xloggc:<em>file</em></code></p>
<p>Here&#8217;s an example GC log file which shows three GC events including one full GC.</p>
<pre>[GC 19062K-&gt;7172K(60800K), 0.0087190 secs]
[GC 9346K-&gt;7525K(60800K), 0.0052810 secs]
[Full GC 7525K-&gt;7477K(60800K), 0.0615190 secs]</pre>
<p>In the first event, garbage collection takes just under nine thousandths of a second to collect 11,890K memory used by objects (19,062K to 7,172K) while the heap is 60,800K.  The last event is a full GC lasting just over six hundredths of a second to free up 48K with no change in the heap.</p>
<p>Data like this can be invaluable in saving one&#8217;s sanity or ending arguments! For further details on garbage collection, see Sun&#8217;s <a title="article on GC Portal" href="http://java.sun.com/developer/technicalArticles/Programming/GCPortal/">GC Portal</a> and <a title="doc on GC tuning" href="http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html">Virtual Machine Garbage Collection Tuning</a> documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://christiansons.net/mike/blog/2008/12/java-garbage-collection-logging/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

