<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Will Reed</title>
	<atom:link href="http://willreed.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://willreed.wordpress.com</link>
	<description>Code simple</description>
	<lastBuildDate>Mon, 21 Sep 2009 15:00:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='willreed.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/cb49436279a6a03a419dcab4e912c09c?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Will Reed</title>
		<link>http://willreed.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://willreed.wordpress.com/osd.xml" title="Will Reed" />
	<atom:link rel='hub' href='http://willreed.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Make Java parse XML like Javascript parses JSON</title>
		<link>http://willreed.wordpress.com/2009/09/19/make-java-see-xml-like-javascript-sees-json/</link>
		<comments>http://willreed.wordpress.com/2009/09/19/make-java-see-xml-like-javascript-sees-json/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 15:31:27 +0000</pubDate>
		<dc:creator>willreed</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://willreed.wordpress.com/?p=27</guid>
		<description><![CDATA[Over the years, I&#8217;ve worked with many different computer languages. I&#8217;ve come to the conclusion that each is suited to a specific set of tasks and conditions. Strongly typed, rigid languages like C and Java are good for projects where performance and precision are more important than the amount of development effort. That&#8217;s a good [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=27&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the years, I&#8217;ve worked with many different computer languages. I&#8217;ve come to the conclusion that each is suited to a specific set of tasks and conditions. Strongly typed, rigid languages like C and Java are good for projects where performance and precision are more important than the amount of development effort. That&#8217;s a good fit when you are working on instrument logic for NASA or building search algorithms, but it&#8217;s just the wrong set of values when building a web application for a startup. In that case, time to deliver and reliability are more important.</p>
<p>So when I found myself needing to parse XML in Java at a startup, I was faced with two possibilities: 1) spend too much time and frustration using traditional, verbose Java techniques, or 2) do something to make Java see XML like Javascript sees JSON &#8211; i.e. as an hierarchial hash. The strongly typed nature of Java means this isn&#8217;t an obvious thing to do. And it&#8217;s not immediately obvious that it&#8217;s even possible to do.</p>
<p>So I built a simple parser, literally, that turns XML into a hierarchical hash of so-called Simple objects. With one line of code, you can request XML from an external URL and get back a fully traversable hierarchical set of hash objects, just like you would with JSON or even something like E4X. You call it like so:</p>
<pre>Simple result = new SimpleParser().parse("http://yourDomain.com/yourXmlResponse.xml");</pre>
<p>That&#8217;s it! Much better than parsing with SAX and creating a bunch of container classes to consume the xml as type specific objects. So what can you do now that you have the result? Well, given some XML like this:</p>
<pre>&lt;Team&gt;
    &lt;TeamName&gt;The Bandits&lt;/TeamName&gt;
    &lt;Players&gt;
        &lt;Player id=”0” name=”Bob”/&gt;
        &lt;Player id=”1” name=”Sam”/&gt;
    &lt;/Players&gt;
&lt;/Team&gt;</pre>
<p>You can make calls like this:</p>
<pre>Simple team = result.getFirst(“Team”); //returns Simple object for the Team element

ArrayList&lt;Simple&gt; players = team.getList(“Player”); //returns
arraylist of players

String teamName = team.getFirstText(“TeamName”);  //returns “The Bandits”

String tname = team.getName(); //returns “Team”

//returns "Bob"
String playerOneName = result.getFirst(“Team”).getFirst(“Players”).getFirst(“Player”).get(“name”);</pre>
<p>The key to this structure is something I call the Simple object. It’s just a wrapper around a couple of properties (the original element name and any text the element contained), a reference to its parent Simple object and a hash of child objects. It has a few useful methods. Use &#8220;get&#8221; to get an attribute value. Use &#8220;getList&#8221; to get a list of child elements. Use &#8220;getFirst&#8221; to get the first element of a list of child elements. And use &#8220;getFirstText&#8221; to get the text node of the first element of the child list.  The SimpleParser just builds a tree of heirarchial Simple object nodes as it parsers the XML. There is a one-to-one correspondence between the xml nodes and nodes in the Simple tree. Just look at the XML to find out how to get the data out of the tree.</p>
<p><strong>Why use this?</strong></p>
<p>Because it&#8217;s quick to implement and flexible. You can point any XML structure at this parser and get exactly the same behavior. No need to muck with SAX and container classes or even to use a schema-to-class generator like JAXB. The SimpleParser just works. It&#8217;s probably a little slower than pure SAX, but that doesn&#8217;t matter at all for most normal sized XML documents (the kind you consume over the web). At any rate, use it as you like. I built this because I couldn&#8217;t find anything like it. Maybe it will be what you are looking for too.</p>
<p><strong>Limitations</strong></p>
<p>While I think this approach goes most of the way to providing a similar experience to JSON parsing and object access, it fails in two important ways. First, it requires an additional object construct, namely the Simple object, to work. I&#8217;m not sure this limitation is really necessary. It seems possible that the hierarchical data structure could be implemented in some other way. Second, the object accessor notation is not as satisfying and is more verbose than JSON. Calling simpleObj.getFirst(&#8220;NodeName&#8221;) is not as nice as simpleObj.NodeName[0]. I&#8217;ve got a feeling this too is possible to duplicate through some tricky use of reflection, but it&#8217;s not something Java is particularly suited for. Java wants to be told what it&#8217;s getting ahead of time &#8211; which is perfectly reasonable. However, XML is really just a big tree of labels and strings, arranged hierarchically. Sometimes you need those types to be more specific. In those cases, something like SOAP is appropriate. But in most cases it&#8217;s really not necessary at all. In those cases, the simple approach is usually the best. </p>
<p><strong>The Code</strong></p>
<p><strong>SimpleTest.java</strong></p>
<pre>
public class SimpleTest {

	public static void main(String[] args) {
		System.out.println("Requesting some random XML...");
		Simple result = new SimpleParser().parse("http://feeds.guardian.co.uk/theguardian/rss");
		System.out.println(result.getFirst("rss").getFirst("channel").getFirst("title").getText()); //prints "The Guardian World News"
	}
}
</pre>
<p><strong>Simple.java</strong></p>
<pre>

import java.util.HashMap;
import java.util.LinkedHashMap;
import org.w3c.dom.*;
import java.util.ArrayList;
import java.util.Iterator;

public class Simple {
	public Simple parent = null;
	public LinkedHashMap childMap = new LinkedHashMap();
	private String text = "";
	private String name = "";

        //xml attribute strings are stored as top level keys in the child hash
	public String get(String key) {
		//System.out.println("Getting " + key + " from \n " + childMap);
		if (childMap.containsKey(key)) {
			return (String)(childMap.get(key));
		} else {
			return null;
		}
	}
        //xml child elements are stored as an arraylist, keyed by the element name
	public ArrayList getList(String key) {
		//System.out.println("Getting " + key + " from \n " + childMap);
		if (childMap.containsKey(key)) {
			return (ArrayList)(childMap.get(key));
		} else {
			return null;
		}
	}
        //gets the first child element from the arraylist of elements named by key
	public Simple getFirst(String key) {
		Object obj = childMap.get(key);
		if (obj != null) {
			if (obj instanceof ArrayList) {
				Object objFirst = ((ArrayList)obj).get(0);
				if (objFirst != null) {
					return (Simple)objFirst;
				} else {
					return null;
				}
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

        //finds the arraylist of child elements matching key, gets the first element, and returns its text content
	public String getFirstText(String key) {
		Simple obj = getFirst(key);
		if (obj != null) {
			return obj.getText();
		} else {
			return "";
		}
	}

        //write out the entire node tree as json
	public String toJson() {
		StringBuffer sb = new StringBuffer();
		Iterator it = childMap.keySet().iterator();
		sb.append("{name:'" + name + "', text:'" + text + "',");
		StringBuffer attsb = new StringBuffer();
		StringBuffer chsb = new StringBuffer();
		while(it.hasNext()) {
		    String key = String.valueOf(it.next());
			Object val = childMap.get(key);
			chsb.append("\t");
			if (val != null) {
				if (val instanceof String) {
					attsb.append(key + ": '" + val + "', ");
				} else if (val instanceof ArrayList) {
					//recursively child simple object toJson methods
					ArrayList sarr = (ArrayList) val;
					for (Simple cs : sarr) {
						chsb.append(cs.toJson());
					}
				}
			}
		}	

		sb.append(" attributes: {" + attsb.toString() + "}, ");
		sb.append("children: [" + chsb.toString() + "]");

		sb.append("\n}\n");	

		return sb.toString();
	}

        //the original xml elements tag name
	public String getName() {
		return name;
	}
	public void setName(String val) {
		name = val;
	}

        //the text content, if any, of the original xml element
	public String getText() {
		return text;
	}
	public void setText(String val) {
		text = val;
	}	

        //override default toString, print out the important info for the simple object, good for debugging
	public String toString() {
		return String.format("\nname: %s; parent: %s; text: %s; children: %s;", name, parent == null ? "null" : parent.name, text, childMap);
	}

        //similar to toString, but print out the simple object data in a useful way for web page debugging
	public String toHtmlString() {
		return String.format("name: %s text: %s attributes: %s", name, text, dumpAttributes(childMap));
	}	

        //print the hash contents to a string; used in debug output
	public static String dumpHash(HashMap map) {
		String output = "";
		for(Object s : map.keySet()) {
			output += s + ": " + map.get(s) + "; ";
		}
		return output;
	}

	public static String dumpAttributes(HashMap map) {
		String output = "";
		for(Object s : map.keySet()) {
			Object val = map.get(s);
			if (val instanceof String) {
				output += s + ": " + val + "; ";
			}
		}
		return output;
	}
}
</pre>
<p><strong>SimpleParser.java</strong></p>
<pre>
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.*;
import java.net.URL;
import org.xml.sax.*;
import java.net.URLConnection;
import java.net.MalformedURLException;

/*simple objects from xml parser
	What's a simple object? an object that contains an xml element node and a ref to its parent and child simple objects.
	This parser is in the spirit of E4X. It takes the hierarchial data of xml and re-creates that using hash tables and array lists.
	author: will
	*/
public class SimpleParser {	

	public Simple parse (String strUrl) {

		URL url = null;
		try {
			url = new URL(strUrl);
		} catch (MalformedURLException e) {
			System.out.println(e.getMessage());
			//do something
		}

		InputStream is = null;

		try {
			URLConnection conn = url.openConnection();
			is = conn.getInputStream();
			InputSource input = new InputSource(is);
			//input.setEncoding("ISO-8859-1");
			DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
			Document doc = builder.parse(input);

			Simple simple = new Simple();
			parseNode(simple, doc);	

			return simple;
		}
		catch (Exception e) {
			// log.error("error: msg: " + e.toString());
			// log.error("error: url: " + url.toString());
			// log.error("error: response: " + (is == null ? "null" : convertStreamToString(is)));
			System.out.println(e.getMessage());
			return null;
		}		

	}
	public void parseNode(Simple simple, Node node) throws Exception {
		//Node node = simple.node;
		HashMap parentMap = simple.parent != null ? simple.parent.childMap : null;		

		if(node == null) {
			return;
		}
		int type = node.getNodeType();

		switch (type) {
			// handle document nodes
			case Node.DOCUMENT_NODE: {
				Simple docBucket = new Simple();
				docBucket.parent = simple;
				docBucket.setName("_ROOT");
				parseNode(docBucket, ((Document)node).getDocumentElement());
				break;
			}
			// handle element nodes
			case Node.ELEMENT_NODE: {
				String elementName = node.getNodeName();
				simple.setName(elementName);	

				if (parentMap != null) {
					if (!parentMap.containsKey(elementName)) {
						parentMap.put(elementName, new ArrayList());
					}

					((ArrayList)parentMap.get(elementName)).add(simple);
				}

				NamedNodeMap attrs = node.getAttributes();
				for(int i = 0 ; i&lt;attrs.getLength() ; i++) {
					Attr att = (Attr)attrs.item(i);
					simple.childMap.put(att.getName(), att.getValue());
				}				

				NodeList childNodes = node.getChildNodes();
				if(childNodes != null) {
					int length = childNodes.getLength();
					for (int loopIndex = 0; loopIndex &lt; length ; loopIndex++) {
						Simple childBucket = new Simple();
						Node cnode = childNodes.item(loopIndex);
						childBucket.setName(cnode.getNodeName());
						childBucket.parent = simple;
						parseNode (childBucket, cnode);
					}
				}
				break;
			}
			// handle text nodes
			case Node.TEXT_NODE: {
				String data = node.getNodeValue().trim();

				if((data.indexOf(&quot;\n&quot;)  0)) {
					simple.parent.setText(simple.parent.getText() + data);
				}
			}
		}
	}

	public static String convertStreamToString(InputStream is) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return sb.toString();
	}
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/willreed.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/willreed.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/willreed.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=27&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://willreed.wordpress.com/2009/09/19/make-java-see-xml-like-javascript-sees-json/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8eaea2f1e553efa50457d8b17570ed7b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">willreed</media:title>
		</media:content>
	</item>
		<item>
		<title>Code as Art</title>
		<link>http://willreed.wordpress.com/2009/06/29/code-as-art/</link>
		<comments>http://willreed.wordpress.com/2009/06/29/code-as-art/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 14:24:41 +0000</pubDate>
		<dc:creator>willreed</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://willreed.wordpress.com/?p=17</guid>
		<description><![CDATA[It seems that every medium follows a chronological path from the practical, to the theoretical, to the aesthetic. Consider sculpture. It could be argued that Venus de Milo has its origins in the earliest Oldowan flake tools. Stone, as a medium, first serves a purely practical purpose: it chops, hacks and smashes. Particular stones take [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=17&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It seems that every medium follows a chronological path from the practical, to the theoretical, to the aesthetic. Consider sculpture. It could be argued that Venus de Milo has its origins in the earliest Oldowan flake tools. Stone, as a medium, first serves a purely practical purpose: it chops, hacks and smashes. Particular stones take on a function because they closely resemble what is needed for that function. By flaking off a few layers, the mere stone becomes a tool. But over time, the medium is seen in the abstract, as medium. It becomes a substance, in itself, that is independent of any one implementation. At this theoretical stage, clever individuals invent new uses for the medium that become increasingly imaginative. This movement culminates in the aesthetic stage, where the medium is finally seen over and above any practical use. It is used to express an idea or feeling that is made more comprehensible by being created through the medium. Hence, Venus de Milo.</p>
<p>I would argue that programming &#8211; what I would call intentional logic &#8211; is somewhere in the late theoretical stage. All programs aim to do something, they reach out toward some goal. That is why programming is intentional and also why it is particularly hard for code, as a medium, to reach the aesthetic stage. Certainly code can be seen as more or less elegant, and the product it creates can be more or less beautiful and usable, but programmers are still, by and large, mere artisans.</p>
<p>It is difficult to say what the aesthetic stage of code would look like. It&#8217;s hard to imagine a block of code in a museum or hung above a mantle. But this assumes that programs will always be expressed in the terse, symbolic form that they are now. I would argue that we are at a very early stage of code as a medium. The trend in the development of programming languages is toward higher levels of abstraction. Perhaps one day it will be possible to express a program with a chisel or paintbrush. Perhaps even the Venus de Milo &#8211; when scanned with some future, aesthetic interpreter &#8211; will become a meaningful program.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/willreed.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/willreed.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/willreed.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=17&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://willreed.wordpress.com/2009/06/29/code-as-art/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8eaea2f1e553efa50457d8b17570ed7b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">willreed</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby + Merb on Google App Engine</title>
		<link>http://willreed.wordpress.com/2009/05/04/ruby-merb-on-google-app-engine/</link>
		<comments>http://willreed.wordpress.com/2009/05/04/ruby-merb-on-google-app-engine/#comments</comments>
		<pubDate>Mon, 04 May 2009 13:31:45 +0000</pubDate>
		<dc:creator>willreed</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://willreed.wordpress.com/?p=12</guid>
		<description><![CDATA[Google recently added limited support for Java on app engine. Like many other ruby on rails developers, I immediately thought of using Jruby to run a ruby app on the app engine jvm. The upshot is, it works &#8211; at a price. The major downside is that you lose Active Record. Google, of course, has [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=12&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Google recently added limited support for Java on app engine. Like many other ruby on rails developers, I immediately thought of using Jruby to run a ruby app on the app engine jvm. The upshot is, it works &#8211; at a price.</p>
<p>The major downside is that you lose Active Record. Google, of course, has its own BigTable data layer implementation. I think a rails-like wrapper is inevitable &#8211; Ola Bini is already working on one (<a href="http://olabini.com/blog/2009/04/jruby-on-rails-on-google-app-engine/">Bumble</a>) &#8211; but that won&#8217;t help much for now. BigTable is basically just a massively distributed object hash, so the API mostly revolves around creating and modifying data objects. Not pretty, fairly inelegant, but it works.</p>
<p>I won&#8217;t go through the precise steps to set this up, because that&#8217;s already been done <a href="http://code.google.com/p/appengine-jruby/wiki/GettingStarted">here</a>. Those steps worked perfectly for me, with one caveat. Make sure you set the following props to false in config/init.rb:<br />
<code> c[:reload_classes]      = false,<br />
c[:reload_templates]    = false,</code><br />
Those can be set to true in dev for testing, but you&#8217;ll get an unhelpful permissions exception when you deploy to app engine if you don&#8217;t first set them to false.</p>
<p>Why Merb? Mostly because that&#8217;s what the setup directions used, but also because you can&#8217;t use ActiveRecord anyway. I also <a href="http://splendificent.com/2008/12/the-merb-rails-merger-announcement-an-inside-opinion/">read</a> that Merb is basically getting taken over/taking over Rails anyhow.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/willreed.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/willreed.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/willreed.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=12&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://willreed.wordpress.com/2009/05/04/ruby-merb-on-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8eaea2f1e553efa50457d8b17570ed7b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">willreed</media:title>
		</media:content>
	</item>
		<item>
		<title>How to debug a tomcat webapp from the command line</title>
		<link>http://willreed.wordpress.com/2009/04/30/how-to-debug-a-tomcat-webapp-from-the-command-line/</link>
		<comments>http://willreed.wordpress.com/2009/04/30/how-to-debug-a-tomcat-webapp-from-the-command-line/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 15:42:30 +0000</pubDate>
		<dc:creator>willreed</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[jdb tomcat debug]]></category>

		<guid isPermaLink="false">http://willreed.wordpress.com/?p=3</guid>
		<description><![CDATA[I like things simple and reliable. The debugging interfaces in most IDE&#8217;s are full of features and sometimes useful. But they are also often slow to attach and crash in the middle of a debug session. Often you just need to inspect a single object or get a quick view of the local variables. At any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=3&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I like things simple and reliable. The debugging interfaces in most IDE&#8217;s are full of features and sometimes useful. But they are also often slow to attach and crash in the middle of a debug session. Often you just need to inspect a single object or get a quick view of the local variables. At any rate, here is how I do it.</p>
<p>1. Start <strong>tomcat</strong> in debug mode<br />
<code>./catalina.sh jpda run</code><br />
This will start tomcat in debug mode and send the log output to the console.</p>
<p>2. Start <strong>jpd</strong><br />
jpd is the command line debugger for java. It&#8217;s very basic, but it does most things you need. Start it like this:<br />
<code>jdb -attach 8000 -sourcepath "[path-to-your-tomcat-webapp]"</code></p>
<p>That&#8217;s it for getting started. jpd will attach to your tomcat process and wait for you to give it some instructions.</p>
<p>Here are a few examples:</p>
<p>1. Set a break point<br />
<code>stop at com.yourdomain.YourClass:45</code><br />
This will set a break point at line 45 in YourClass. Go load a page in your browser that hits that code. Once the break point is hit you can do stuff like:<br />
2. Get the value of a variable<br />
<code>print someVar</code><br />
3. Look at local variables<br />
<code>locals</code></p>
<p>For a full list of commands, check out <a href="http://www.javastudy.co.kr/docs/gu/docs/jdb.html">this</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/willreed.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/willreed.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/willreed.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=willreed.wordpress.com&amp;blog=7262553&amp;post=3&amp;subd=willreed&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://willreed.wordpress.com/2009/04/30/how-to-debug-a-tomcat-webapp-from-the-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/8eaea2f1e553efa50457d8b17570ed7b?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">willreed</media:title>
		</media:content>
	</item>
	</channel>
</rss>
