<?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>Pyr0g</title>
	<atom:link href="http://pier0w.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pier0w.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 14 Nov 2011 22:20:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pier0w.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Pyr0g</title>
		<link>http://pier0w.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pier0w.wordpress.com/osd.xml" title="Pyr0g" />
	<atom:link rel='hub' href='http://pier0w.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Gentoo XBMC Post-Setup</title>
		<link>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-post-setup/</link>
		<comments>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-post-setup/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 20:35:18 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=393</guid>
		<description><![CDATA[The very last thing to do is get XBMC to start up automatically on boot. To do this we will make it so that the xbmc user starts XBMC automatically when ever they login locally to the laptop. So first get the xbmc user to start X11 on a local login by adding the following [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=393&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The very last thing to do is get XBMC to start up automatically on boot.</p>
<p>To do this we will make it so that the xbmc user starts XBMC automatically when ever they login locally to the laptop.</p>
<p>So first get the xbmc user to start X11 on a local login by adding the following to the end of the users <code>.bashrc</code> file.</p>
<p><code>...</code><br />
<code>#&nbsp;Put&nbsp;your&nbsp;fun&nbsp;stuff&nbsp;here.</code><br />
<code>LOGIN_TYPE=`tty&nbsp;|&nbsp;awk&nbsp;'{if(match($0,&nbsp;/pts/)){print&nbsp;"SSH"}else{print&nbsp;"LOCAL"}}'`</code><br />
<code></code><br />
<code>if&nbsp;[&nbsp;$LOGIN_TYPE&nbsp;==&nbsp;"LOCAL"&nbsp;]</code><br />
<code>then</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exec&nbsp;startx</code><br />
<code>fi</code><br />
<code></code><br />
<code>unset&nbsp;LOGIN_TYPE</code></p>
<p>This little bit of script will only start X11 if the user logs in locally.</p>
<p>Next create a file called <code>.xinitrc</code> in the root of the user home directory, anything within this file will be executed by X11 right after it starts up. So this is where we will place the start up of XBMC.</p>
<p><code>.xinitrc:</code><br />
<code>#!/bin/bash</code></p>
<p><code>exec&nbsp;/usr/bin/xbmc</code></p>
<p>Now this should work fine if you chose to configure X11 to either ignore or turn off the laptop monitor, but if you did neither of those then you tell XBMC to start up twice. This is because on the first start up it will get the resolution conpletely wrong, but once you close it down then start it again the resolution will be right.</p>
<p><code>.xinitrc:</code><br />
<code>#!/bin/bash</code></p>
<p><code>xbmc</code><br />
<code>xbmc</code></p>
<p>Now get Gentoo to login to the xbmc use on boot, this can be done within the /etc/conf.d/local.start file which is a file that will always be executed at the end of Gentoo&#8217;s boot process.</p>
<p><code>/etc/conf.d/local.start:</code><br />
<code>#&nbsp;/etc/conf.d/local.start</code></p>
<p><code>#&nbsp;This&nbsp;is&nbsp;a&nbsp;good&nbsp;place&nbsp;to&nbsp;load&nbsp;any&nbsp;misc&nbsp;programs</code><br />
<code>#&nbsp;on&nbsp;startup&nbsp;(use&nbsp;&amp;&gt;/dev/null&nbsp;to&nbsp;hide&nbsp;output)</code></p>
<p><code>su&nbsp;-&nbsp;xbmc</code></p>
<p>So with that all done XBMC is all setup and ready to use.</p>
<p>Link for getting <a href="http://forums.gentoo.org/viewtopic-t-864327-start-0.html">shutdown</a> to work.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/393/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/393/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/393/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=393&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-post-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Gentoo XBMC Installation</title>
		<link>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-installation/</link>
		<comments>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-installation/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 18:24:49 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[XBMC]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=385</guid>
		<description><![CDATA[With the Gentoo Installation and Gentoo XBMC Pre-Setup complete it should just be able to be emerged with our any hassle. #&#62;&#160;emerge&#160;-av&#160;xbmc When that completes XBMC should be able to be started by simply running the command xbmc from an xterm within an X environment. #&#62;&#160;startx Now from inside one of the xterms. #&#62;&#160;xbmc XBMC [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=385&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the Gentoo Installation and Gentoo XBMC Pre-Setup complete it should just be able to be emerged with our any hassle.</p>
<p><code>#&gt;&nbsp;emerge&nbsp;-av&nbsp;xbmc</code></p>
<p>When that completes XBMC should be able to be started by simply running the command <code>xbmc</code> from an <code>xterm</code> within an <code>X</code> environment.</p>
<p><code>#&gt;&nbsp;startx</code></p>
<p><em>Now from inside one of the xterms.</em><br />
<code>#&gt;&nbsp;xbmc</code></p>
<p>XBMC should now be running.</p>
<p>To get XBMC to display on the TV we need to do<a href="http://www.gentoo.org/doc/en/dri-howto.xml"> create a couple X11 configuration</a> files within the <code>/usr/share/X11/xorg.conf.d/</code>.</p>
<p>The first configuration file will tell X11 to always use the <a href="http://intellinuxgraphics.org/dualhead.html">intel driver</a> and also provide labels for the TV and laptop monitor.</p>
<p><code>/usr/share/X11/xorg.conf.d/11-intel.conf:</code><br />
<code>Section&nbsp;"Device"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"Intel&nbsp;Graphics&nbsp;Card"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Driver&nbsp;"intel"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"Monitor-LVDS1"&nbsp;"LCD&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"Monitor-VGA1"&nbsp;"VGA&nbsp;screen"</code><br />
<code>EndSection</code><br />
<code>Section&nbsp;"dri"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Mode&nbsp;0666</code><br />
<code>EndSection</code></p>
<p>The files name starts with 11 so that it will be executed after the original config file which starts with 10. Any additional config files can have their execution order set in this way.</p>
<p>The <code>"Device"</code> section is where the driver and monitor labels are set, the first name in the <code>Option</code> lines is the actual name that X11 gives the physical devices. X11 gives all video outputs a name that starts with &#8220;<code>Monitor-</code>&#8221; it then appends that device name on to that, to find the device name of a monitor you can use the <a href="http://www.thinkwiki.org/wiki/Xorg_RandR_1.2"><code>xrandr -q</code></a> command.</p>
<p><code>Screen&nbsp;0:&nbsp;minimum&nbsp;320&nbsp;x&nbsp;200,&nbsp;current&nbsp;3200&nbsp;x&nbsp;1080,&nbsp;maximum&nbsp;4096&nbsp;x&nbsp;4096</code><br />
<code>LVDS1&nbsp;connected&nbsp;1280x800+1920+0&nbsp;(normal&nbsp;left&nbsp;inverted&nbsp;right&nbsp;x&nbsp;axis&nbsp;y&nbsp;axis)&nbsp;331mm&nbsp;x&nbsp;207mm</code><br />
<code>&nbsp;&nbsp;&nbsp;1280x800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;61.0*+</code><br />
<code>&nbsp;&nbsp;&nbsp;1024x768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;800x600&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;56.2&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;640x480&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;59.9&nbsp;&nbsp;</code><br />
<code>VGA1&nbsp;connected&nbsp;1920x1080+0+0&nbsp;(normal&nbsp;left&nbsp;inverted&nbsp;right&nbsp;x&nbsp;axis&nbsp;y&nbsp;axis)&nbsp;886mm&nbsp;x&nbsp;498mm</code><br />
<code>&nbsp;&nbsp;&nbsp;1920x1080&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;+</code><br />
<code>&nbsp;&nbsp;&nbsp;1600x1200&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1680x1050&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1280x1024&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1440x900&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;59.9&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1280x960&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1360x768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1280x800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;59.8*&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1152x864&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;1024x768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;70.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;832x624&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;74.6&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;800x600&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;72.2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.3&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;640x480&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;72.8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;75.0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;66.7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;60.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;720x400&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;70.1&nbsp;&nbsp;</code><br />
<code>TV1&nbsp;unknown&nbsp;connection&nbsp;(normal&nbsp;left&nbsp;inverted&nbsp;right&nbsp;x&nbsp;axis&nbsp;y&nbsp;axis)</code><br />
<code>&nbsp;&nbsp;&nbsp;848x480&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30.0&nbsp;+</code><br />
<code>&nbsp;&nbsp;&nbsp;640x480&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30.0&nbsp;+</code><br />
<code>&nbsp;&nbsp;&nbsp;1024x768&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30.0&nbsp;&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;800x600&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30.0</code></p>
<p>From the output of this you can see that the laptop screen is called <code>LVD1</code> and the vga plug is called <code>VGA1</code> so the X11 names will be <code>Monitor-LVD1</code> and <code>Monitor-VGA1</code> respectively.</p>
<p>The <code>"dri"</code> turns on the hardware acceleration.</p>
<p>Now that the monitors have been labelled we need to tell X11 what configuration they are in, this I have done in another config file.</p>
<p><code>/usr/share/X11/xorg.conf.d/12-dual-screen.conf:</code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"LCD&nbsp;screen"</code><br />
<code>EndSection</code><br />
<code></code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"VGA&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"LeftOf"&nbsp;"LCD&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"PreferredMode"&nbsp;"1920x1080"</code><br />
<code>EndSection</code></p>
<p>This tells X11 that there are two monitors associated to the two output devices, it also tells X11 that the <code>"VGA screen"</code> (the TV) should be set to the resolution 1920&#215;1080 and that it is to the left of the <code>"LCD screen"</code>.</p>
<p>Now this should work fine with XBMC&#8230; and it sort of does. If you start up the X11 server then start up XBMC inside of it you will see that the resolution will be set to the 1280&#215;800, the laptops resolution, but if you then close XBMC but NOT the X11 server then start XBMC again it will be at the right resolution. I have no idea why this is but there you go. Because of this I have created a hack in the next section.</p>
<p>But, if you want to have XBMC start in the correct resolution in a more correct way there are two things you can do.</p>
<p>The first is tell X11 to turn off the laptop monitor, this is good because it saves power and won&#8217;t burn out the monitor, but it means when X11 shuts down the monitor won&#8217;t turn back on so you are stuck with having to use the TV as the only monitor. In reality this isn&#8217;t that bad because you&#8217;ll surely be using ssh to do anything with the command line on the laptop any way. So to turn of the laptop monitor use this configuration.</p>
<p><code>/usr/share/X11/xorg.conf.d/12-dual-screen.conf:</code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"LCD&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"Disable"&nbsp;"True"</code><br />
<code>EndSection</code><br />
<code></code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"VGA&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"PreferredMode"&nbsp;"1920x1080"</code><br />
<code>EndSection</code></p>
<p>Though, if for some reason you want the laptop monitor to stay on but still want XBMC to start correctly you can set X11 to ignore the laptop monitor. This is good because it stays on, but bad because it ALWAYS stays on even with the lid close so may burn out the monitor.</p>
<p><code>/usr/share/X11/xorg.conf.d/12-dual-screen.conf:</code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"LCD&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"Ignore"&nbsp;"True"</code><br />
<code>EndSection</code><br />
<code></code><br />
<code>Section&nbsp;"Monitor"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Identifier&nbsp;"VGA&nbsp;screen"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;"PreferredMode"&nbsp;"1920x1080"</code><br />
<code>EndSection</code></p>
<p>So now that X11 is configured XBMC should start up and run perfectly on your TV.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/385/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=385&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Gentoo XBMC Pre-Setup</title>
		<link>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-pre-setup/</link>
		<comments>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-pre-setup/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 18:18:55 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[XBMC]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=382</guid>
		<description><![CDATA[There is some extra configuration that is required before XBMC can be installed. This is mostly to do with unmasking some packages and setting up some USE flags. So first create the /etc/portage/ directory, this is where the unmask, keyword, and use files will go. Next create the following files: /etc/portage/package.use: media-video/mplayer&#160;fbcon x11-base/xorg-server&#160;udev x11-base/xorg-x11&#160;udev&#160;opengl sys-fs/udev&#160;extras [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=382&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There is some extra configuration that is required before XBMC can be installed. This is mostly to do with unmasking some packages and setting up some USE flags.</p>
<p>So first create the <code>/etc/portage/</code> directory, this is where the unmask, keyword, and use files will go.</p>
<p>Next create the following files:</p>
<p><code>/etc/portage/package.use:</code><br />
<code>media-video/mplayer&nbsp;fbcon</code><br />
<code>x11-base/xorg-server&nbsp;udev</code><br />
<code>x11-base/xorg-x11&nbsp;udev&nbsp;opengl</code><br />
<code>sys-fs/udev&nbsp;extras</code><br />
<code>sys-auth/pambase&nbsp;consolekit</code><br />
<code>x11-libs/cairo&nbsp;X</code><br />
<code>dev-libs/libgcrypt&nbsp;static-libs</code><br />
<code>dev-libs/libgpg-error&nbsp;static-libs</code><br />
<code>media-libs/libsdl&nbsp;X&nbsp;opengl</code><br />
<code>sys-auth/consolekit&nbsp;policykit</code><br />
<code>sys-block/parted&nbsp;device-mapper</code><br />
<code>media-tv/xbmc&nbsp;webserver</code></p>
<p><code>/etc/portage/package.keywords:</code><br />
<code>dev-util/debhelper&nbsp;~*</code><br />
<code>app-misc/cwiid&nbsp;~*</code><br />
<code>net-libs/libmicrohttpd&nbsp;~*</code><br />
<code>media-tv/xbmc&nbsp;~*</code></p>
<p><code>/etc/portage/package.unmask:</code><br />
<code>app-misc/cwiid</code><br />
<code>net-libs/libmicrohttpd</code><br />
<code>media-tv/xbmc</code></p>
<p>With that done XBMC should now be able to be emerged.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/382/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/382/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/382/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=382&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/04/18/gentoo-xbmc-pre-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Gentoo Installation (Inspiron 6400)</title>
		<link>http://pier0w.wordpress.com/2011/04/17/gentoo-installation-inspiron-6400/</link>
		<comments>http://pier0w.wordpress.com/2011/04/17/gentoo-installation-inspiron-6400/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 13:36:45 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Gentoo]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=322</guid>
		<description><![CDATA[Here is a run down of the Gentoo installation I did on an Inspiron 6400. I will walk through the configuration I used in the different stages of the Gentoo Handbook installation. I chose to install the x86 version of Gentoo because it has better compatibility with closed sources applications like Java and Flash. I&#8217;m [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=322&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a run down of the Gentoo installation I did on an <a href="http://support.dell.com/support/downloads/devices.aspx?c=us&amp;cs=19&amp;l=en&amp;s=dhs&amp;SystemID=INSPIRONI6400/E1505&amp;os=WW1&amp;osl=EN">Inspiron 6400</a>. I will walk through the configuration I used in the different stages of the <a href="http://www.gentoo.org/doc/en/handbook/">Gentoo Handbook</a> installation.</p>
<p>I chose to install the x86 version of Gentoo because it has better compatibility with closed sources applications like Java and Flash.</p>
<p>I&#8217;m not going to walk through how I set up my network for the install.</p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=4">4. Preparing the Disks</a></p>
<p>The <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=4#doc_chap4">disk layout</a> I chose is the same as the one the Gentoo Handbook recommends. That is a very small boot partition at the start of the disk, then a 512Meg swap partition after that, and lastly the rest of the disk is an ext3 partition that will be used for the root file system.</p>
<p>Here is the output of <code>fdisk -l</code>:</p>
<p><code>Disk&nbsp;/dev/sda:&nbsp;250.1&nbsp;GB,&nbsp;250059350016&nbsp;bytes</code><br />
<code>255&nbsp;heads,&nbsp;63&nbsp;sectors/track,&nbsp;30401&nbsp;cylinders,&nbsp;total&nbsp;488397168&nbsp;sectors</code><br />
<code>Units&nbsp;=&nbsp;sectors&nbsp;of&nbsp;1&nbsp;*&nbsp;512&nbsp;=&nbsp;512&nbsp;bytes</code><br />
<code>Sector&nbsp;size&nbsp;(logical/physical):&nbsp;512&nbsp;bytes&nbsp;/&nbsp;512&nbsp;bytes</code><br />
<code>I/O&nbsp;size&nbsp;(minimum/optimal):&nbsp;512&nbsp;bytes&nbsp;/&nbsp;512&nbsp;bytes</code><br />
<code>Disk&nbsp;identifier:&nbsp;0xab6ad924</code> </p>
<p><code>&nbsp;&nbsp;&nbsp;Device&nbsp;Boot&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Start&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Blocks&nbsp;&nbsp;&nbsp;Id&nbsp;&nbsp;System</code><br />
<code>/dev/sda1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2048&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;67583&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32768&nbsp;&nbsp;&nbsp;83&nbsp;&nbsp;Linux</code><br />
<code>/dev/sda2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;67584&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1116159&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;524288&nbsp;&nbsp;&nbsp;82&nbsp;&nbsp;Linux&nbsp;swap&nbsp;/&nbsp;Solaris</code><br />
<code>/dev/sda3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1116160&nbsp;&nbsp;&nbsp;488397167&nbsp;&nbsp;&nbsp;243640504&nbsp;&nbsp;&nbsp;83&nbsp;&nbsp;Linux</code></p>
<p>As you can see I have added a larger hard drive to this laptop but otherwise the partition layout is nice and simple. I decided not to use ext4 because I don&#8217;t think I will require any of it&#8217;s new features and maybe it&#8217;s not as light wait as ext3, but I am not certain of that.</p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=5">5. Installing the Gentoo Installation Files</a></p>
<p>The only thing that I did different in this section was to set the <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=5#doc_chap4_sect3"><code>MAKEOPTS</code></a> to use three threads.</p>
<p><code>MAKEOPTS="-j3"</code></p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=6#doc_chap2">6. Installing the Gentoo Base System</a></p>
<p>I have added a large number of <code>USE</code> flags to the <code>make.conf</code> file, this is just to make sure that all the required features are compiled in. Also the video card driver has been set to the <code>intel</code> driver.</p>
<p>Here is the <code>make.conf</code> file:</p>
<p><code>#&nbsp;These&nbsp;settings&nbsp;were&nbsp;set&nbsp;by&nbsp;the&nbsp;catalyst&nbsp;build&nbsp;script&nbsp;that&nbsp;automatically</code><br />
<code>#&nbsp;built&nbsp;this&nbsp;stage.</code><br />
<code>#&nbsp;Please&nbsp;consult&nbsp;/usr/share/portage/config/make.conf.example&nbsp;for&nbsp;a&nbsp;more</code><br />
<code>#&nbsp;detailed&nbsp;example.</code><br />
<code>CFLAGS="-O2&nbsp;-march=i686&nbsp;-pipe"</code><br />
<code>CXXFLAGS="${CFLAGS}"</code><br />
<code>#&nbsp;WARNING:&nbsp;Changing&nbsp;your&nbsp;CHOST&nbsp;is&nbsp;not&nbsp;something&nbsp;that&nbsp;should&nbsp;be&nbsp;done&nbsp;lightly.</code><br />
<code>#&nbsp;Please&nbsp;consult&nbsp;http://www.gentoo.org/doc/en/change-chost.xml&nbsp;before&nbsp;changing.</code><br />
<code>CHOST="i686-pc-linux-gnu"</code><br />
<code>MAKEOPTS="-j3"</code> </p>
<p><code>USE="a52&nbsp;aac&nbsp;acpi&nbsp;aim&nbsp;alsa&nbsp;cdda&nbsp;cddb&nbsp;cdr&nbsp;css&nbsp;dts&nbsp;dv&nbsp;dvd&nbsp;dvdr&nbsp;encode&nbsp;ffmpeg&nbsp;flac&nbsp;gif</code><br />
<code>gphoto2&nbsp;icq&nbsp;ios&nbsp;ipod&nbsp;jpeg&nbsp;jpeg2k&nbsp;lame&nbsp;lirc&nbsp;matroska&nbsp;mmx&nbsp;mp3&nbsp;mp4&nbsp;mpeg&nbsp;mplayer&nbsp;msn</code><br />
<code>musicbrainz&nbsp;ogg&nbsp;opengl&nbsp;png&nbsp;quicktime&nbsp;raw&nbsp;samba&nbsp;smp&nbsp;sound&nbsp;sse&nbsp;sse2&nbsp;svg&nbsp;svga&nbsp;theora&nbsp;truetype</code><br />
<code>udev&nbsp;usb&nbsp;v4l&nbsp;v4l2&nbsp;vcd&nbsp;vorbis&nbsp;wifi&nbsp;win32codecs&nbsp;wmf&nbsp;x264&nbsp;xvid"</code> </p>
<p><code>GENTOO_MIRRORS="ftp://mirror.bytemark.co.uk/gentoo/&nbsp;http://mirror.bytemark.co.uk/gentoo/&nbsp;rsync://mirror.bytemark.co.uk/gentoo/&nbsp;ftp://mirror.qubenet.net/mirror/gentoo/&nbsp;http://mirror.qubenet.net/mirror/gentoo/&nbsp;rsync://rsync.mirrorservice.org/www.ibiblio.org/gentoo/&nbsp;http://www.mirrorservice.org/sites/www.ibiblio.org/gentoo/&nbsp;ftp://ftp.mirrorservice.org/sites/www.ibiblio.org/gentoo/&nbsp;ftp://gentoo.virginmedia.com/sites/gentoo&nbsp;http://gentoo.virginmedia.com/"</code> </p>
<p><code>SYNC="rsync://rsync.uk.gentoo.org/gentoo-portage"</code> </p>
<p><code>VIDEO_CARDS="intel"</code></p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=7">7. Configuring the Kernel</a></p>
<p>I have <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=7#doc_chap3">customised the kernel</a> (2.6.36-gentoo-r8) quite a bit to fit this laptop and to add some extra functionality for wireless and XBMC support.</p>
<p>Below are the custom settings that I used.</p>
<p><a name="processor"></a>Processor:<br />
<code>Processor&nbsp;type&nbsp;and&nbsp;features&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Processor&nbsp;family&nbsp;(Core&nbsp;2/newer&nbsp;Xeon)&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(X)&nbsp;Core&nbsp;2/newer&nbsp;Xeon</code></p>
<p><a name="fiel-system"></a>File System:<br />
<code>File&nbsp;systems&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;Second&nbsp;extended&nbsp;fs&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Ext2&nbsp;extended&nbsp;attributes</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext2&nbsp;POSIX&nbsp;Access&nbsp;Control&nbsp;Lists</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext2&nbsp;Security&nbsp;Labels</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Ext2&nbsp;execute&nbsp;in&nbsp;place&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;Ext3&nbsp;journalling&nbsp;file&nbsp;system&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Ext3&nbsp;extended&nbsp;attributes</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext3&nbsp;POSIX&nbsp;Access&nbsp;Control&nbsp;Lists</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext3&nbsp;Security&nbsp;Labels</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;The&nbsp;Extended&nbsp;4&nbsp;(ext4)&nbsp;filesystem</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Ext4&nbsp;extended&nbsp;attributes</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext4&nbsp;POSIX&nbsp;Access&nbsp;Control&nbsp;Lists</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ext4&nbsp;Security&nbsp;Labels</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Dnotify&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Inotify&nbsp;support&nbsp;for&nbsp;userspace</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Quota&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Report&nbsp;quota&nbsp;messages&nbsp;through&nbsp;netlink&nbsp;interface</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;Quota&nbsp;format&nbsp;vfsv0&nbsp;and&nbsp;vfsv1&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;Kernel&nbsp;automounter&nbsp;version&nbsp;4&nbsp;support&nbsp;(also&nbsp;supports&nbsp;v3)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;FUSE&nbsp;(Filesystem&nbsp;in&nbsp;Userspace)&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;CD-ROM/DVD&nbsp;Filesystems&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;ISO&nbsp;9660&nbsp;CDROM&nbsp;file&nbsp;system&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Microsoft&nbsp;Joliet&nbsp;CDROM&nbsp;extensions</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Transparent&nbsp;decompression&nbsp;extension</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;UDF&nbsp;file&nbsp;system&nbsp;support&nbsp;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;DOS/FAT/NT&nbsp;Filesystems&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;MSDOS&nbsp;fs&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;VFAT&nbsp;(Windows-95)&nbsp;fs&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(437)&nbsp;Default&nbsp;codepage&nbsp;for&nbsp;FAT</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(iso8859-1)&nbsp;Default&nbsp;iocharset&nbsp;for&nbsp;FAT</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;NTFS&nbsp;file&nbsp;system&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;NTFS&nbsp;write&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Network&nbsp;File&nbsp;Systems&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;NFS&nbsp;client&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NFS&nbsp;client&nbsp;support&nbsp;for&nbsp;NFS&nbsp;version&nbsp;3</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NFS&nbsp;client&nbsp;support&nbsp;for&nbsp;the&nbsp;NFSv3&nbsp;ACL&nbsp;protocol&nbsp;extension</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NFS&nbsp;client&nbsp;support&nbsp;for&nbsp;NFS&nbsp;version&nbsp;4</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Root&nbsp;file&nbsp;system&nbsp;on&nbsp;NFS</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;CIFS&nbsp;support&nbsp;(advanced&nbsp;network&nbsp;filesystem,&nbsp;SMBFS&nbsp;successor)</code></p>
<p><a name="intel-graphics"></a>Intel Graphics: (<a href="http://en.gentoo-wiki.com/wiki/Intel_GMA">Intel GMA</a>, <a href="http://www.gentoo.org/doc/en/dri-howto.xml">Gentoo 3D Acceleration</a>, <a href="http://bugs.gentoo.org/81440">GLX</a>)<br />
<code>Device&nbsp;Drivers&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Graphics&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Direct&nbsp;Rendering&nbsp;Manager&nbsp;(XFree86&nbsp;4.1.0&nbsp;and&nbsp;higher&nbsp;DRI&nbsp;support)&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Intel&nbsp;I810</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Intel&nbsp;830M,&nbsp;845G,&nbsp;852GM,&nbsp;855GM,&nbsp;865G&nbsp;(i915&nbsp;driver)&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(X)&nbsp;i915&nbsp;driver</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enable&nbsp;modesetting&nbsp;on&nbsp;intel&nbsp;by&nbsp;default</code></p>
<p><a name="sound"></a>Sound: (<a href="http://www.gentoo.org/doc/en/alsa-guide.xml">Gentoo Alsa</a>)<br />
<code>Device&nbsp;Drivers&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;Sound&nbsp;card&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Advanced&nbsp;Linux&nbsp;Sound&nbsp;Architecture&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;PCI&nbsp;sound&nbsp;devices&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Intel&nbsp;HD&nbsp;Audio&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;hwdep&nbsp;interface&nbsp;for&nbsp;HD-audio&nbsp;driver</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Realtek&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Analog&nbsp;Device&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;IDT/Sigmatel&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;VIA&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;ATI&nbsp;HDMI&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;NVIDIA&nbsp;HDMI&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;INTEL&nbsp;HDMI&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Cirrus&nbsp;Logic&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Conexant&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Creative&nbsp;CA0110-IBG&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;C-Media&nbsp;HD-audio&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Build&nbsp;Silicon&nbsp;Labs&nbsp;3054&nbsp;HD-modem&nbsp;codec&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Enable&nbsp;generic&nbsp;HD-audio&nbsp;codec&nbsp;parser</code></p>
<p><a name="network"></a>Network:<br />
<code>Device&nbsp;Drivers&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Network&nbsp;device&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Broadcom&nbsp;440x/47xx&nbsp;ethernet&nbsp;support</code></p>
<p><a name="wireless"></a>Wireless: (<a href="http://en.gentoo-wiki.com/wiki/Iwlwifi">Iwlwifi</a>, <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=4&amp;chap=4">Gentoo Wireless</a>):<br />
<em>The wireless drivers are loaded as modules because they need to access the file system (<code>/lib/firmware</code>) which is loaded AFTER the kernel loads.</em><br />
<code>General&nbsp;setup&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Prompt&nbsp;for&nbsp;development&nbsp;and/or&nbsp;incomplete&nbsp;code/drivers</code><br />
<code>[*]&nbsp;Networking&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;Wireless&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;cfg80211&nbsp;-&nbsp;wireless&nbsp;configuration&nbsp;API</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nl80211&nbsp;testmode&nbsp;command</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enable&nbsp;powersave&nbsp;by&nbsp;default</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cfg80211&nbsp;wireless&nbsp;extensions&nbsp;compatibility</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Wireless&nbsp;extensions&nbsp;sysfs&nbsp;files</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Common&nbsp;routines&nbsp;for&nbsp;IEEE802.11&nbsp;drivers</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Generic&nbsp;IEEE&nbsp;802.11&nbsp;Networking&nbsp;Stack&nbsp;(mac80211)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Enable&nbsp;LED&nbsp;triggers</code><br />
<code>Device&nbsp;Drivers&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;Generic&nbsp;Driver&nbsp;Options&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;Userspace&nbsp;firmware&nbsp;loading&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;Network&nbsp;device&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Wireless&nbsp;LAN&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;M&gt;&nbsp;&nbsp;&nbsp;Intel&nbsp;Wireless&nbsp;Wifi</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enable&nbsp;full&nbsp;debugging&nbsp;output&nbsp;in&nbsp;iwlagn&nbsp;and&nbsp;iwl3945&nbsp;drivers</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;M&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intel&nbsp;Wireless&nbsp;WiFi&nbsp;Next&nbsp;Gen&nbsp;AGN&nbsp;(iwlagn)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intel&nbsp;Wireless&nbsp;WiFi&nbsp;4965AGN</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intel&nbsp;Wireless-N/Advanced-N/Ultimate-N&nbsp;WiFi&nbsp;Link</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;M&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Intel&nbsp;PRO/Wireless&nbsp;3945ABG/BG&nbsp;Network&nbsp;Connection&nbsp;(iwl3945)</code><br />
<code>-*-&nbsp;Cryptographic&nbsp;API&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;Cryptographic&nbsp;algorithm&nbsp;manager</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;Disable&nbsp;run-time&nbsp;self&nbsp;tests</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;Authenc&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;CBC&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;ECB&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;PCBC&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;HMAC&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;MD5&nbsp;digest&nbsp;algorithm</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Michael&nbsp;MIC&nbsp;keyed&nbsp;digest&nbsp;algorithm</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;SHA1&nbsp;digest&nbsp;algorithm</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;SHA224&nbsp;and&nbsp;SHA256&nbsp;digest&nbsp;algorithm</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;AES&nbsp;cipher&nbsp;algorithms</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;AES&nbsp;cipher&nbsp;algorithms&nbsp;(i586)</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;ARC4&nbsp;cipher&nbsp;algorithm</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;-*-&nbsp;&nbsp;&nbsp;DES&nbsp;and&nbsp;Triple&nbsp;DES&nbsp;EDE&nbsp;cipher&nbsp;algorithms</code></p>
<p><a name="sd-card"></a>SD Card:<br />
<code>Device&nbsp;Drivers&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;MMC/SD/SDIO&nbsp;card&nbsp;support&nbsp;&nbsp;---&gt;</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;MMC&nbsp;block&nbsp;device&nbsp;driver</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[*]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Use&nbsp;bounce&nbsp;buffer&nbsp;for&nbsp;simple&nbsp;hosts</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;Secure&nbsp;Digital&nbsp;Host&nbsp;Controller&nbsp;Interface&nbsp;support</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;SDHCI&nbsp;support&nbsp;on&nbsp;PCI&nbsp;bus</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;*&gt;&nbsp;&nbsp;&nbsp;SDHCI&nbsp;support&nbsp;on&nbsp;the&nbsp;platform&nbsp;specific&nbsp;bus</code></p>
<p>You&#8217;ll notice that in the <a href="#wireless">wireless</a> section some of the drivers have been compiled as modules so they need to be registered to load on start up. I have added them to my <code>/etc/modules.autoload.d/kernel-2.6</code> file, they are the only modules in there.</p>
<p><code>#&nbsp;/etc/modules.autoload.d/kernel-2.6:&nbsp;&nbsp;kernel&nbsp;modules&nbsp;to&nbsp;load&nbsp;when&nbsp;system&nbsp;boots.</code><br />
<code>#</code><br />
<code>#&nbsp;Note&nbsp;that&nbsp;this&nbsp;file&nbsp;is&nbsp;for&nbsp;2.6&nbsp;kernels.</code><br />
<code>#</code><br />
<code>#&nbsp;Add&nbsp;the&nbsp;names&nbsp;of&nbsp;modules&nbsp;that&nbsp;you'd&nbsp;like&nbsp;to&nbsp;load&nbsp;when&nbsp;the&nbsp;system</code><br />
<code>#&nbsp;starts&nbsp;into&nbsp;this&nbsp;file,&nbsp;one&nbsp;per&nbsp;line.&nbsp;&nbsp;Comments&nbsp;begin&nbsp;with&nbsp;#&nbsp;and</code><br />
<code>#&nbsp;are&nbsp;ignored.&nbsp;&nbsp;Read&nbsp;man&nbsp;modules.autoload&nbsp;for&nbsp;additional&nbsp;details.</code><br />
<code></code><br />
<code>#&nbsp;For&nbsp;example:</code><br />
<code>#&nbsp;aic7xxx</code><br />
<code></code><br />
<code>iwlcore</code><br />
<code>iwlagn</code><br />
<code>iwl3945</code></p>
<p>Also for the sound to work the <a href="http://www.gentoo.org/doc/en/alsa-guide.xml"><code>alsa</code> needs to be configured</a>. So first install <code>alsa</code>.<br />
<code>#&gt;&nbsp;emerge&nbsp;-av&nbsp;alsa-utils</code></p>
<p>Once <code>alsa</code> has finished installing start it up.</p>
<p><code>#&gt;&nbsp;/etc/init.d/alsasound&nbsp;start</code></p>
<p>Next unmute the volume so that it is possible to actually hear something. Do this by starting <code>alsamixer</code> then highlighting the <code>Master</code> and <code>PCM</code> channels and pressing the &#8216;m&#8217; key to make sure they have <code>00</code> instead of <code>MM</code> at the bottom.</p>
<p><code>#&gt;&nbsp;alsamixer</code></p>
<p>Lastly set <code>alsa</code> to start at boot.</p>
<p><code>#&gt;&nbsp;rc-update&nbsp;add&nbsp;alsasound&nbsp;boot</code></p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=8#doc_chap2">8. Configuring your System</a></p>
<p>I set up fstab in the a exact same way as the handbook, but the <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=8#doc_chap2">networking</a> I had to do a little differently.</p>
<p>Firstly to get the wireless working I had to install an extra package called <code>iwl3945-ucode</code> which is used by the drivers.</p>
<p><code>#&gt; emerge -av iwl3945-ucode</code></p>
<p>Also a symlink needs to be created in the <code>/etc/init.d/</code> directory for the wireless network.</p>
<p><code>#&gt; cd /etc/init.d/</code><br />
<code>#&gt; ln -s net.lo net.wlan0</code></p>
<p>Now the Gentoo handbook says to register the <code>net.eth0</code> interface to start at boot, don&#8217;t do this because it will be started anyway. One thing that can be done is to <a href="http://forums.gentoo.org/viewtopic-t-804861.html">tell Gentoo which interface to start</a> <code>net.eth0</code> or <code>net.wlan0</code>, this is done within the <code>/etc/conf.d/rc</code> script in the <code>RC_PLUG_SERVICES</code> variable.</p>
<p>Below is the <code>RC_PLUG_SERVICES</code> setting that I used to only start the wlan0 interface.</p>
<p><code>RC_PLUG_SERVICES="net.lo net.wlan0 !net.eth*"</code></p>
<p>Next the wired and wireless network need to be setup so they start correctly, I have configured them both with static IP&#8217;s, this is so that later I will be able to control XBMC with the Android remote.</p>
<p><code>/etc/conf.d/net:</code><br />
<code>#&nbsp;This&nbsp;blank&nbsp;configuration&nbsp;will&nbsp;automatically&nbsp;use&nbsp;DHCP&nbsp;for&nbsp;any&nbsp;net.*</code><br />
<code>#&nbsp;scripts&nbsp;in&nbsp;/etc/init.d.&nbsp;&nbsp;To&nbsp;create&nbsp;a&nbsp;more&nbsp;complete&nbsp;configuration,</code><br />
<code>#&nbsp;please&nbsp;review&nbsp;/etc/conf.d/net.example&nbsp;and&nbsp;save&nbsp;your&nbsp;configuration</code><br />
<code>#&nbsp;in&nbsp;/etc/conf.d/net&nbsp;(this&nbsp;file&nbsp;:]!).</code><br />
<code></code><br />
<code>config_eth0=(&nbsp;"192.168.1.32&nbsp;netmask&nbsp;255.255.255.0&nbsp;brd&nbsp;192.168.1.255"&nbsp;)</code><br />
<code>routes_eth0=(&nbsp;"default&nbsp;via&nbsp;192.168.1.254"&nbsp;)</code><br />
<code></code><br />
<code>#&nbsp;Prefer&nbsp;wpa_supplicant&nbsp;over&nbsp;wireless-tools</code><br />
<code>modules=(&nbsp;"wpa_supplicant"&nbsp;)</code><br />
<code></code><br />
<code>#&nbsp;It's&nbsp;important&nbsp;that&nbsp;we&nbsp;tell&nbsp;wpa_supplicant&nbsp;which&nbsp;driver&nbsp;we&nbsp;should</code><br />
<code>#&nbsp;be&nbsp;using&nbsp;as&nbsp;it's&nbsp;not&nbsp;very&nbsp;good&nbsp;at&nbsp;guessing&nbsp;yet</code><br />
<code>wpa_supplicant_wlan0="-Dwext"</code><br />
<code></code><br />
<code>config_wlan0=(&nbsp;"192.168.1.42&nbsp;netmask&nbsp;255.255.255.0&nbsp;brd&nbsp;192.168.1.255"&nbsp;)</code><br />
<code>routes_wlan0=(&nbsp;"default&nbsp;via&nbsp;192.168.1.254"&nbsp;)</code></p>
<p>My <code>wpa_supplicant</code> configuration is very simple.</p>
<p><code>/etc/wpa_supplicant/wpa_supplicant.conf:</code><br />
<code>#&nbsp;The&nbsp;below&nbsp;line&nbsp;not&nbsp;be&nbsp;changed&nbsp;otherwise&nbsp;we&nbsp;refuse&nbsp;to&nbsp;work</code><br />
<code>ctrl_interface=/var/run/wpa_supplicant</code><br />
<code></code><br />
<code>#&nbsp;Ensure&nbsp;that&nbsp;only&nbsp;root&nbsp;can&nbsp;read&nbsp;the&nbsp;WPA&nbsp;configuration</code><br />
<code>ctrl_interface_group=0</code><br />
<code></code><br />
<code>#&nbsp;Let&nbsp;wpa_supplicant&nbsp;take&nbsp;care&nbsp;of&nbsp;scanning&nbsp;and&nbsp;AP&nbsp;selection</code><br />
<code>ap_scan=1</code><br />
<code></code><br />
<code>#&nbsp;Simple&nbsp;case:&nbsp;WPA-PSK,&nbsp;PSK&nbsp;as&nbsp;an&nbsp;ASCII&nbsp;passphrase,&nbsp;allow&nbsp;all&nbsp;valid&nbsp;ciphers</code><br />
<code>network={</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;ssid="MyWireless"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;psk="password"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;higher&nbsp;the&nbsp;priority&nbsp;the&nbsp;sooner&nbsp;we&nbsp;are&nbsp;matched</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;priority=5</code><br />
<code>}</code><br />
<code></code><br />
<code>#&nbsp;Same&nbsp;as&nbsp;previous,&nbsp;but&nbsp;request&nbsp;SSID-specific&nbsp;scanning&nbsp;(for&nbsp;APs&nbsp;that&nbsp;reject</code><br />
<code>#&nbsp;broadcast&nbsp;SSID)</code><br />
<code>network={</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;ssid="MyWireless"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;scan_ssid=1</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;psk="password"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;priority=2</code><br />
<code>}</code></p>
<p>The last extra piece of configuration that I carried out is to do with the <a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=8#doc_chap3_pre3">key mapping</a>, I created mappings for the <a href="https://wiki.archlinux.org/index.php/Dell_Inspiron_6400#Multimedia_Buttons">buttons on the front of the laptop</a> that are meant to be used to control the DVD drive. I have mapped these keys to the keyboard letters that correspond to the <a href="http://wiki.xbmc.org/index.php?title=Global_Keyboard">volume and play controls of XBMC</a>.</p>
<p><a href="http://www.gentoo-wiki.info/TIP_Console:_Change_Caps_Lock_to_Control">Custom key mappings</a> need to be placed in a file under the <code>/usr/share/keymaps/include/</code> directory and can have any name as long as they have the &#8220;<code>.map</code>&#8221; extension.</p>
<p>The file I created was called <code>facebuttons.map</code> and had the following content.<br />
<code>/usr/share/keymaps/include/facebuttons.map:</code><br />
<code>keycode&nbsp;113&nbsp;=&nbsp;0x0030</code><br />
<code>keycode&nbsp;114&nbsp;=&nbsp;0x002d</code><br />
<code>keycode&nbsp;115&nbsp;=&nbsp;0x002b</code><br />
<code>keycode&nbsp;164&nbsp;=&nbsp;0x0020</code><br />
<code>keycode&nbsp;165&nbsp;=&nbsp;0x0072</code><br />
<code>keycode&nbsp;163&nbsp;=&nbsp;0x0066</code><br />
<code>keycode&nbsp;166&nbsp;=&nbsp;0x0078</code></p>
<p>This creates the following mapping:<br />
Mute Button -&gt; 0<br />
Volume Down Button -&gt; -<br />
Volume Up Button -&gt; +<br />
Play Button -&gt; Space<br />
Track Back Button -&gt; r<br />
Track Forward Button -&gt; f<br />
Stop Button -&gt; x</p>
<p>To find the values of the face buttons use the <a href="https://wiki.archlinux.org/index.php/Hotkeys"><code>showkey</code></a> program, just run it and start pressing the face buttons you should get output like this:<br />
<code>#&gt; showkey</code><br />
<code>...</code><br />
<code>keycode&nbsp;113&nbsp;press&nbsp;&nbsp;&nbsp;&nbsp;&lt;--&nbsp;When&nbsp;I&nbsp;Pressed&nbsp;Mute</code><br />
<code>keycode&nbsp;113&nbsp;release</code><br />
<code>keycode&nbsp;114&nbsp;press&nbsp;&nbsp;&nbsp;&nbsp;&lt;--&nbsp;When&nbsp;I&nbsp;Pressed&nbsp;Volume&nbsp;Down</code><br />
<code>keycode&nbsp;114&nbsp;release</code><br />
<code>keycode&nbsp;115&nbsp;press&nbsp;&nbsp;&nbsp;&nbsp;&lt;--&nbsp;When&nbsp;I&nbsp;Pressed&nbsp;Volume&nbsp;Up</code><br />
<code>keycode&nbsp;115&nbsp;release</code><br />
<code>keycode&nbsp;164&nbsp;press&nbsp;&nbsp;&nbsp;&nbsp;&lt;--&nbsp;When&nbsp;I&nbsp;Pressed&nbsp;Play</code><br />
<code>keycode&nbsp;164&nbsp;release</code></p>
<p>Now to find the &#8220;keysym&#8221; (the last value in the key mapping) for the keys that you want the buttons to represent run the <a href="https://wiki.archlinux.org/index.php/Extra_Keyboard_Keys_in_Console"><code>dumpkeys -l</code></a> command and <code>grep</code> the keys you want.<br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;zero</code><br />
<code><strong>0x0030&nbsp;&nbsp;&nbsp;&nbsp;zero</strong></code><br />
<code>0x0830&nbsp;&nbsp;&nbsp;&nbsp;Meta_zero</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;plus</code><br />
<code><strong>0x002b&nbsp;&nbsp;&nbsp;&nbsp;plus</strong></code><br />
<code>0x00b1&nbsp;&nbsp;&nbsp;&nbsp;plusminus</code><br />
<code>0x082b&nbsp;&nbsp;&nbsp;&nbsp;Meta_plus</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;minus</code><br />
<code><strong>0x002d&nbsp;&nbsp;&nbsp;&nbsp;minus</strong></code><br />
<code>0x00b1&nbsp;&nbsp;&nbsp;&nbsp;plusminus</code><br />
<code>0x082d&nbsp;&nbsp;&nbsp;&nbsp;Meta_minus</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;space</code><br />
<code><strong>0x0020&nbsp;&nbsp;&nbsp;&nbsp;space</strong></code><br />
<code>0x00a0&nbsp;&nbsp;&nbsp;&nbsp;nobreakspace</code><br />
<code>0x0820&nbsp;&nbsp;&nbsp;&nbsp;Meta_space</code><br />
<code>no-break_space&nbsp;&nbsp;for&nbsp;nobreakspace</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;"r$"</code><br />
<code>0x0012&nbsp;&nbsp;&nbsp;&nbsp;Control_r</code><br />
<code>0x0024&nbsp;&nbsp;&nbsp;&nbsp;dollar</code><br />
<code>0x0034&nbsp;&nbsp;&nbsp;&nbsp;four</code><br />
<code>0x003e&nbsp;&nbsp;&nbsp;&nbsp;greater</code><br />
<code><strong>0x0072&nbsp;&nbsp;&nbsp;&nbsp;r</strong></code><br />
<code>0x007c&nbsp;&nbsp;&nbsp;&nbsp;bar</code><br />
<code>0x00a6&nbsp;&nbsp;&nbsp;&nbsp;brokenbar</code><br />
<code>0x00b2&nbsp;&nbsp;&nbsp;&nbsp;twosuperior</code><br />
<code>0x00b3&nbsp;&nbsp;&nbsp;&nbsp;threesuperior</code><br />
<code>0x00b9&nbsp;&nbsp;&nbsp;&nbsp;onesuperior</code><br />
<code>0x00bc&nbsp;&nbsp;&nbsp;&nbsp;onequarter</code><br />
<code>0x0118&nbsp;&nbsp;&nbsp;&nbsp;Prior</code><br />
<code>0x030e&nbsp;&nbsp;&nbsp;&nbsp;KP_Enter</code><br />
<code>0x0701&nbsp;&nbsp;&nbsp;&nbsp;AltGr</code><br />
<code>0x0812&nbsp;&nbsp;&nbsp;&nbsp;Meta_Control_r</code><br />
<code>0x0824&nbsp;&nbsp;&nbsp;&nbsp;Meta_dollar</code><br />
<code>0x0834&nbsp;&nbsp;&nbsp;&nbsp;Meta_four</code><br />
<code>0x083e&nbsp;&nbsp;&nbsp;&nbsp;Meta_greater</code><br />
<code>0x0872&nbsp;&nbsp;&nbsp;&nbsp;Meta_r</code><br />
<code>0x087c&nbsp;&nbsp;&nbsp;&nbsp;Meta_bar</code><br />
<code>0x0c01&nbsp;&nbsp;&nbsp;&nbsp;SAltGr</code><br />
<code>PageUp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;Prior</code><br />
<code>AltR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;AltGr</code><br />
<code>Alt_R&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;AltGr</code><br />
<code>AltGr_R&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;AltGr</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;"f$"</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0000&nbsp;-&nbsp;0x00ff</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0100&nbsp;-&nbsp;0x01ff</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0500&nbsp;-&nbsp;0x05ff</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0800&nbsp;-&nbsp;0x08ff</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0b00&nbsp;-&nbsp;0x0bff</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;0x0d00&nbsp;-&nbsp;0x0dff</code><br />
<code>0x0006&nbsp;&nbsp;&nbsp;&nbsp;Control_f</code><br />
<code><strong>0x0066&nbsp;&nbsp;&nbsp;&nbsp;f</strong></code><br />
<code>0x00bd&nbsp;&nbsp;&nbsp;&nbsp;onehalf</code><br />
<code>0x0806&nbsp;&nbsp;&nbsp;&nbsp;Meta_Control_f</code><br />
<code>0x0866&nbsp;&nbsp;&nbsp;&nbsp;Meta_f</code><br />
<code>#&gt;&nbsp;dumpkeys&nbsp;-l&nbsp;|&nbsp;grep&nbsp;"x$"</code><br />
<code>0x0018&nbsp;&nbsp;&nbsp;&nbsp;Control_x</code><br />
<code>0x0036&nbsp;&nbsp;&nbsp;&nbsp;six</code><br />
<code><strong>0x0078&nbsp;&nbsp;&nbsp;&nbsp;x</strong></code><br />
<code>0x00c2&nbsp;&nbsp;&nbsp;&nbsp;Acircumflex</code><br />
<code>0x00ca&nbsp;&nbsp;&nbsp;&nbsp;Ecircumflex</code><br />
<code>0x00ce&nbsp;&nbsp;&nbsp;&nbsp;Icircumflex</code><br />
<code>0x00d4&nbsp;&nbsp;&nbsp;&nbsp;Ocircumflex</code><br />
<code>0x00db&nbsp;&nbsp;&nbsp;&nbsp;Ucircumflex</code><br />
<code>0x00e2&nbsp;&nbsp;&nbsp;&nbsp;acircumflex</code><br />
<code>0x00ea&nbsp;&nbsp;&nbsp;&nbsp;ecircumflex</code><br />
<code>0x00ee&nbsp;&nbsp;&nbsp;&nbsp;icircumflex</code><br />
<code>0x00f4&nbsp;&nbsp;&nbsp;&nbsp;ocircumflex</code><br />
<code>0x00fb&nbsp;&nbsp;&nbsp;&nbsp;ucircumflex</code><br />
<code>0x0402&nbsp;&nbsp;&nbsp;&nbsp;dead_circumflex</code><br />
<code>0x0818&nbsp;&nbsp;&nbsp;&nbsp;Meta_Control_x</code><br />
<code>0x0836&nbsp;&nbsp;&nbsp;&nbsp;Meta_six</code><br />
<code>0x0878&nbsp;&nbsp;&nbsp;&nbsp;Meta_x</code><br />
<code>dead_caron&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;dead_circumflex</code></p>
<p>Now that the mappings have been setup we need to tell Gentoo to use them, this is done by putting the name of our mappings file minus the extension into the <code>EXTENDED_KEYMAPS</code> variable of the <code>/etc/conf.d/keymaps</code> file.</p>
<p><code>#&nbsp;/etc/conf.d/keymaps</code></p>
<p><code>#&nbsp;Use&nbsp;KEYMAP&nbsp;to&nbsp;specify&nbsp;the&nbsp;default&nbsp;console&nbsp;keymap.&nbsp;&nbsp;There&nbsp;is&nbsp;a&nbsp;complete&nbsp;tree</code><br />
<code>#&nbsp;of&nbsp;keymaps&nbsp;in&nbsp;/usr/share/keymaps&nbsp;to&nbsp;choose&nbsp;from.</code></p>
<p><code>KEYMAP="us"</code></p>
<p><code>#&nbsp;Should&nbsp;we&nbsp;first&nbsp;load&nbsp;the&nbsp;'windowkeys'&nbsp;console&nbsp;keymap?&nbsp;&nbsp;Most&nbsp;x86&nbsp;users&nbsp;will</code><br />
<code>#&nbsp;say&nbsp;"yes"&nbsp;here.&nbsp;&nbsp;Note&nbsp;that&nbsp;non-x86&nbsp;users&nbsp;should&nbsp;leave&nbsp;it&nbsp;as&nbsp;"no".</code></p>
<p><code>SET_WINDOWKEYS="no"</code></p>
<p><code>#&nbsp;The&nbsp;maps&nbsp;to&nbsp;load&nbsp;for&nbsp;extended&nbsp;keyboards.&nbsp;&nbsp;Most&nbsp;users&nbsp;will&nbsp;leave&nbsp;this&nbsp;as&nbsp;is.</code></p>
<p><code>EXTENDED_KEYMAPS="facebuttons"</code></p>
<p><code>#&nbsp;Tell&nbsp;dumpkeys(1)&nbsp;to&nbsp;interpret&nbsp;character&nbsp;action&nbsp;codes&nbsp;to&nbsp;be&nbsp;</code><br />
<code>#&nbsp;from&nbsp;the&nbsp;specified&nbsp;character&nbsp;set.</code><br />
<code>#&nbsp;This&nbsp;only&nbsp;matters&nbsp;if&nbsp;you&nbsp;set&nbsp;UNICODE="yes"&nbsp;in&nbsp;/etc/rc.conf.</code><br />
<code>#&nbsp;For&nbsp;a&nbsp;list&nbsp;of&nbsp;valid&nbsp;sets,&nbsp;run&nbsp;`dumpkeys&nbsp;--help`</code></p>
<p><code>DUMPKEYS_CHARSET=""</code></p>
<p>That is the end of the extra configuration for this section.</p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=10#doc_chap2">10. Configuring the Bootloader</a></p>
<p>I installed GRUB and used the following kernel line so that the console runs in a nice frame buffer.</p>
<p><code>kernel&nbsp;/boot/kernel-2.6.36-gentoo-r8&nbsp;root=/dev/sda3&nbsp;video=uvesafb:mtrr:3,ywrap,1280x800-32@60</code></p>
<p><a href="http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&amp;chap=11">11. Finalizing your Gentoo Installation</a></p>
<p>The very last peace of Gentoo specific configuration I did was to create an <code>xbmc</code> user. I made sure the user had video, audio, usb, and dvd privileges.</p>
<p><code>#&gt;&nbsp;useradd&nbsp;-d&nbsp;/home/xbmc&nbsp;-m&nbsp;-G&nbsp;audio,cdrom,video,cdrw,usb,users&nbsp;xbmc</code></p>
<p>Now reboot the laptop and hopefully everything works, if it does now would be a good time to run a global update.</p>
<p><code>#&gt;&nbsp;emerge&nbsp;--update&nbsp;--deep&nbsp;world</code></p>
<p>Once this has completed there is a good chance that Python will have been updated to version 3. XBMC and it&#8217;s dependencies do not like this version of Python so will fail to compile or run. To fix this use <code>eselect</code> to set Python back to version 2.6.</p>
<p><code>#&gt;&nbsp;eselect&nbsp;python&nbsp;list</code><br />
<code>Available&nbsp;Python&nbsp;interpreters:</code><br />
<code>&nbsp;&nbsp;[1]&nbsp;&nbsp;&nbsp;python2.6</code><br />
<code>&nbsp;&nbsp;[2]&nbsp;&nbsp;&nbsp;python3.1&nbsp;*</code></p>
<p><code>#&gt;&nbsp;eselect&nbsp;python&nbsp;set&nbsp;1</code><br />
<code>#&gt;&nbsp;eselect&nbsp;python&nbsp;list</code><br />
<code>Available&nbsp;Python&nbsp;interpreters:</code><br />
<code>&nbsp;&nbsp;[1]&nbsp;&nbsp;&nbsp;python2.6&nbsp;*</code><br />
<code>&nbsp;&nbsp;[2]&nbsp;&nbsp;&nbsp;python3.1</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/322/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/322/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/322/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=322&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/04/17/gentoo-installation-inspiron-6400/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Maven &#8211; Debug Test</title>
		<link>http://pier0w.wordpress.com/2011/03/17/maven-debug-test/</link>
		<comments>http://pier0w.wordpress.com/2011/03/17/maven-debug-test/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 16:15:14 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Debug]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Test]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=313</guid>
		<description><![CDATA[So if you happen to program in Intellij IDEA like my self you may have come across a situation where your tests pass within your IDE but fail when running mvn clean install. Generally this is because you did something silly in one of your tests that is now infecting all the following tests. Now [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=313&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So if you happen to program in Intellij IDEA like my self you may have come across a situation where your tests pass within your IDE but fail when running <code>mvn clean install</code>. Generally this is because you did something silly in one of your tests that is now infecting all the following tests.</p>
<p>Now it&#8217;s all well and good knowing you&#8217;ve done something wrong, but it&#8217;s not so helpful if you don&#8217;t actually know WHAT that something is. So now you&#8217;ll be thinking &#8220;I KNOW! I&#8217;ll run <code>mvn clean install</code> within Intellij IDEA in debug mode then step through them there tests. I SO SMART!&#8221;. Then with your maven build profile all configured within Intellij and your break points all precisely set you click on run debug and&#8230; the tests run to the end without a pause in site.</p>
<p>Now is when you&#8217;re wondering what the duce just happened. Well it turns out that maven runs it&#8217;s test in forked processes, this means that you may be happily debugging the maven process but you have absolutely no connection to the forked processes that are running the tests. So what to do?</p>
<p>The first, easiest and maybe even best thing to do is <a href="http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html">add the <code>-DforkMode=never</code> parameter</a> to your <code>mvn clean install</code> command to become&#8230;</p>
<pre>
mvn clean install -DforkMode=never
</pre>
<p>Who&#8217;d of thought?</p>
<p>In regards to your profile, put it in the Goals text field.</p>
<p>This will stop maven forking the tests so they will stay within the maven process you are actually debugging. So problem solved.</p>
<p>Though, what if you want to debug some tests that are running on another server? Well that is actually very simple as well. Simple kick the tests off with the <code>-Dmaven.surefire.debug</code> parameter included within your command. The maven tests will now pause at the beginning and expose a debug socket on port 5005 where you can then connect your favourite IDE to carry out the debugging. This works weather the tests are forked or not.</p>
<pre>
mvn clean install -Dmaven.surefire.debug
</pre>
<p>And that&#8217;s it, now you know how to debug your maven tests no matter where they are.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/313/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/313/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/313/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=313&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/03/17/maven-debug-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate Tutorial</title>
		<link>http://pier0w.wordpress.com/2011/02/23/hibernate-tutorial/</link>
		<comments>http://pier0w.wordpress.com/2011/02/23/hibernate-tutorial/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 23:14:10 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=251</guid>
		<description><![CDATA[What is Hibernate? Hibernate is an Object-relational Mapper or ORM. What this means is that hibernate will map database tables into Java objects. So for example if we have the table &#8220;user&#8221; in our ASCIISQL database like so: -------------------------------------------- &#124; id &#124; first_name &#124; last_name &#124; age &#124; gender &#124; &#124; 1 &#124; Some &#124; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=251&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What is Hibernate? Hibernate is an Object-relational Mapper or <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">ORM</a>. What this means is that hibernate will map database tables into Java objects.</p>
<p>So for example if we have the table &#8220;user&#8221; in our ASCIISQL database like so:</p>
<pre>
 --------------------------------------------
| id | first_name | last_name | age | gender |
| 1  | Some       | One       | 25  | MALE   |
 --------------------------------------------
</pre>
<p>Then hibernate could automatically map the values from that table into the following class:</p>
<pre>
package org.project.hibernate.domain.enums;

public enum GENDER {
    FEMALE,
    MALE
}
</pre>
<p></p>
<pre>
package org.project.hibernate.domain;

import org.project.hibernate.domain.enums.GENDER;

public class User {

    private Long id;
    private String firstName;
    private String lastName;
    private Long age;
    private GENDER gender;

    public User() {
    }

    public User(String firstName, String lastName, Long age, GENDER gender) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
        this.gender = gender;
    }

    public User(Long id, String firstName, String lastName, Long age, GENDER gender) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age;
        this.gender = gender;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Long getAge() {
        return age;
    }

    public void setAge(Long age) {
        this.age = age;
    }

    public GENDER getGender() {
        return gender;
    }

    public void setGender(GENDER gender) {
        this.gender = gender;
    }
}
</pre>
<p>This means that you can now try to ignore that fact that all your data is kept in a relational database. I mean TRY, because in reality that is something you will never succeed at.</p>
<p>But hibernate is still very helpful when it is working correctly.</p>
<p>So lets begin our first very simple hibernate project. So the first thing to do is <a href="http://pier0w.wordpress.com/2011/02/12/maven-new-project-tutorial/">create a project</a> and then get <a href="http://pier0w.wordpress.com/2011/02/12/initialise-git-project-tutorial/">git to track your changes</a>.</p>
<p><strong>Project naming suggestions:</strong><br />
<strong>groupId:</strong> org.project.hibernate<br />
<strong>artifactId:</strong> hibernate<br />
<strong>version:</strong> 1.0<br />
<strong>package:</strong> hibernate</p>
<p>Once that is complete open the project in Intelij IDEA and create a package called &#8220;<code>domain</code>&#8221; under the &#8220;<code>hibernate</code>&#8221; package. This is where we will put any of the Java objects that are going to be mapped to their equivalent tables, these will be <a href="http://www.alachisoft.com/resources/articles/dop.html">Domain Objects</a>. Domain Objects are there to provide a representation of our applications data that is not tied to the way the data is stored. So basically if all the data just ends up in domain objects it can easily be used within logic code without the need to care how it got there. For this tutorial Hibernate is going to be what got it there.</p>
<p>Now in the domain directory create the <code>User</code> class that was mentioned above along with the GENDER enum. We now have a user domain object.</p>
<p>Next create a <code>Hibernate</code> class in the <code>hibernate</code> package and give it a <code>main</code> method. Also create a JUnit 4 unit test class for the <code>Hibernate</code> class. You may have to update the version of the JUnit dependency in your pom file. Lastly delete the <code>App</code> class and it&#8217;s test class.</p>
<p>Now that we have the beginning of our project lets add the hibernate dependencies.</p>
<pre>
...
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;

        <strong><em>&lt;!--Hibernate and it's annotation dependencies.--&gt;</em>
        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
            &lt;version&gt;3.2.7.ga&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;ejb3-persistence&lt;/artifactId&gt;
            &lt;version&gt;1.0.2.GA&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
            &lt;artifactId&gt;hibernate-annotations&lt;/artifactId&gt;
            &lt;version&gt;3.4.0.GA&lt;/version&gt;
            &lt;exclusions&gt;
                &lt;exclusion&gt; <em>&lt;!-- Exclude included slf4j-api dependency to allow chosen version --&gt;</em>
                    &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                    &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
                &lt;/exclusion&gt;
            &lt;/exclusions&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
            &lt;artifactId&gt;jta&lt;/artifactId&gt;
            &lt;version&gt;1.1&lt;/version&gt;
        &lt;/dependency&gt;

        <em>&lt;!--Hibernates logging dependencies.--&gt;</em>
        &lt;dependency&gt;
            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
            &lt;version&gt;1.5.11&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
            &lt;version&gt;1.5.11&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
            &lt;version&gt;1.5.11&lt;/version&gt;
        &lt;/dependency&gt;

        <em>&lt;!--The embedded database that is going to be used.--&gt;</em>
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
            &lt;artifactId&gt;derby&lt;/artifactId&gt;
            &lt;version&gt;10.4.2.0&lt;/version&gt;
        &lt;/dependency&gt;</strong>
    &lt;/dependencies&gt;
...
</pre>
<p>Wow, that is a LOT of dependencies. You&#8217;ll notice that 3 of the dependencies are just logging api&#8217;s &#8220;<code>slf4j</code>&#8220;, hibernate seems to need you to include these dependencies your self. Don&#8217;t ask me why&#8230;</p>
<p>So now that we have all the dependencies we need lets configure hibernate so that we can start it up. How is that done? Well you create a hibernate configuration file of course. This is an XML file that tells hibernate where to find the database, how to log into the database, what type of SQL that database uses, where the domain classes are, what type of connection pooling should be used, if any, and loads of other stuff. </p>
<p>Create the <code>resources</code> directory and then a file within it called <code>hibernate.cfg.xml</code> and past the following into it.</p>
<pre>
&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
        <em>&lt;!-- Database connection settings --&gt;</em>
        &lt;property name="connection.driver_class"&gt;org.apache.derby.jdbc.EmbeddedDriver&lt;/property&gt;
        &lt;property name="connection.url"&gt;jdbc:derby:derbydb;create=true&lt;/property&gt;
        <em>&lt;!-- JDBC connection pool (use the built-in) --&gt;</em>
        &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
        <em>&lt;!-- SQL dialect --&gt;</em>
        &lt;property name="dialect"&gt;org.hibernate.dialect.DerbyDialect&lt;/property&gt;
        <em>&lt;!-- Enable Hibernate's automatic session context management --&gt;</em>
        &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
        <em>&lt;!-- Disable the second-level cache --&gt;</em>
        &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
        <em>&lt;!-- Echo all executed SQL to stdout --&gt;</em>
        &lt;property name="show_sql"&gt;true&lt;/property&gt;
        <em>&lt;!-- Drop and re-create the database schema on startup --&gt;</em>
        &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
        <em>&lt;!-- Boolean substitution --&gt;</em>
        &lt;property name="query.substitutions"&gt;true 'T', false 'F'&lt;/property&gt;

    &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p>This configuration will set up the database, but we are yet to configure any table mapping. Also it should be noted that this configuration will create the database by inferring it&#8217;s structure from the domain objects that we ask it to map. Since we haven&#8217;t asked it to map anything it won&#8217;t actually create a database at this stage.</p>
<p>Now lets start hibernate for the first time. To do this we use the hibernate configuration we just carried out to create a hibernate session factory. The session factory provides access to an instances of a hibernate session, the session is then used to carry out any request or updates to the database using the domain objects. </p>
<p>All of this must be done inside of a hibernate transaction, when in a transaction and before a transaction is started the session returned by the session factory will always be the same, but once a transaction has finished the session factory will return a brand new session.</p>
<p>So with that all as clear as mud lets start up hibernate and see if we can&#8217;t request our first session.</p>
<pre>
package org.project.hibernate;

<strong>import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;</strong>

public class Hibernate {

    <strong>private static final SessionFactory SESSION_FACTORY;

    static {
        <em>// Create a session factory with the config file.</em>
        SESSION_FACTORY = new Configuration().configure().buildSessionFactory();
    }</strong>

    public static void main(String[] args) {
        <strong>Session session = SESSION_FACTORY.getCurrentSession(); <em>// Request for the current hibernate session.</em>

        <em>// YAY! we found a session or BOO! we didn't.</em>
        System.out.println(session != null ? "YAY!" : "BOO!");</strong>
    }
}
</pre>
<p>Ok now that we know hibernate can be started lets map the User file with a hibernate mapping file. We could also map the file using annotations especially since we have the hibernate annotations dependency in our pom file. But I personally think that using mapping files is a better option for two reasons. First, mapping files provide a few features that have yet to be implemented for the annotations and secondly if you use annotations at some point you will find you need to use a custom hibernate annotation. This means you will have hibernate code within your code, so you will have some tight coupling to the hibernate framework which means if you ever want to use your domain classes somewhere else you will have to also bring in the hibernate dependencies which may not be necessary for the other project. Either that or you will have to create a second lot of identical code that just doesn&#8217;t contain the hibernate annotations. This of course is terribly bad for the maintainability of your code.</p>
<p>So here is the User mapping file. Create a directory called <code>mapping</code> within your <code>resources</code> directory then create a file called <code>User.hbm.xml</code> with that directory and past the following XML into it. We only create the mapping directory to keep the config files separate and tidy not for any strict reason.</p>
<pre>
&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;

&lt;hibernate-mapping package="org.project.hibernate.domain"&gt;

    <em>&lt;!-- Map the User class to the user_table table. It is called user_table --&gt;
    &lt;!-- because the word "user" is a key word in the Derby database. --&gt;</em>
    &lt;class name="User" table="user_table"&gt;

        &lt;id name="id"&gt;
            <em>&lt;!-- Map the id property for the User class and tell hibernate to --&gt;
            &lt;!-- automatically populate it with what ever method best --&gt;
            &lt;!-- suits the current database. --&gt;</em>
            &lt;generator class="native"/&gt;
        &lt;/id&gt;

        <em>&lt;!-- Map the firstName property to the first_name column. --&gt;</em>
        &lt;property name="firstName" column="first_name" not-null="true"/&gt;

        <em>&lt;!-- Map the lastName property to the last_name column. --&gt;</em>
        &lt;property name="lastName" column="last_name" not-null="true"/&gt;

        <em>&lt;!-- Map the age property to the age column. If you don't -&gt;
        &lt;!-- give a column name hibernate will assume the column name --&gt;
        &lt;!-- matches the property name. --&gt;</em>
        &lt;property name="age" not-null="true"/&gt;

       <em> &lt;!-- Map the gender property to the gender column --&gt;</em>
        &lt;property name="gender" not-null="true"&gt;
            <em>&lt;!-- Tell hibernate that this property is an enum and what type of enum it is. --&gt;</em>
            &lt;type name="org.hibernate.type.EnumType"&gt;
                &lt;param name="enumClass"&gt;org.project.hibernate.domain.enums.GENDER&lt;/param&gt;
            &lt;/type&gt;
        &lt;/property&gt;

    &lt;/class&gt;

&lt;/hibernate-mapping&gt;
</pre>
<p></p>
<p>We now need to tell hibernate about this mapping file by adding a mapping reference to the hibernate config file.</p>
<pre>
&lt;?xml version='1.0' encoding='utf-8'?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
&lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
        <em>&lt;!-- Database connection settings --&gt;</em>
        &lt;property name="connection.driver_class"&gt;org.apache.derby.jdbc.EmbeddedDriver&lt;/property&gt;
        &lt;property name="connection.url"&gt;jdbc:derby:derbydb;create=true&lt;/property&gt;
        <em>&lt;!-- JDBC connection pool (use the built-in) --&gt;</em>
        &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
        <em>&lt;!-- SQL dialect --&gt;</em>
        &lt;property name="dialect"&gt;org.hibernate.dialect.DerbyDialect&lt;/property&gt;
        <em>&lt;!-- Enable Hibernate's automatic session context management --&gt;</em>
        &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
        <em>&lt;!-- Disable the second-level cache --&gt;</em>
        &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
        <em>&lt;!-- Echo all executed SQL to stdout --&gt;</em>
        &lt;property name="show_sql"&gt;true&lt;/property&gt;
        <em>&lt;!-- Drop and re-create the database schema on startup --&gt;</em>
        &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
        <em>&lt;!-- Boolean substitution --&gt;</em>
        &lt;property name="query.substitutions"&gt;true 'T', false 'F'&lt;/property&gt;

       <strong> <em>&lt;!-- Reference to the User mapping file --&gt;</em>
        &lt;mapping resource="mapping/User.hbm.xml" /&gt;</strong>

    &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p></p>
<p>So now that hibernate knows how to map the <code>User</code> class we will be able to add and retrieve users from the database. Also because we have the <code>hbm2ddl.auto</code> property set to <code>update</code> hibernate will create the <code>user_table</code> table from the mapping information we have provided.</p>
<p>So since we can now do stuff with the database lets go and well&#8230; do stuff.</p>
<pre>
package org.project.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
<strong>import org.hibernate.Transaction;</strong>
import org.hibernate.cfg.Configuration;
<strong>import org.project.hibernate.domain.User;</strong>

import java.util.List;

import static org.project.hibernate.domain.enums.GENDER.MALE;

public class Hibernate {

    private static final SessionFactory SESSION_FACTORY;

    static {
        <em>// Create a session factory with the config file.</em>
        SESSION_FACTORY = new Configuration().configure().buildSessionFactory();
    }

    public static void main(String[] args) {
        Session session = SESSION_FACTORY.getCurrentSession(); <em>// Request for the current hibernate session.</em>

       <strong> if (session != null) {
            <em>// YAY! we found a session.</em>
            System.out.println("YAY!");

            <em>// First when using Hibernate to access a database you must create a transaction.
            // When ever you work inside a transaction there is less chance you will corrupt
            // the data within your database. This is because any changes you make will not
            // be committed until the transaction completes. So if something breaks while in
            // the transaction any changes you made to the database will be rolled back.</em>
            Transaction transaction = session.beginTransaction();

            <em>// Now we create a new user to place within the database. Notice we are using
            // the constructor that does not set the "id" property. This is because in the
            // mapping file we told hibernate to set the "id" property for us.</em>
            User user = new User("Some", "One", 25L, MALE);

           <em> // Now save the new user to the database.</em>
            session.save(user);

            <em>// Complete/commit the transaction so the changes get saved to the database.
            // This will also close the session.</em>
            transaction.commit();

            <em>// Display the id of the user we just save to show that hibernate
            // did in fact generate the id for us.</em>
            System.out.println("User saved. ID set to (" + user.getId() + ")");
            System.out.println();

            <em>// Now lets display the users in the database so that we can see the users that
            // accumulate within the database after each time we run this project.</em>
            System.out.println("Users in the database:");

            <em>// To access the database again we need to get a new session since we closed the last one.</em>
            session = SESSION_FACTORY.getCurrentSession();
            <em>// Also we will need to start a new transaction.</em>
            transaction = session.beginTransaction();

            <em>// Now we will request all the users from the database by using hibernates criteria API.
            // This provides a nice way of building up SQL queries problematically.
            // Notice we have to cast the list that is returned by hibernate into a list of Users. I really
            // do not see why this is required since we have told hibernate the class type that we are
            // looking for and the List that hibernate returns is actual contains Users.</em>
            List users = (List) session.createCriteria(User.class).list();

            <em>// We can now commit the transaction since we have all the data we want. Though if we
            // wanted to make changes to the users in the list we retrieved and then save those
            // changes to the database we would not be able to close the transaction here.</em>
            transaction.commit();

           <em> // Now we iterate through the users and display their values.</em>
            for (User u : users) {
                System.out.println("User");
                System.out.println(" - id: " + u.getId());
                System.out.println(" - First Name: " + u.getFirstName());
                System.out.println(" - Last Name: " + u.getLastName());
                System.out.println(" - Age: " + u.getAge());
                System.out.println(" - Gender: " + u.getGender());
                System.out.println();
            }

        } else {
            <em>// BOO! we didn't find a session.</em>
            System.out.println("BOO!");
        }</strong>
    }
}
</pre>
<p></p>
<p>Well that&#8217;s it we have created a working hibernate application. If you run this application over and over again it will keep adding users to the database. You can clear the database by just deleting the <code>derby</code> directory that is created under the root directory of your project .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/251/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/251/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/251/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=251&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/02/23/hibernate-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Tutorial Two (Spring MCV)</title>
		<link>http://pier0w.wordpress.com/2011/02/13/spring-tutorial-two-spring-mcv/</link>
		<comments>http://pier0w.wordpress.com/2011/02/13/spring-tutorial-two-spring-mcv/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 17:09:52 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=201</guid>
		<description><![CDATA[This next Spring tutorial is going to look at Spring MVC. This is Springs implementation of the Model View Controller architecture, with it you can configure your Model layer, configure the View template you wish to use, and create very simple and concise Controllers. Now just like all Java web application frameworks Spring MVC must [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=201&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This next Spring tutorial is going to look at Spring MVC. This is Springs implementation of the Model View Controller architecture, with it you can configure your Model layer, configure the View template you wish to use, and create very simple and concise Controllers. </p>
<p>Now just like all Java web application frameworks Spring MVC must be wrapped up within a WAR file and run from within a <a href="http://www.service-architecture.com/application-servers/articles/j2ee_web_server_or_container.html">Java web container</a>. A web container can just be thought of as an environment that provides all the required boilerplate to allow the easy creation of web applications. It will automatically handle the creation of a thread pool to handle any requests, create sessions so that you can keep state across a users time on your web app, and lots of other great stuff.</p>
<p>There are quite a lot of Java web containers out there, there is <a href="http://tomcat.apache.org/">Tomcat</a>, <a href="http://jetty.codehaus.org/jetty/">Jetty</a>, <a href="http://glassfish.java.net/">Glassfish</a>, and <a href="http://www.jboss.org/">JBoss</a> just to name a few.</p>
<p>The one we are going to use is Jetty, this is a Java web app container that can be embedded within an application. It is not the only one of course, <a href="http://oatv.com/pub/a/onjava/2002/04/03/tomcat.html">Tomcat can also be embedded</a>, but Jetty was specifically created for this purpose.</p>
<p>This tutorial is going to build on the <a href="http://pier0w.wordpress.com/2011/02/12/spring-tutorial-one-2/">previous Spring tutorial</a>, so open that within Intellij IDEA.</p>
<p>Since we are working with the project from the first tutorial lets make a tag to preserve the code in it&#8217;s current state. To do this navigate to the projects directory and type the following command.</p>
<p><strong>
<pre>#&gt; git tag -a tutorial_one -m "A tag taken at the end of the first Spring tutorial."</pre>
<p></strong></p>
<p>You can check to make sure that tag was created with this command.</p>
<p><strong>
<pre>#&gt; git tag -l -n1</pre>
<p></strong></p>
<p>The <code>-l</code> tells git to list the tags and the <code>-n1</code> tells git to display one line of the tags message. You can use a higher number to display more lines.</p>
<p>The first thing we will do is add the Jetty maven dependency to our pom file, so open the file and add the dependency to the &lt;dependencies&gt; tag.</p>
<pre>
...
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;3.0.3.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        <strong>&lt;dependency&gt;
            &lt;groupId&gt;org.eclipse.jetty.aggregate&lt;/groupId&gt;
            &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
            &lt;version&gt;7.1.4.v20100610&lt;/version&gt;
        &lt;/dependency&gt;</strong>
    &lt;/dependencies&gt;
...
</pre>
<p>Now lets remove pretty much all of the code we wrote in the first tutorial because it won&#8217;t be of any use to us in this new tutorial. Delete the context file in the resources directory, the <code>MyClassOne</code>, <code>MyClassTwo</code>, and <code>MyHolder</code> classes, all the code from within the <code>MainTest</code> leaving the shell of the test method, the <code>toStuff</code> method from within the <code>Main</code> class as well as all the code within the <code>main</code> method. Once that is done commit the changes into git.</p>
<pre>
package org.project;

public class Main {

    <strong>public static void main(String[] args) {
    }</strong>
}
</pre>
<pre>
package org.project;

import org.junit.Test;

public class MainTest {

    <strong>@Test
    public void testDoStuff() throws Exception {
    }</strong>
}
</pre>
<p>If you wish to get the old code back you can just checkout the tag.</p>
<p><strong>
<pre>#&gt; git checkout tutorial_one</pre>
<p></strong></p>
<p>Note that when you commit changes to the tag they will not actually be saved if you then move off the tag. To save your changes you will have to create a branch from the tag with the git <code>branch</code> method.</p>
<p>If you wish to then get back to the code we just committed then us this command.</p>
<p><strong>
<pre>#&gt; git checkout master</pre>
<p></strong></p>
<p>Now that we are back looking at our new code lets see if we can&#8217;t start up a Jetty server in preparation for our Spring code. First create an instance of a Jetty Server class, start the server, then join the server to the main thread so that the main thread doesn&#8217;t just exit right after starting the server.</p>
<pre>
package org.project;

<strong>import org.eclipse.jetty.server.Server;</strong>

public class Main {

    public static void main(String[] args) <strong>throws Exception</strong> {
        <strong>Server server = new Server(8080); // Create a server instance that listens on port 8080.
        server.start(); // Start the server.
        server.join(); // Join the main thread to the server so that the main thread doesn't exit.</strong>
    }
}
</pre>
<p><strong>Pro tip:</strong> Only copy the code from within the main method and past it into yours. Then use <code>ALT-ENTER</code> to get Intellij IDEA to import the jetty Server class for you. The start and join method calls will now be underlined in red so click within the code of one of them and in a moment a small red light build should show up off to the left. Click on it and select the <code>Add Exception(s) to Method Signature</code> option. This will make the main method throw the correct exception for the methods.</p>
<p>You can now run the main method and see the server start up. Though it is a rather useless application server because there is nothing running within it.</p>
<p>To get Jetty to run something he have to give it a <code>Handler</code>. It is possible to either create your own handler or use one of the pre-made handlers that Jetty provides. Since we are making a web application that will be running Spring MVC we will be using Jetty&#8217;s <code>WebAppContext</code> handler. To instantiate this handler you need to give it the path to where your web application configuration files will be and also the context of your web application. A context is simply some text that comes after the domain name of the web app where all of the web apps pages will fall under. So if a web app is found at the following URL.</p>
<p><strong>
<pre>http://localhost:8080/myapp/index.html</pre>
<p></strong></p>
<p>Then the context would be <code>myapp</code> and all the wep apps pages like <code>index.html</code> will be found under that context.</p>
<p>So lets instantiate a <code>WebAppContext</code> handler and give it the path <code>webapp</code> and the context <code>/</code> which means there actually will not be a context. </p>
<p>To get the proper path to the <code>webapp</code> directory we will need to get the resource URL and then get the external form from that. This is because we are running within the environment of a JAR file, so it is unfortunately not as simple as giving it the name of the directory.</p>
<p>We will also need to tell Jetty not to extract the web apps directory, this is again because we running the project from within a JAR environment.</p>
<pre>
package org.project;

import org.eclipse.jetty.server.Server;
<strong>import org.eclipse.jetty.webapp.WebAppContext;

import java.net.URL;</strong>

public class Main {

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080); // Create a server instance that listens on port 8080.

        <strong>URL webAppURL = server.getClass().getClassLoader().getResource("webapp"); // Find the webapp dir from within the JAR.

        String webAppPath = webAppURL.toExternalForm(); // Then get it's actual path string.

        WebAppContext webAppContext = new WebAppContext(webAppPath, "/"); // The config dir will be in resources/webapp.
        webAppContext.setExtractWAR(false); // Make sure not to extract the web app directory because we will run this in a JAR file.

        server.setHandler(webAppContext); // Add the WebAppContext handler to the Jetty server.</strong>

        server.start(); // Start the server.
        server.join(); // Join the main thread to the server so that the main thread doesn't exit.
    }
}
</pre>
<p>You can now try and run the Jetty server again but as you might expect it will crash, this is because we haven&#8217;t created the <code>webapp</code> directory under the <code>resources</code> directory. Also we haven&#8217;t created the <code>web.xml</code> file that is required by the <code>WebAppContext</code> handler.</p>
<p>Lets do both of those things now, first create the <code>webapp</code> directory under the <code>resources</code> directory, then create another directory under that called <code>WEB-INF</code>, lastly under that directory create an empty file called <code>web.xml</code>. In the end you should have a path to the web.xml file as follows.</p>
<p><strong>
<pre>src/main/resources/webapp/WEB-INF/web.xml</pre>
<p></strong></p>
<p>Now past the following into the web.xml file.</p>
<pre>
&lt;web-app id="WebApp_9" version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="   http://java.sun.com/xml/ns/javaee
                                http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;

    &lt;display-name&gt;Spring Tutorial Two&lt;/display-name&gt;
&lt;/web-app&gt;
</pre>
<p>Now run the <code>main</code> method again and Jetty should start up happily.</p>
<p>It is also a good idea to add a thread pool to Jetty, this will make it run a lot more efficiently and faster. We will start up a queued thread pool with a minimum of 10 threads and a maximum of 50 threads.</p>
<pre>
package org.project;

import org.eclipse.jetty.server.Server;
<strong>import org.eclipse.jetty.util.thread.QueuedThreadPool;</strong>
import org.eclipse.jetty.webapp.WebAppContext;

import java.net.URL;

public class Main {

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080); // Create a server instance that listens on port 8080.

        URL webAppURL = server.getClass().getClassLoader().getResource("webapp"); // Find the webapp dir from within the JAR.

        String webAppPath = webAppURL.toExternalForm(); // Then get it's actual path string.

        WebAppContext webAppContext = new WebAppContext(webAppPath, "/"); // The config dir will be in resources/webapp.
        webAppContext.setExtractWAR(false); // Make sure not to extract the web app directory because we will run this in a JAR file.

        server.setHandler(webAppContext); // Add the WebAppContext handler to the Jetty server.

        <strong>QueuedThreadPool threadPool = new QueuedThreadPool(); // Instantiate the thread pool.
        threadPool.setMinThreads(10); // Set the minimum threads to 10.
        threadPool.setMaxThreads(50); // Set the maximum threads to 50.

        server.setThreadPool(threadPool); // Add the thread pool to the Jetty server.</strong>

        server.start(); // Start the server.
        server.join(); // Join the main thread to the server so that the main thread doesn't exit.
    }
}
</pre>
<p>Right, so now the programmatical configuration of the Jetty server is complete. All the rest of our configuration will be done within the web.xml file.</p>
<p>The <code>web.xml</code> is where we will configure our Spring context. Remember in the first tutorial we started the Spring context within the <code>main</code> method. This time by configuring the Spring context object within the <code>web.xml</code> file we will get the web app container to start it.</p>
<p>Now to return a successful response to an HTTP request a Java Web Application Container needs to contain a Servlet. Servlets are J2EE classes that contain all the logic to handle request for a given URL pattern. That is all you will ever need to know about them because no one ever manually programs Servlets any more and all we will be doing is configuring the Spring context so that it behaves like a Servlet.</p>
<p>So as always when starting a Spring project the first thing we need to do is create a XML context configuration file and place it in the resources directory.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
&lt;/beans&gt;
</pre>
<p>Now that we have the context file we need to configure the Spring context class. We will use is the Spring <code>DispatcherServlet</code> class which configures the Spring context and wraps it in a J2EE Servlet. We will need to add the Spring MVC dependency to the pom file so that we have access the <code>DispatcherServlet</code> class and all the other classes within the Spring MVC module.</p>
<pre>
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        <strong>&lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
            &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;</strong>
        &lt;dependency&gt;
            &lt;groupId&gt;org.eclipse.jetty.aggregate&lt;/groupId&gt;
            &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
            &lt;version&gt;7.1.4.v20100610&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
</pre>
<p>To correctly configure this class we need to give it a name, the full name of the <code>DispatcherServlet</code> class, the path to the context file, and lastly the order in which it should be started. For our project we will want it to be the very first thing the web container starts.</p>
<pre>
&lt;web-app id="WebApp_9" version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="   http://java.sun.com/xml/ns/javaee
                                http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;

    &lt;display-name&gt;Spring Tutorial Two&lt;/display-name&gt;

    <strong>&lt;servlet&gt;
        &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
            &lt;param-value&gt;classpath:context.xml&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;load-on-startup&gt;0&lt;/load-on-startup&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;</strong>

&lt;/web-app&gt;
</pre>
<p>We can now run the main method again and we should see the Jetty server start as well as the Spring framework.</p>
<p>It is now possible to start actually writing some code for a very simple Spring MVC web app. The first place to start is the  Model or the M in MVC. The model is the data layer of the application, we shall make our model exceptionally simple, it will just be a class that contains some data. So lets create a <code>Model</code> class.</p>
<pre>
package org.project.model;

import java.util.Date;
import java.util.List;

public class Model {

    private String name;
    private Date date;
    private List data;
    private String message;

    public Model() {
    }

    public Model(String name, Date date, List data, String message) {
        this.name = name;
        this.date = date;
        this.data = data;
        this.message = message;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
</pre>
<p>And now lets wire it up within the Spring context file.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    <strong>&lt;bean id="model" class="org.project.model.Model"&gt;
        &lt;property name="name" value="Model"/&gt;
        &lt;property name="date"&gt;
            &lt;bean class="java.util.Date"/&gt;
        &lt;/property&gt;
        &lt;property name="data"&gt;
            &lt;list&gt;
                &lt;bean class="java.lang.Integer"&gt;&lt;constructor-arg value="1"/&gt;&lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;&lt;constructor-arg value="2"/&gt;&lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;&lt;constructor-arg value="3"/&gt;&lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;&lt;constructor-arg value="4"/&gt;&lt;/bean&gt;
            &lt;/list&gt;
        &lt;/property&gt;
        &lt;property name="message" value="Message from the model."/&gt;
    &lt;/bean&gt;</strong>
&lt;/beans&gt;
</pre>
<p>Now that we have a model lets configure our view, the V in MVC. The view is the framework that we will use to present the data from our model to the user, this is generally done with HTML. We will use Freemarker as our view, so lets first add it&#8217;s dependency to our pom file.</p>
<pre>
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
            &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.eclipse.jetty.aggregate&lt;/groupId&gt;
            &lt;artifactId&gt;jetty-webapp&lt;/artifactId&gt;
            &lt;version&gt;7.1.4.v20100610&lt;/version&gt;
        &lt;/dependency&gt;
        <strong>&lt;dependency&gt;
            &lt;groupId&gt;org.freemarker&lt;/groupId&gt;
            &lt;artifactId&gt;freemarker&lt;/artifactId&gt;
            &lt;version&gt;2.3.16&lt;/version&gt;
        &lt;/dependency&gt;</strong>
    &lt;/dependencies&gt;
</pre>
<p>Now that we have access to the Freemarker classes we can configure it in the Spring context file. There are two classes that need to be configured, the first is the <code>FreeMarkerConfigurer</code> class, here we set the path to the Freemarker files. The next class is the <code>FreeMarkerViewResolver</code> which is the class that will actually parse the Freemarker files. We will configure this so that it doesn&#8217;t cache the pages, so that it knows what files are our Freemarker files, enable the Spring extensions, and lastly set the Freemarker resolver to always be the first resolver that is picked by Spring when it tries to resolve a view.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    &lt;bean id="model" class="org.project.model.Model"&gt;
        &lt;property name="name" value="Model"/&gt;
        &lt;property name="date"&gt;
            &lt;bean class="java.util.Date"/&gt;
        &lt;/property&gt;
        &lt;property name="data"&gt;
            &lt;list&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="1"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="2"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="3"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="4"/&gt;
                &lt;/bean&gt;
            &lt;/list&gt;
        &lt;/property&gt;
        &lt;property name="message" value="Message from the model."/&gt;
    &lt;/bean&gt;

    <strong>&lt;bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"&gt;
        &lt;property name="templateLoaderPath" value="/WEB-INF/pages/"/&gt;
    &lt;/bean&gt;

    &lt;bean id="freemarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"&gt;
        &lt;property name="cache" value="false"/&gt;
        &lt;property name="prefix" value=""/&gt;
        &lt;property name="suffix" value=".ftl"/&gt;
        &lt;property name="exposeSpringMacroHelpers" value="true"/&gt;
        &lt;property name="order" value="0"/&gt;
    &lt;/bean&gt;</strong>

&lt;/beans&gt;
</pre>
<p>Now that our view framework is configured we can create a simple view page. This page will display the name and message properties of the model class. This class will be passed to the view by the controller which we will write next. To created the page first create the <code>pages</code> directory under the <code>WEB-INF</code> directory. This is where we said the Freemarker files would be when we configured the <code>FreeMarkerConfigurer</code> above. Then create a file called <code>view.ftl</code> and passed the following HTML into it.</p>
<pre>
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Spring Tutorial Two&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;<strong>${model.name}</strong>&lt;/h1&gt;
    &lt;p&gt;<strong>${model.message}</strong>&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The <code>${model.name}</code> and <code>${model.message}</code> within the page are the very small snippets of Freemarker that we are going to use in this tutorial. It is this syntax that is used to access a domain class and it&#8217;s properties. A domain class is a class that has been placed into the domain of a view by the controller. We will see how this is done soon.</p>
<p>Now that the view file is created we can move onto the controller, the C in MVC. A controller is a class to simply take data classes from the model and sends them into the view. This is usually done by the controller calling on a service layer that abstracts away any logic and decouples the Controllers and Views from the Model layer, but for simplicities sake we are just going to pass the Model class straight into the controller.</p>
<p>The annotations we are going to use are:<br />
@Controller &#8211; This is used to annotate a class to mark it as a Spring Controller.<br />
@RequestMapping &#8211; This is used to annotate a class or method to map them to a specific request URL pattern. When the annotation is used on a class it is usually used to map a common context that all the methods in that class will then fall under. Though it is also possible to map a class to a URL pattern then just have a method that handles all the GET request for that class. Other wise methods can have their own unique request URL patterns mapped to them.<br />
@Resource &#8211; This annotation is another way of telling Spring to inject a class, the difference between this and @Autowired is that with this annotation you can specify the name of the bean you would like to inject.</p>
<p>So after those explanations here is the controller.</p>
<pre>
package org.project.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.project.model.Model;

import javax.annotation.Resource;

@Controller
@RequestMapping(value = "/model")
public class ModelController {

    @Resource(name = "model")
    private Model model;

    @RequestMapping(value = "/view")
    public String view(ModelMap modelMap) {

        modelMap.addAttribute("model", model);

        return "view";
    }
}
</pre>
<p>For this controller we have used the combination of providing a request mapping for the class and the method. This means that Spring with route all request that begin with <code>/model</code> to the <code>ModelController</code> class, then it will finally route the complete pattern <code>/model/view</code> to the view method within that class.</p>
<p>We have given the method a <code>ModelMap</code> argument. Any <code>ModelMap</code> argument that you give to a request method will automatically be injected by Spring with the responses <code>ModelMap</code>. The ModelMap is a map that is forwarded by Spring to the view. So any classes you place into this map will become domain classes in the view. That is why we are placing the Model object into this map. It can get a bit confusing that the word Model is used by Spring to label classes that will be passed to the view, since this is also the name for the data layer of an application that uses the MVC pattern. This is also Spring MVC we are talking about so you would have thought they might have seen how that could be confusing, but oh well&#8230;</p>
<p>The last thing to explain about this controller is that the request method is returning a static <code>String</code> <code>"view"</code>. If Spring sees that your request method returns a <code>String</code> it will assume that that <code>String</code> will be that name of a view file that it should use to render the response. It is possible to have your request methods return far more complicated things but that is outside the scope of this tutorial. So with that in mind you can see that Spring will select out <code>view.ftl</code> file to render the response.</p>
<p>Now the very last thing we have to do is to tell Spring were our controller is. This is done in the same way that we told it how to find the <code>HyHolder</code> class at the end of the last tutorial.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       <strong>xmlns:context="http://www.springframework.org/schema/context"</strong>
       xsi:schemaLocation=" http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

                            <strong>http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-3.0.xsd</strong>"&gt;

    &lt;bean id="model" class="org.project.model.Model"&gt;
        &lt;property name="name" value="Model"/&gt;
        &lt;property name="date"&gt;
            &lt;bean class="java.util.Date"/&gt;
        &lt;/property&gt;
        &lt;property name="data"&gt;
            &lt;list&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="1"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="2"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="3"/&gt;
                &lt;/bean&gt;
                &lt;bean class="java.lang.Integer"&gt;
                    &lt;constructor-arg value="4"/&gt;
                &lt;/bean&gt;
            &lt;/list&gt;
        &lt;/property&gt;
        &lt;property name="message" value="Message from the model."/&gt;
    &lt;/bean&gt;

    &lt;bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"&gt;
        &lt;property name="templateLoaderPath" value="/WEB-INF/pages/"/&gt;
    &lt;/bean&gt;

    &lt;bean id="freemarkerViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"&gt;
        &lt;property name="cache" value="false"/&gt;
        &lt;property name="prefix" value=""/&gt;
        &lt;property name="suffix" value=".ftl"/&gt;
        &lt;property name="exposeSpringMacroHelpers" value="true"/&gt;
        &lt;property name="order" value="0"/&gt;
    &lt;/bean&gt;

    <strong>&lt;context:component-scan base-package="org.project.controllers"/&gt;</strong>
&lt;/beans&gt;
</pre>
<p>With that complete we can finally run our web application and the simple view we created should be able to be seen at the following URL displaying the data that we configured in the model.</p>
<p><a href="http://localhost:8080/model/view">http://localhost:8080/model/view</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/201/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=201&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/02/13/spring-tutorial-two-spring-mcv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Spring Tutorial One</title>
		<link>http://pier0w.wordpress.com/2011/02/12/spring-tutorial-one-2/</link>
		<comments>http://pier0w.wordpress.com/2011/02/12/spring-tutorial-one-2/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 17:52:41 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=190</guid>
		<description><![CDATA[Right so&#8230; what is Spring? Well the Spring About page has a good description of what it does but not how it does it or how you can does stuff with it. My self, I see Spring as a container that initialises and sticks all your classes together. This is handy because it means you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=190&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Right so&#8230; what is Spring? Well the Spring <a href="http://www.springsource.org/about">About</a> page has a good description of what it <em>does</em> but not how it <em>does</em> it or how you can <em>does</em> stuff with it. My self, I see Spring as a container that initialises and sticks all your classes together. This is handy because it means you don&#8217;t have to bother writing factory classes or singletons because Spring will start up a single instance of each class then propagate those single instances throughout any classes that require them. So you could almost think of Spring as duct tape for Java. </p>
<p>Springs main goal is to provide a paradigm called <a href="http://en.wikipedia.org/wiki/Inversion_of_control">Inversion of Control</a> or IoC. The wikipedia explanation is ok but it doesn&#8217;t really give you any idea about how this relates to Spring. Springs version of IoC can be easily summed up with the term Dependency Injection. Now coming from a unix background and being quite used to the dependency resolution of package managers, when I first heard that term I instantly thought Spring must be dynamically pulling down all the dependant libraries you have used and injecting them into your class path and maybe even dynamically adding the imports at compile time. This is of course not the case at all, but oddly is pretty much exactly what <a href="http://maven.apache.org/">Maven</a> does except for adding the imports, that&#8217;s what your IDE is for. Springs dependency injection refers to the dynamic injection of a classes properties during the start up of an application.</p>
<p>So say we have the following classes:</p>
<pre>
public class MyClassOne {

        private Integer one;

        // All classes that are to be used within Spring MUST have a default constructor.
        // This is so that Spring can instantiate the class before injecting the properties.
        public MyClassOne () {
        }

        public MyClassOne (Integer one) {
                this.one = one;
        }

        public Integer getOne() {
                return one;
        }

        public void setOne(Integer one) {
                this.one = one;
        }
}
</pre>
<pre>
public class MyClassTwo {

        private Integer two;

        // All classes that are to be used within Spring MUST have a default constructor.
        // This is so that Spring can instantiate the class before injecting the properties.
        public MyClassTwo () {
        }

        public MyClassTwo (Integer two) {
                this.two = two;
        }

        public Integer getTwo() {
                return two;
        }

        public void setTwo(Integer two) {
                this.two = two;
        }
}
</pre>
<pre>
public class MyHolder {

        private MyClassOne one;
        private MyClassTwo two;

        // All classes that are to be used within Spring MUST have a default constructor.
        // This is so that Spring can instantiate the class before injecting the properties.
        public MyHolder() {
        }

        public MyHolder(MyClassOne one, MyClassTwo two) {
                this.one = one;
                this.two = two;
        }

        public MyClassOne getMyClassOne() {
                return one;
        }

        public void setMyClassOne(MyClassOne one) {
                this.one = one;
        }

        public MyClassTwo getMyClassTwo() {
                return two;
        }

        public void setMyClassTwo(MyClassTwo two) {
                this.two = two;
        }

}
</pre>
<p>Spring would handle these classes by first instantiate <code>MyClassOne</code> and then <code>MyClassTwo</code>, Spring might even set an Integer value for both classes. The two new instances would then be used to create an instance of <code>MyHolder</code>, this would be done by injecting the instance of <code>MyClassOne</code> into the property named <em><code>one</code></em> and then injecting the instance of <code>MyClassTwo</code> into the property named <em><code>two</code></em>. </p>
<p>For my example I have only used concrete classes, it should also be noted that it is of course possible for Spring to inject a property with any object that can be cast into the properties type. So a property could just have the type of an interface which is great because your code then becomes a lot more generic since you don&#8217;t ever have to care about the implementation of your properties, you can let Spring decide on the best implementation for you.</p>
<p>Spring can do the injection in three different ways. First it can be told to instantiate the MyHolder class using the constructor that contains the arguments <em>one</em> and <em>two</em> and place the new MyClassOne and MyClassTwo instances in the correct slots. If this method is used the MyHolder class would not require a default constructor.<br />
Secondly Spring could instantiate an empty MyHolder class then use the setter and getter methods to populate the <em>one</em> and <em>two</em> properties.<br />
Lastly through the use of annotations Spring could then use reflection to directly access and set the values for the <em>one</em> and <em>two</em> properties.</p>
<p>If the last method is used it is actually possible to create classes that look like they would be impossible to use. For example it would be quite valid for the MyHolder classes code to be as follows:</p>
<pre>
public class MyHolder {

        @Autowired // Spring annotation that will be explained later.
        private MyClassOne one;

        @Autowired
        private MyClassTwo two;
}
</pre>
<p>It now looks like there is no way to set the properties in the MyHolder class but Spring can do this quite happily. It also looks rather clean and wizz bang nifty. Personally I don&#8217;t like using Spring like this because it tightly couples your cope to the Spring framework which I guess in reality is fine because you&#8217;ll rewrite your application before you&#8217;ll actually ever move away from Spring. But I personally think it is bad practice, if you wish to use Spring in this way I would still make sure to add all the getters and setters at the very least. I my self also add the property constructor as well.</p>
<p>So that is what the very basic core of Spring does, though there are now quite a lot of extra modules that make up the core Spring echo system that provide far more functionality including, web interface security, data validation, data base transacting and even more.</p>
<p>For this initial tutorial we will only be looking at the different types of dependency injection and how to start the Spring container outside of a J2EE container, which is the most common place to use Spring. The next tutorial will look at how to use Spring with the J2EE containers <a href="http://tomcat.apache.org/">Tomcat</a> and <a href="http://jetty.codehaus.org/jetty/">Jetty</a>.</p>
<p>Before starting this tutorial we need to make sure we have all the right equipment.</p>
<p>First the build tool we will be using is <a href="http://maven.apache.org/">Maven</a>, so make sure to have this installed and that you are connected to the internet. Though odds are if you are reading this you should have the second half of that done. Installing maven is very simple so I won&#8217;t be discussing how to do it here. We will just be using the default maven config so no extra configuration is required.</p>
<p>Secondly the <a href="http://en.wikipedia.org/wiki/Software_configuration_management">SCM</a> we will be using is <a href="http://git-scm.com/">git</a>. Again this just has to be installed and working, there is no need for any extra configuration, we won&#8217;t even be using a remote repository so that doesn&#8217;t even have to be set up.</p>
<p>Lastly the IDE I will be using for these examples will be <a href="http://www.jetbrains.com/idea/">Intellij IDEA</a>. I am going to use the free <a href="http://www.jetbrains.com/idea/free_java_ide.html">Community Edition</a>.</p>
<p>Once your environment is set up we can begin.</p>
<p>First we need to generate a maven project. This can be done by following the <a href="http://pier0w.wordpress.com/2011/02/12/maven-new-project-tutorial/">Maven New Project Tutorial</a>.</p>
<p>Ok so next we need get git to start tracking the changes on the project so move into the projects directory and run through the <a href="http://pier0w.wordpress.com/2011/02/12/initialise-git-project-tutorial/">Initialise GIT Project Tutorial</a>.</p>
<p>Git should now be tracking all of our files so it is time to open the project in our IDE. If you are using Intellij IDEA select <code>File-&gt;Open Project...</code> then find the project directory select it and click the <code>OK</code> button. Once the project is open click on the <code>Project</code> tab in the top left hand corner and you will see the project structure and all it&#8217;s files.<br />
Intellij will create some of it&#8217;s own project files within the spring directory, we do not want git to track these so to tell git to ignore them create a file called .gitignore within the spring directory and enter the following into it.</p>
<pre>
# Ignore intellij IDEA project files.
*.iml
*.ipr
*.iws

# Ignore the maven temporary build directory.
target/
</pre>
<p>Notice we are also going to ignore the maven build directory. Once that file is created add it to git and commit.</p>
<pre>
#&gt; git add .gitignore
#&gt; git commit -m "Created .gitignore file to stop tracking IDE project files and maven build directory."
</pre>
<p>You can now tell Intellij to recheck the git status by selecting <code>Version Control-&gt;Refresh File Status</code>. You will now see that the project files are no longer being tracked.</p>
<p>Now lets create our main class that we will use to run this project. Right click on the org.project package under the java directory and select New-&gt;Java Class and give the class the name <code>Main</code>. If you are asked whether you would like to add the new file to git tick the box to tell Intellij to stop asking and then click <code>Yes</code>.<br />
We now have an empty main class, lets give it a method called <code>doStuff</code> so we have something to test.</p>
<pre>
package org.project;

public class Main {

    public String doStuff() {
        return "Do Stuff.";
    }
}
</pre>
<p>You will now notice something odd, Intellij doesn&#8217;t seem to recognise the Java String class. This doesn&#8217;t seem right since that is part of the Java core library. The reason for this is that you have to tell Intellij which Java compiler it should use on your code. To do this place the cursor inside the word <code>String</code> that is the return type of the method. After a few moments you should see a red light bulb appear to the left of the word <code>public</code>. Now hover the cursor over the red light buld and click on the drop down arrow that appears and select the <code>Setup JDK</code> option, then click the <code>Configure...</code> button. Next click the small <code>+</code> button at the top left of the <code>Configure SDK</code> window, then select the <code>JSDK</code> option. Intellij should now be showing you the home directory of you JDK, select it and click <code>OK</code>, then click ok in the <code>Configure SDK</code> window, then finally click <code>OK</code> in the <code>Select Project SDK</code> window. Your Java compiler should now be setup.</p>
<p>The next thing to do will be to create a test class for <code>Main</code>. But before we do that we should update two things within our maven pom file.</p>
<p>First is the Java Compiler version, by default this is set to 1.4 which is far too old so we are going to upgrade it to 1.6 by adding the following to the root of the pom file.</p>
<pre>
    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;configuration&gt;
                    &lt;compilerVersion&gt;1.6&lt;/compilerVersion&gt;
                    &lt;fork&gt;true&lt;/fork&gt;
                    &lt;source&gt;1.6&lt;/source&gt;
                    &lt;target&gt;1.6&lt;/target&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;
</pre>
<p><strong>Pro tip:</strong> Press <code>CTRL-ALT-L</code> to format any code including <code>XML</code>.</p>
<p>Then we are going to update the JUnit verion to 4.7 by changing the version tag within the dependency.</p>
<pre>
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            <strong>&lt;version&gt;4.7&lt;/version&gt;</strong>
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
</pre>
<p><strong>Pro tip:</strong> Delete the number inside the version tag then press <code>CTRL-SPACE</code> to get a list of all the versions that are available for any maven dependency. This will work in most of the tags within the maven pom file so you could also use it to find all the artefacts within the <code>junit</code> group.</p>
<p>After editing the pom file Intellij will pop out a small message at the top of the code window asking to import the new changes from the pom file, click the <code>Import Changes</code> link in this pop out to tell Intellij to process the changes. Now that we have finished editing the pom file lets commit the changes by right clicking on the code and then selecting <code>Git-&gt;Commit File...</code>, this will pop up the commit changes window. The first thing to do here is to untick the <code>Perform code analyses for affected file</code> tick box. This will speed up your commits and also stop you getting bugged by Intellij. Then write your commit message into the <code>Commit</code> text area and click <code>Commit</code>.</p>
<p>Now click back into the <code>Main</code> class&#8217;s code and make sure the cursor is somewhere within the code for the class, clicking in it&#8217;s name is good then press <code>CTRL-SHIFT-T</code> to start the process of generating a JUnit test class. Click on the <code>Creat New Test...</code> option then make sure to select the <code>JUnit4</code> radio button at the top of the <code>Create Test</code> window, also tick the <code>doStuff</code> method to generate a test method, then click ok.<br />
We now have a test class so lets right a pointless test to make sure that the <code>doStuff</code> method is returning the correct string. For this we will need to statically import the junit assert methods.</p>
<pre>
package org.project;

import org.junit.Test;

<strong>import static junit.framework.Assert.*;</strong>

public class MainTest {

    // Test strings and other variables should be set up as constants so that they
    // can be easily modified and used across multiple tests.
    <strong>private static final String DO_STUFF = "Do Stuff.";</strong>

    @Test
    public void testDoStuff() throws Exception {
        <strong>Main main = new Main();

        // Assert that the method is returning the correct value.
        assertEquals("test do stuff method's return string", DO_STUFF, main.doStuff());</strong>
    }
}
</pre>
<p>To run the test right click on the method name and select  <code>Run "testDoStuff()"</code>.</p>
<p>Now that we have a new class and it&#8217;s corresponding test class we can safely delete the generated <code>AppTest</code> and <code>App</code> classes, in that order so that Intellij&#8217;s safe delete doesn&#8217;t complain. Once that is done it would also be a good idea to commit the new Main files to git. From now on I&#8217;m going to leave the commiting up to you.</p>
<p>At this point we should now have a very simple and completely useless maven project. You can test to see if it will build with the following command.</p>
<p><code>#&gt; mvn clean install</code></p>
<p>You should get a pointless yet successful build. Lets take this one step further by making a pointless yet executable project by creating a main method within the <code>main</code> class that outputs the string from the <code>doStuff</code> method.</p>
<pre>
package org.project;

public class Main {

    <strong>public static void main(String[] args) {
        Main main = new Main();

        System.out.println(main.doStuff());
    }</strong>

    public String doStuff() {
        return "Do Stuff.";
    }
}
</pre>
<p><strong>Pro tip:</strong> Type <code>psvm</code> inside the class and press the <code>TAB</code> key, this will automatically generate a <code>main</code> method. Also then type <code>sout</code> within the main method and press <code>TAB</code>, this will generate  <code>System.out.println()</code>.</p>
<p>We can now execute our class, try it by right clicking on the <code>main</code> method or the class in the <code>Project</code> pain and select <code>Run "Main.main()"</code>. Similar to how you previously ran the test.</p>
<p>Ok so far for a Spring tutorial there is very little about Spring so lets fix that.<br />
To be able to use Spring in our project we are going to need to add it as a dependency within our pom file.</p>
<pre>
   &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
</pre>
<p>We have added the <strong>spring-context</strong> module which will give us access to the Spring context which is where Spring stores all of it&#8217;s instantiated objects.</p>
<p>Now that we have access to all the classes we can start up the Spring container, so to do this we first have to create a context (config) file for the container to use on startup.<br />
To create the context file first create a directory called <code>resources</code> in the directory called <code>main</code> within the project, then create a file called <code>context.xml</code> and place the following inside it. The <code>resources</code> directory within a maven project is where all config and &#8220;resource&#8221; files should be placed.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
&lt;/beans&gt;
</pre>
<p>You now have an empty context file that can be used to start up a Spring container. So lets start it up, to do that we have to instantiate the <code>ClassPathXmlApplicationContext</code> class and give it the path to the context file as an argument.</p>
<pre>
package org.project;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

    public static void main(String[] args) {
       <strong> AbstractApplicationContext context = new ClassPathXmlApplicationContext("context.xml");</strong>

        Main main = new Main();

        System.out.println(main.doStuff());
    }

    public String doStuff() {
        return "Do Stuff.";
    }
}
</pre>
<p>Run the main class again and you should get some Spring output, but not much else. Now as I mentioned before Spring&#8217;s main feature is Dependency Injection, so lets inject some classes.</p>
<p>Before we can inject anything we need something to inject, so lets create the same classes that were mentioned at the start of this tutorial. <code>MyClassOne</code>, <code>MyClassTwo</code>, and <code>MyHolder</code>.</p>
<p>Once these classes have been created you can use Spring to inject and instantiate them by adding <code>bean</code> definitions to the context file. For the two my classes we are going to us property injection then for the holder we are going to use constructor injection.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=" http://www.springframework.org/schema/beans
                            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    <strong>&lt;bean id="myClassOne" class="org.project.MyClassOne"&gt;
        &lt;property name="one" value="1"/&gt;
    &lt;/bean&gt;

    &lt;bean id="myClassTwo" class="org.project.MyClassTwo"&gt;
        &lt;property name="two" value="2"/&gt;
    &lt;/bean&gt;

    &lt;bean id="myHolder" class="org.project.MyHolder"&gt;
        &lt;constructor-arg name="one" ref="myClassOne"/&gt;
        &lt;constructor-arg name="two" ref="myClassTwo"/&gt;
    &lt;/bean&gt;</strong>
&lt;/beans&gt;
</pre>
<p>Now lets access the new beans from the Spring context with the following code.</p>
<pre>
package org.project;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

    public static void main(String[] args) {
        Main main = new Main();

        System.out.println(main.doStuff());

        AbstractApplicationContext context = new ClassPathXmlApplicationContext("context.xml");

        <strong>// Retrieve MyClassOne using just the id. Casting required because no type set.
        MyClassOne one = (MyClassOne) context.getBean("myClassOne");

        // Retrieve MyClassTwo using the id and type. No cast required.
        MyClassTwo two = context.getBean("myClassTwo", MyClassTwo.class);

        System.out.println("Spring instantiated MyClassOne one value: " + one.getOne());
        System.out.println("Spring instantiated MyClassTwo two value: " + two.getTwo());

        // Retrieve MyHolder with just the type because there is only ever one instance instantiated.
        MyHolder holder = context.getBean(MyHolder.class);

        System.out.println("Spring instantiated MyHolder one value: " + holder.getOne().getOne());
        System.out.println("Spring instantiated MyHolder two value: " + holder.getTwo().getTwo());</strong>
    }

    public String doStuff() {
        return "Do Stuff.";
    }
}
</pre>
<p>Now if we run the application we should get output similar to the following.</p>
<pre>
Do Stuff.
06-Feb-2011 19:44:27 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1815859: startup date [Sun Feb 06 19:44:27 GMT 2011]; root of context hierarchy
06-Feb-2011 19:44:27 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [context.xml]
06-Feb-2011 19:44:27 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d2fc36: defining beans [myClassOne,myClassTwo,myHolder]; root of factory hierarchy
<strong>Spring instantiated MyClassOne one value: 1
Spring instantiated MyClassTwo two value: 2
Spring instantiated MyHolder one value: 1
Spring instantiated MyHolder two value: 2</strong>
</pre>
<p>The Spring project now actually does something interesting, it instantiates and injects some beans then retrieves and displays their content.</p>
<p>Lastly lets do some injection with Spring annotations. First we need to update the context file so that Spring knows where to look for the annotated classes. To do this add the spring context XSD to the context file to enable access to the context tags then add the component scan tag to scan for any annotated classes under the <code>org.project package</code>. Lastly comment out the wiring of the holder object in the context file.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      <strong>xmlns:context="http://www.springframework.org/schema/context"</strong>
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

            <strong>http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd</strong>"&gt;

    &lt;bean id="myClassOne" class="org.project.MyClassOne"&gt;
        &lt;property name="one" value="1"/&gt;
    &lt;/bean&gt;

    &lt;bean id="myClassTwo" class="org.project.MyClassTwo"&gt;
        &lt;property name="two" value="2"/&gt;
    &lt;/bean&gt;

    <strong>&lt;context:component-scan base-package="org.project"/&gt;</strong>

    <strong>&lt;!--&lt;bean id="myHolder" class="org.project.MyHolder"&gt;--&gt;
    &lt;!--&lt;constructor-arg name="one" ref="myClassOne"/&gt;--&gt;
    &lt;!--&lt;constructor-arg name="two" ref="myClassTwo"/&gt;--&gt;
    &lt;!--&lt;/bean&gt;--&gt;</strong>

&lt;/beans&gt;
</pre>
<p>Now we need to add the right annotations to the MyHolder class. FIrst we annotate the class with the <code>org.springframework.stereotype.Component</code> annotation. This tells Spring that this class should be instantiated and injected. Then we annotate the properties with <code>org.springframework.beans.factory.annotation.Autowired</code>, this tells Spring that the properties should be populated with beans in the context that match their type. It is also possible to just annotate the property constructor and then Spring will instantiate the class in the same way that it did with the previous context file configuration.</p>
<pre>
package org.project;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MyHolder {

    @Autowired
    private MyClassOne one;

    @Autowired
    private MyClassTwo two;

    public MyHolder() {
    }

    public MyHolder(MyClassOne one, MyClassTwo two) {
        this.one = one;
        this.two = two;
    }

    public MyClassOne getOne() {
        return one;
    }

    public void setOne(MyClassOne one) {
        this.one = one;
    }

    public MyClassTwo getTwo() {
        return two;
    }

    public void setTwo(MyClassTwo two) {
        this.two = two;
    }
}
</pre>
<p>And there you have it the end of the first Spring tutorial, where you have learned a little about what Spring <em>does</em>, how it <em>does</em> it, and the different ways to <em>does</em> things with it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=190&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/02/12/spring-tutorial-one-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Initialise GIT Project Tutorial</title>
		<link>http://pier0w.wordpress.com/2011/02/12/initialise-git-project-tutorial/</link>
		<comments>http://pier0w.wordpress.com/2011/02/12/initialise-git-project-tutorial/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 17:50:13 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=192</guid>
		<description><![CDATA[Git is a really nice distributed source control system. A distributed source control system allows every person working with it to have a local copy of the entire source repository including all of it&#8217;s change history, so the only difference between the copy of the repository on your machine and the central repository is that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=192&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Git is a really nice distributed source control system. A distributed source control system allows every person working with it to have a local copy of the entire source repository including all of it&#8217;s change history, so the only difference between the copy of the repository on your machine and the central repository is that everyone has decided to push their changes to the central repository.</p>
<p>This means you are able to make local commits without ever worrying about clashing with other developers. Clashes can only ever then occur when you finally decide to push all your changes to the central repository and since GIT has such fantastic auto merge capabilities you will very rarely have to worry about dealing with clashes your self. I find that this ease of committing makes me commit much more than I usually would with SVN since all of my commits will succeed every time.</p>
<p>So to get git to start monitoring your files move into your projects directory and run the git <code>init</code> command.</p>
<pre>
<strong>#&gt; cd project/
#&gt; git init</strong>
Initialized empty Git repository in /some/dir/project/.git/
</pre>
<p>You can now check to see what git has found in your project with the git <code>status</code> command.</p>
<pre>
<strong>#&gt; git status</strong>
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#	pom.xml
#	src/
nothing added to commit but untracked files present (use "git add" to track)
</pre>
<p>Since this is a maven project It has found the maven pom file and the source directory for your project. Now you can actually tell git to start tracking these by adding them to the repository and then carrying out our first commit.</p>
<pre>
<strong>#&gt; git add pom.xml src/
#&gt; git status</strong> # Just running git status again to check what files have been added.
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#	new file:   pom.xml
#	new file:   src/main/java/org/project/App.java
#	new file:   src/test/java/org/project/AppTest.java
#
<strong>#&gt; git commit -m "First commit."</strong> # Our first commit. Ignore the warnings, you can do what it says to stop git complaining if you like.
[master (root-commit) 4100aeb] First commit.
 Committer: Some One
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name '

 3 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 pom.xml
 create mode 100644 src/main/java/org/project/App.java
 create mode 100644 src/test/java/org/project/AppTest.java
</pre>
<p>Git is now tracking all the files within your project and will pick up any changes you make.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/192/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/192/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/192/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=192&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/02/12/initialise-git-project-tutorial/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
		<item>
		<title>Maven New Project Tutorial</title>
		<link>http://pier0w.wordpress.com/2011/02/12/maven-new-project-tutorial/</link>
		<comments>http://pier0w.wordpress.com/2011/02/12/maven-new-project-tutorial/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 17:32:51 +0000</pubDate>
		<dc:creator>pier0w</dc:creator>
				<category><![CDATA[Maven]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://pier0w.wordpress.com/?p=173</guid>
		<description><![CDATA[Maven is a Java build tool that not only compiles your project and automatically runs all it&#8217;s tests it also provides a really good directory structure and handles the retrieval of any JAR dependencies your project might have. Also as you might have guessed it builds your project in a way that it is then [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=173&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Maven is a Java build tool that not only compiles your project and automatically runs all it&#8217;s tests it also provides a really good directory structure and handles the retrieval of any JAR dependencies your project might have. Also as you might have guessed it builds your project in a way that it is then able to be used as a maven dependency it&#8217;s self.</p>
<p>This tutorial is only going to describe the very basic process of creating a new maven project. So lets begin.</p>
<p>Creating a maven project is as simple as running the following command.</p>
<pre>
<strong>#&gt; mvn archetype:generate</strong>
...
365: remote -&gt; wicket-scala-archetype (-)
366: remote -&gt; wikbook.archetype (-)
367: remote -&gt; circumflex-archetype (-)
368: remote -&gt; javg-minimal-archetype (-)
<strong>Choose a number: 99:</strong>
</pre>
<p><strong>Pro tip:</strong> If you get an error like the following saying that maven can&#8217;t find the archetype plugin this means that your repository is set to download a version of the plugin that is too new for the repository that you are using.<br />
<code>[INFO] Unable to find resource 'org.apache.maven.plugins:maven-archetype-plugin:maven-plugin:2.0-alpha-6' in repository central (http://repo1.maven.org/maven2)</code></p>
<p>To fix this you will need to open up the <code>.m2/repository/org/apache/maven/plugins/maven-archetype-plugin/maven-metadata-central.xml</code> file and edit the <code>&lt;latest&gt;</code> and <code>&lt;release&gt;</code> tags. Place the value of one of the <code>&lt;version&gt;</code> tags within them that is a couple version down from the what is in there. It&#8217;s also a good idea to just stay away from alpha versions so maybe take the highest version that isn&#8217;t alpha. Your <code>maven-metadata-central.xml</code> file will then look as follows.</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;metadata&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-archetype-plugin&lt;/artifactId&gt;
  &lt;versioning&gt;
    &lt;latest&gt;2.0&lt;/latest&gt;
    &lt;release&gt;2.0&lt;/release&gt;
    &lt;versions&gt;
      &lt;version&gt;1.0-alpha-3&lt;/version&gt;
      &lt;version&gt;1.0-alpha-4&lt;/version&gt;
      &lt;version&gt;1.0-alpha-7&lt;/version&gt;
      &lt;version&gt;2.0-alpha-1&lt;/version&gt;
      &lt;version&gt;2.0-alpha-2&lt;/version&gt;
      &lt;version&gt;2.0-alpha-3&lt;/version&gt;
      &lt;version&gt;2.0-alpha-4&lt;/version&gt;
      &lt;version&gt;2.0-alpha-5&lt;/version&gt;
      &lt;version&gt;2.0&lt;/version&gt;
    &lt;/versions&gt;
    &lt;lastUpdated&gt;20101028011818&lt;/lastUpdated&gt;
  &lt;/versioning&gt;
&lt;/metadata&gt;
</pre>
<p>This technique can also be used to fix any other plugins that might not download.</p>
<p>The <code>mvn archetype:generate</code> command will kick off a process to allow you to easily generate a maven project. You&#8217;ll be displayed with a list of around 300 &#8211; 400 custom maven projects that provide you with good starting points for different situations and frameworks, read through them, you might find a good starting point for your project, otherwise just select the default option (<code>99: remote -&gt; maven-archetype-quickstart</code>) by pressing <code>ENTER</code>.</p>
<pre>
367: remote -&gt; circumflex-archetype (-)
368: remote -&gt; javg-minimal-archetype (-)
Choose a number: 99:
Choose version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
<strong>Choose a number: 6:</strong>
</pre>
<p>Next you will be asked which version of the template you would like to use, select the latest by pressing <code>ENTER</code> again.</p>
<p>Now you need to select how you want to name your project by giving the group id (namespace), artifactId (name), version, and package name (generally but not always the same as your given groupId) of your project. Fill these in with what ever you feel is apropriate.</p>
<pre>
5: 1.0
6: 1.1
Choose a number: 6:
Define value for property 'groupId': : <strong>org.project</strong>
Define value for property 'artifactId': : <strong>project</strong>
Define value for property 'version': 1.0-SNAPSHOT: <strong>1.0</strong>
Define value for property 'package': org.project: <strong>#Press ENTER to select the groupId as the package name by default</strong>
Confirm properties configuration:
groupId: org.project
artifactId: project
version: 1.0
package: org.project
Y: <strong>#Press ENTER to confirm</strong>
</pre>
<p>You will now have a brand new maven project.</p>
<pre>
<strong>#&gt; ls -R project/</strong>
project/:
pom.xml  src

project/src:
main  test

project/src/main:
java

project/src/main/java:
org

project/src/main/java/org:
project

project/src/main/java/org/project:
App.java

project/src/test:
java

project/src/test/java:
org

project/src/test/java/org:
project

project/src/test/java/org/project:
AppTest.java
</pre>
<p>That is it you can now begin developing within the maven project. To build and run tests use the following command.<br />
<code><strong>#&gt; mvn clean install</strong></code></p>
<p>If the build command finishes successfully maven will place a copy of the JAR file it has built from your project into your local maven repository (the place where maven keeps all of your dependencies). This means that any classes from your project will be accessible from any other local maven projects as long as you add your project as a dependency. Your should remember though that your local build JAR&#8217;s only ever get updated after a successful run of <code>mvn install</code> so if you make a change in one project and want it to be seen by your other projects you will have to run a build.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pier0w.wordpress.com/173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pier0w.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pier0w.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pier0w.wordpress.com&amp;blog=12372253&amp;post=173&amp;subd=pier0w&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pier0w.wordpress.com/2011/02/12/maven-new-project-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/08dcce564a7e1be203c803306f7a472f?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pier0w</media:title>
		</media:content>
	</item>
	</channel>
</rss>
