<?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>The World Of Gavin &#187; java</title>
	<atom:link href="http://www.gavinwillingham.com/tag/java/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gavinwillingham.com</link>
	<description>My opinions on things I have opinions on</description>
	<lastBuildDate>Fri, 28 Jan 2011 17:08:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Classloading in Rome</title>
		<link>http://www.gavinwillingham.com/classloading-in-rome.html</link>
		<comments>http://www.gavinwillingham.com/classloading-in-rome.html#comments</comments>
		<pubDate>Wed, 18 Nov 2009 15:58:25 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[classloader]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[rome]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=440</guid>
		<description><![CDATA[As a side-project at work, I&#8217;ve been working on an ant task to generate an atom feed of something. The something&#8217;s not really important. Rather than re-invent the wheel, I did a quick search on google for a Java library to take care of the feed processing for me. Sure enough, Rome seemed to fit [...]]]></description>
			<content:encoded><![CDATA[<p>As a side-project at work, I&#8217;ve been working on an <a title="Apache Ant" href="http://ant.apache.org">ant</a> task to generate an atom feed of something. The something&#8217;s not really important.</p>
<p>Rather than re-invent the wheel, I did a quick search on google for a Java library to take care of the feed processing for me. Sure enough, <a title="Rome" href="http://wiki.java.net/bin/view/Javawsxml/Rome">Rome</a> seemed to fit the bill.</p>
<p>Merrily testing away in my Eclipse workbench, I quickly wrote the code to generate my atom feed. All was good with the world. The planets may or may not have aligned. And then I came to run it through ant.</p>
<p>Unfortunately, that&#8217;s where the problems started&#8230;</p>
<p><span id="more-440"></span></p>
<pre>BUILD FAILED
C:\testAnt.xml:6: java.lang.ExceptionInInitializerError
 at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
 at org.apache.tools.ant.Task.perform(Task.java:348)
...
Caused by: java.lang.ExceptionInInitializerError
 at java.lang.J9VMInternals.initialize(J9VMInternals.java:222)
 at com.sun.syndication.io.SyndFeedInput.build(SyndFeedInput.java:110)
...
Caused by: java.lang.NullPointerException
 at java.util.Properties.load(Properties.java:267)
 at com.sun.syndication.io.impl.PropertiesLoader.&lt;init&gt;(PropertiesLoader.java:74)
 at com.sun.syndication.io.impl.PropertiesLoader.getPropertiesLoader(PropertiesLoader.java:46)
 at com.sun.syndication.io.impl.PluginManager.&lt;init&gt;(PluginManager.java:54)
 at com.sun.syndication.io.impl.PluginManager.&lt;init&gt;(PluginManager.java:46)
 at com.sun.syndication.feed.synd.impl.Converters.&lt;init&gt;(Converters.java:40)
 at com.sun.syndication.feed.synd.SyndFeedImpl.&lt;clinit&gt;(SyndFeedImpl.java:59)</pre>
<p>Bugger.</p>
<p>A quick google only turns up 2 useful hits: <a title="Spring forum" href="http://forum.springsource.org/showthread.php?t=74020">here</a> and <a title="MarkMail" href="markmail.org/message/dh2u7cibw7dbh5hy">here</a>. Both links seem to suggest that Rome can run into problems with the way it loads its classes. After much hacking around, I found that a (somewhat hacky) way to solve this was by over-riding the Thread&#8217;s ClassLoader in my main class; e.g.</p>
<pre>public class Test extends Task{

    public void execute(){

        ClassLoader cl = Test.class.getClassLoader();
        Thread.currentThread().setClassLoader(cl);

        // now do Rome stuff
        ...
    }
}</pre>
<p>It&#8217;s not pretty, but it works. For now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/classloading-in-rome.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging across Eclipse workbenches</title>
		<link>http://www.gavinwillingham.com/debugging-was-in-eclipse-with-multiple-workbenches.html</link>
		<comments>http://www.gavinwillingham.com/debugging-was-in-eclipse-with-multiple-workbenches.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 16:45:20 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[WAS]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=350</guid>
		<description><![CDATA[One annoying part of developing Eclipse plugins which generate deployable JEE applications is that the server you use for deployment is often set up and started through the runtime workbench. This means that to test your code, you need to configure the code lookup in your runtime workbench &#8211; a pain if you have multiple [...]]]></description>
			<content:encoded><![CDATA[<p>One annoying part of developing Eclipse plugins which generate deployable JEE applications is that the server you use for deployment is often set up and started through the runtime workbench.</p>
<p>This means that to test your code, you need to configure the code lookup in your runtime workbench &#8211; a pain if you have multiple runtime workbenches, or frequently clear your runtime workbench metadata.</p>
<p>An alternative approach, which I use, is to disconnect the debugger from the runtime workbench and connect it in your base workbench. This post details how.</p>
<p><span id="more-350"></span>The first step is to find out what port your server&#8217;s debug process is listening on. The default for WebSphere Application Server is 7777, but this might change if you&#8217;ve either customised it or configured multiple server instances. An easy way to check is to select the &#8220;debug&#8221; view in your Eclipse runtime workbench.</p>
<p style="text-align: center;">
<div id="attachment_354" class="wp-caption aligncenter" style="width: 472px"><a href="http://www.gavinwillingham.com/wp-content/uploads/2009/11/runtime_debug.jpg"><img class="size-full wp-image-354 " title="runtime_debug" src="http://www.gavinwillingham.com/wp-content/uploads/2009/11/runtime_debug.jpg" alt="Debug View" width="462" height="285" /></a><p class="wp-caption-text">Debug View</p></div>
<p>In this picture, you can see that my WAS instance is running on port 7778. Make a note of this number, then select (in this view) the server (either of the top 2 lines), and click the disconnect icon (the red &#8216;N&#8217; with 2 blobs icon). This disconnects the runtime workbench&#8217;s debugger from the server, freeing up the server&#8217;s debug port for another application i.e. your base workbench.</p>
<p style="text-align: center;">
<div id="attachment_356" class="wp-caption aligncenter" style="width: 232px"><a href="http://www.gavinwillingham.com/wp-content/uploads/2009/11/new_runtime_configuration.jpg"><img class="size-full wp-image-356 " title="new_runtime_configuration" src="http://www.gavinwillingham.com/wp-content/uploads/2009/11/new_runtime_configuration.jpg" alt="New config" width="222" height="245" /></a><p class="wp-caption-text">New config</p></div>
<p>Next, we need to create a runtime configuration in the base workbench to connect to the server. Open the debug configurations dialog (Run-&gt;Debug Configurations), and select &#8220;Remote Java Application&#8221;, then click the new button. All you really need to change from the default settings are the name (if you want to be able to remember it) and the port (to the port you wrote down earlier). Here&#8217;s mine:</p>
<div id="attachment_358" class="wp-caption aligncenter" style="width: 236px"><a href="http://www.gavinwillingham.com/wp-content/uploads/2009/11/runtime_config_settings.jpg"><img class="size-full wp-image-358" title="runtime_config_settings" src="http://www.gavinwillingham.com/wp-content/uploads/2009/11/runtime_config_settings.jpg" alt="Settings" width="226" height="260" /></a><p class="wp-caption-text">Settings</p></div>
<p>Finally, hit debug and away you go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/debugging-was-in-eclipse-with-multiple-workbenches.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ant</title>
		<link>http://www.gavinwillingham.com/ant.html</link>
		<comments>http://www.gavinwillingham.com/ant.html#comments</comments>
		<pubDate>Tue, 29 Sep 2009 12:43:11 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[Content]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=189</guid>
		<description><![CDATA[Calling another ant file To invoke a target in a separate ant file, you would use this code in one of your main file&#8217;s targets (etc): &#60;ant antfile="secondFile.xml" target="targetInSecondFile" /&#62;]]></description>
			<content:encoded><![CDATA[<h2>Calling another ant file</h2>
<p>To invoke a target in a separate ant file, you would use this code in one of your main file&#8217;s targets (etc):<br />
<code> </code></p>
<pre>&lt;ant antfile="secondFile.xml" target="targetInSecondFile" /&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/ant.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SWT</title>
		<link>http://www.gavinwillingham.com/swt.html</link>
		<comments>http://www.gavinwillingham.com/swt.html#comments</comments>
		<pubDate>Sat, 26 Sep 2009 15:43:00 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[Content]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[swt]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=154</guid>
		<description><![CDATA[Checkboxes To create a checkbox in SWT, you actually create a Button: Button checkbox = new Button(parentComponent, SWT.CHECK); To get the value (checked or not), the boolean method: checkbox.getSelection();]]></description>
			<content:encoded><![CDATA[<h2>Checkboxes</h2>
<p>To create a checkbox in SWT, you actually create a Button:</p>
<pre>Button checkbox = new Button(parentComponent, SWT.CHECK);</pre>
<p>To get the value (checked or not), the <code>boolean</code> method:</p>
<pre>checkbox.getSelection();</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/swt.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java</title>
		<link>http://www.gavinwillingham.com/java.html</link>
		<comments>http://www.gavinwillingham.com/java.html#comments</comments>
		<pubDate>Wed, 23 Sep 2009 15:53:28 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[Content]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=144</guid>
		<description><![CDATA[Tips and tricks Using utility class to check for empty or null String in Java Problems solved NullPointerException during class loading in Rome]]></description>
			<content:encoded><![CDATA[<h2>Tips and tricks</h2>
<ul>
<li>Using utility class to check for <a title="Empty or null String in Java" href="empty-or-null-string-in-java.html">empty or null String</a> in Java</li>
</ul>
<h2>Problems solved</h2>
<ul>
<li>NullPointerException during <a title="Class loading in Rome" href="classloading-in-rome.html">class loading in Rome</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Empty or null String in Java</title>
		<link>http://www.gavinwillingham.com/empty-or-null-string-in-java.html</link>
		<comments>http://www.gavinwillingham.com/empty-or-null-string-in-java.html#comments</comments>
		<pubDate>Wed, 23 Sep 2009 15:45:54 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache commons]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=139</guid>
		<description><![CDATA[It’s such a common bit of code that crops up everywhere. That familiar line: if(var != null &#38;&#38; var.length() &#62; 0) There are slight variations. Some use if(var != null &#38;&#38; !var.equals("")) They’re all there to achieve the same purpose: check whether a String is null or empty. I&#8217;ve always thought &#8220;there really should be [...]]]></description>
			<content:encoded><![CDATA[<p>It’s such a common bit of code that crops up everywhere. That familiar line:</p>
<p><code> </code></p>
<pre>if(var != null &amp;&amp; var.length() &gt; 0)</pre>
<p>There are slight variations. Some use</p>
<p><code> </code></p>
<pre>if(var != null &amp;&amp; !var.equals(""))</pre>
<p>They’re all there to achieve the same purpose: check whether a String is null or empty.</p>
<p>I&#8217;ve always thought &#8220;there really should be a utility for this&#8221;, but written the code anyway. Today, when faced with repeating this pattern about 10 times, I finally decided to go and check the <a title="Apache Commons Lang javadoc" href="http://commons.apache.org/lang/api/index.html">Apache Commons Lang javadoc</a> and see if there was such a method. Unsurprisingly, there is, in <a title="StringUtils javadoc" href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringUtils.html">StringUtils</a>.</p>
<p>There&#8217;s actually a few:</p>
<ul>
<li>
<pre>isBlank(String)</pre>
</li>
<li>
<pre>isEmpty(String)</pre>
</li>
</ul>
<ul>
<li>
<pre>isNotBlank(String)</pre>
</li>
<li>
<pre>isNotEmpty(String)</pre>
</li>
</ul>
<p>Very handy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/empty-or-null-string-in-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DB2 and JDBC</title>
		<link>http://www.gavinwillingham.com/db2-and-jdbc.html</link>
		<comments>http://www.gavinwillingham.com/db2-and-jdbc.html#comments</comments>
		<pubDate>Sun, 20 Sep 2009 12:07:49 +0000</pubDate>
		<dc:creator>gavin</dc:creator>
				<category><![CDATA[Content]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdbc]]></category>

		<guid isPermaLink="false">http://www.gavinwillingham.com/?p=79</guid>
		<description><![CDATA[You need to include db2jcc.jar db2jcc_license_cu.jar on the classpath of the application. These can be found in the java/ sub-directory of the db2 install directory (Program Files/IBM/SQLLIB for me on Windows). Connecting The connection server string depends on whether you are using type2 or type4. Type 1: JDBC-ODBC Bridge Type 2: Native-API/partly Java driver Type [...]]]></description>
			<content:encoded><![CDATA[<p>You need to include</p>
<ul>
<li>db2jcc.jar</li>
<li>db2jcc_license_cu.jar</li>
</ul>
<p>on the classpath of the application. These can be found in the <code>java/</code> sub-directory of the db2 install directory (<code>Program Files/IBM/SQLLIB</code> for me on Windows).</p>
<h2>Connecting</h2>
<p>The connection server string depends on whether you are using type2 or type4.</p>
<blockquote>
<ul>
<li>Type 1: JDBC-ODBC Bridge</li>
<li>Type 2: Native-API/partly Java driver</li>
<li>Type 3: Net-protocol/all-Java driver</li>
<li>Type 4: Native-protocol/all-Java driver</li>
</ul>
<p><span class="citation">Source: http://www.javaworld.com/javaworld/jw-07-2000/jw-0707-jdbc.html</span></p></blockquote>
<h3>Type2:</h3>
<p><code>jdbc:db2:database</code></p>
<h3>Type4:</h3>
<p><code>jdbc:db2//server[:port]/database</code></p>
<h3>Sample code</h3>
<p>Opens a connection, executes a query and then closes the connection.<br />
<code></p>
<pre>
/* Load the driver */
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();

/* open the connection */
Connection conn = DriverManager.getConnection(url, user, password);

Statement st = conn.createStatement();

/* Execute a simple query to test the connection */
ResultSet rs = st.executeQuery("SELECT COUNT(*) FROM myTable");
rs.next();

/* Print the query results */
System.out.println(rs.getInt(1));

/* don't forget to close the connection */
conn.close();</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gavinwillingham.com/db2-and-jdbc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

