<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andy Gibson</title>
	<atom:link href="http://www.andygibson.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andygibson.net/blog</link>
	<description>Open Source Projects &#38; Technical Writings</description>
	<lastBuildDate>Fri, 30 Jul 2010 02:42:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The key to being a good programmer</title>
		<link>http://www.andygibson.net/blog/article/the-key-to-being-a-good-programmer/</link>
		<comments>http://www.andygibson.net/blog/article/the-key-to-being-a-good-programmer/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 13:47:53 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1216</guid>
		<description><![CDATA[One blog topic that never seems to get old is what makes a good programmer, or how to be a good programmer, or what you can do to be a better programmer. The same activities are often listed as being the path to successful codesmithing, when really it is just the method by which the [...]]]></description>
			<content:encoded><![CDATA[<p>One blog topic that never seems to get old is what makes a good programmer, or how to be a good programmer, or what you can do to be a better programmer. The same activities are often listed as being the path to successful codesmithing, when really it is just the method by which the true magic happens. With programming, like many things, it isn&#8217;t what you do, it&#8217;s what you learn from it and the only key ingredient to being a good programmer (besides practice) is exposure to programming. Exposure comes in many forms, whether it is through hands-on practice or looking at someone elses code. Here&#8217;s a few of typical examples given and how it exposes us to programming.</p>
<h2>Work on projects outside of the office</h2>
<p>Working on your own projects outside of work lets you practice programming and exposes yourself to your own code.  It also lets you practice problem solving and gives you the opportunity to experiment with alternative solutions. Also, a number of times I&#8217;ve gone back and re-read something I wrote and found better ways of doing it. However, it needs to be mixed with exposure to outside code so you don&#8217;t just keep yourself in your own rut and writing the same code with the same mistakes.</p>
<h2>Works on Open Source projects</h2>
<p>Not only does this give you more practice but also the ability to work on other people&#8217;s source and see how they code their way around certain problems. It also gives you exposure to the build and testing processes which are tools than that help improve your skills. Usually, in the case of libraries, you don&#8217;t even need to work on the project, you can be exposed to some of their ideas just by using the API.</p>
<h2>Knows multiple languages</h2>
<p>Working with multiple languages does give you exposure to different ideas and ways of doing things, but in itself, doesn&#8217;t make a better programmer and can even be detrimental. A native English speaker may improve their vocabulary and be exposed to different phrases by knowing French or German, but it doesn&#8217;t make them a much better English speaker or writer. Flip that around and a native French speaker is going to give a better speech than an English speaker who picked up a bit of French. Similarly, a hardcore Java/c#/C++/Delphi guy is going to be better than someone who dabbles in it. </p>
<h1>Other Factors</h1>
<p>It could be argued that it is obvious that getting more experience leads to being a better programmer, but not so. Solitary practice and accumulation of personal experience may get you so far, even gets some people very far, but for most, external exposure is required to drive new experiences and learning whether it be writing code, drawing pictures or playing the guitar.</p>
<p>Joel Spolsky wrote that good programmers are smart and get things done which also happens to be what makes good lawyers, doctors, accountants and applies to just about every other profession. Obviously being smart is a good thing, but that will only take you to the point where you have to sit down and write some code.</p>
<p>Passion is often stated as a requirement for being a good programmer, but it is just a means to an end. In itself, it doesn&#8217;t make a good programmer but can be the fuel that drives the activities that do improve your game.  I&#8217;ve known a number of capable (not great) programmers who have little passion for it, they enjoy it, but it is purely a 9-5 job for them. The lack of passion shows in that they are content to just use existing skills without spending any time learning new ones or exploring the technical ecosystem available to them. </p>
<h1>Summary</h1>
<p>Try and expose yourself to as much code as possible, even bad code can be good for you as long as you aren&#8217;t copying it. Identify design patterns and more importantly, think about why those patterns were used over other patterns and what possible consequences are there of using that pattern. Learning the thinking behind other architectures will help when the time comes to make your own decisions. After all, when we get stuck as developers the first thing we do is Google it to see what someone else has done. This is just pre-emptive research!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/the-key-to-being-a-good-programmer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Accessing and Paginating CSV Files with DataValve</title>
		<link>http://www.andygibson.net/blog/tutorial/accessing-and-paginating-csv-files-with-datavalve/</link>
		<comments>http://www.andygibson.net/blog/tutorial/accessing-and-paginating-csv-files-with-datavalve/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 17:07:30 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Apprentice]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[DataValve]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Swing]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1123</guid>
		<description><![CDATA[
 Prerequisites
Install Maven
Installing DataValve Into Maven


While DataValve is mostly used with database driven back ends, this tutorial shows you how DataValve can turn a comma delimited file into a paginated list of objects that the user can page through. We will then use this data provider in a console application, a Swing application and a [...]]]></description>
			<content:encoded><![CDATA[<div class="prereq floatRight">
<ul> <lh>Prerequisites</lh></p>
<li>Install Maven</li>
<li><a href="http://www.andygibson.net/blog/tutorial/install-datavalve-into-maven/">Installing DataValve Into Maven</a></li>
</ul>
</div>
<p>While <a href="http://www.andygibson.net/blog/projects/datavalve/">DataValve</a> is mostly used with database driven back ends, this tutorial shows you how DataValve can turn a comma delimited file into a paginated list of objects that the user can page through. We will then use this data provider in a console application, a Swing application and a JSF web page using the DataValve data client interfaces.<br />
 <span id="more-1123"></span><br />
We will start by writing this tutorial as a console application and then demonstrate how the data provider can be used in other applications, even web applications. We&#8217;ll start by creating a new Maven application and then include the dependencies for DataValve. We&#8217;ll then create our comma delimited data provider, define a row mapper class for it, and hook it up to our demo data. We&#8217;ll then attach it to a dataset so we can easily iterate through the data. We will then take our provider and use it in different clients.</p>
<ol>
<li>Create a new Maven application in your IDE and add <code>datavalve-dataset</code>  as a dependency in your <code>pom.xml</code> file.
<pre class="brush: xml;">
	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.fluttercode.datavalve&lt;/groupId&gt;
			&lt;artifactId&gt;datavalve-dataset&lt;/artifactId&gt;
			&lt;version&gt;0.9.0.CR2&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
</pre>
</li>
<li>Create a new class called <code>Person</code> in the package of your choice. I used <code>org.fluttercode.tutorials.datavalve.csvreader</code> We will only be using one package in this demonstration.</li>
<li>The <code>Person</code> class will be our model which will be populated from the comma delimited file.
<pre class="brush: java;">
public class Person {

	private Integer id;
	private String firstName;
	private String middleName;
	private String lastName;
	private Date dob;
	private String email;
	private String address;
	private String city;
	private String zip;

	public Person() {
	}

	public Person(Integer id, String firstName, String lastName,String middleName,
			Date dob, String email, String address,
			String city, String zip) {
		super();
		this.id = id;
		this.firstName = firstName;
		this.middleName = middleName;
		this.lastName = lastName;
		this.email = email;
		this.dob = dob;
		this.address = address;
		this.city = city;
		this.zip = zip;
	}

	public String getName() {
		return firstName + &quot; &quot; + lastName;
	}

	public String getAddressText() {
		return address+ &quot;,&quot; + city+&quot;,&quot;+zip;
	}

	@Override
	public String toString() {
		return String.format(&quot;Person [id=%d, name=%s, dob=%s,address=%s, email=%s&quot;,
		    id,getName(),dob,getAddressText(),email);
	}

    .... Getters and Setters Omitted ....
}
</pre>
</li>
<li>In order to convert the csv data to an object, we need to create a <code>ColumnarRowMapper</code> instance. This takes a row of data, already converted to an array of string values, builds the model object from it and returns it back to the caller. Create a new class called <code>PersonRowMapper</code>.</li>
<pre class="brush: java;">
public class PersonRowMapper implements ColumnarRowMapper&lt;Person&gt; {

    private static SimpleDateFormat converter = new SimpleDateFormat(
			&quot;MM/dd/yyyy&quot;);

	public Person mapRow(String[] values) {
		Date dob = null;

		try {
			dob = converter.parse(values[5]);
		} catch (ParseException e) {
		}

		return new Person(DataConverter.getInteger(values[0]), values[1],
				values[2], values[3], dob, values[4], values[6], values[7],
				values[8]);
	}
}
</pre>
<p>This row mapper implements the <code>ColumnarRowMapper</code> interface and implements the single method to return a built entity object from the array of column values passed in.</p>
<li>The only other element we need is some test data to run it on which you can download from <a href='http://www.andygibson.net/blog/wp-content/uploads/2010/07/data.zip'>here</a>. Download this file and place it in the package folder with your source code. Depending on your IDE, you may need to refresh the folder in the package explorer so it can pick up the new file in the folder. The example file has 100 rows of data in it.</li>
<li>Create a new class called <code>ProviderFactory</code> which will create our provider and initialize it with the CSV file url.
<pre class="brush: java;">
public class ProviderFactory {

	public static CommaDelimitedProvider&lt;Person&gt; createProvider() {
		URL url = ProviderFactory.class.getResource(&quot;data.csv&quot;);
		CommaDelimitedProvider&lt;Person&gt; provider;
		provider = new CommaDelimitedProvider&lt;Person&gt;(url.getFile());
		provider.setRowMapper(new PersonRowMapper());
		return provider;
	}
}
</pre>
<p>We use a <code>URL</code> to reference the csv file stored in the jar from which we get a <code>File</code> instance that we can pass to our <code>CommaDelimitedProvider</code>. This relies on the <code>data.csv</code> file being in the same location as this class. Alternatively, you can put the file elsewhere and just create a regular <code>File</code> object to it rather than use the <code>URL</code>.
</li>
<li>For the console part of this demo, create a <code>Main</code> class and add a <code>main</code> method containing the code get an instance of the provider, and perform a simple iteration through the data.
<pre class="brush: java;">
public class Main {

	public static void main(String[] args) {
		CommaDelimitedProvider&lt;Person&gt; provider;

		provider= ProviderFactory.createProvider();

		List&lt;Person&gt; results = provider.fetchResults(new DefaultPaginator());
		for (Person p : results) {
			System.out.println(p);
		}
	}
}
</pre>
<p>In this example we are reading all the results at once in memory and displaying the whole list.</li>
</ol>
<h2>Paginating the results</h2>
<p>We can control which results and how many are displayed by using a paginator to control the flow of data. This can be useful if you have a huge file and it would be impractical to read all the results into memory in one go. Datasets have paginators built in and use a reference to a provider to fetch the actual data.</p>
<ol>
<li>In the <code>main</code> method, instead of using the provider directly, create a dataset and pass it a reference to our data provider.
<pre class="brush: java;">
public static void main(String[] args) {
	CommaDelimitedProvider&lt;Person&gt; provider;

	provider = ProviderFactory.createProvider();

	CommaDelimitedDataset&lt;Person&gt; ds = new CommaDelimitedDataset&lt;Person&gt;(provider);
	ds.setMaxRows(10);
	List&lt;Person&gt; results = ds.getResultList();
	for (Person p : results) {
		System.out.println(p);
	}
}
</pre>
<p>We have set the maximum number of rows to 10 so the results returned only contains 10 rows of data at most. We can use this mechanism to control the number of results fetched if they are paginated.</li>
<li>The dataset classes implement the <code>Iterable</code> interface which lets us iterate over the entire set of data. By setting the page size, we can control the batch sizes when the data is fetched in while it is being iterated over. This allows us to control the flow of data, either to reduce the in-memory realization of the source data, or to reduce latency in an otherwise slow data source as the application can process one page of data while the provider is loading the next page of data.
<pre class="brush: java;">
public static void main(String[] args)  {
	CommaDelimitedProvider&lt;Person&gt; provider;
	provider = ProviderFactory.createProvider();

	CommaDelimitedDataset&lt;Person&gt; ds = new CommaDelimitedDataset&lt;Person&gt;(provider);
	ds.setMaxRows(5);
	for (Person p : ds) {
		System.out.println(p);
	}
}
</pre>
</li>
<li>You can see this process in action by extending the comma delimited data provider as an anonymous class and adding logging to the post fetch methods. We do this by modifying the <code>ProviderFactory.createProvider()</code> method :
<pre class="brush: java;">
public static CommaDelimitedProvider&lt;Person&gt; createProvider() {
	URL url = Main.class.getResource(&quot;data.csv&quot;);
	CommaDelimitedProvider&lt;Person&gt; provider = new CommaDelimitedProvider&lt;Person&gt;(url.getFile()) {
		@Override
		protected List&lt;Person&gt; doPostFetchResults(List&lt;Person&gt; results,
				Paginator paginator) {
			int end = paginator.getFirstResult()+paginator.getMaxRows();
			System.out.println(&quot;Fetching results from &quot;+paginator.getFirstResult()+&quot; to &quot;+end);
			return results;
		}
	};
	provider.setRowMapper(new PersonRowMapper());
	return provider;
}
</pre>
</li>
<li>
If you run this now, with the max rows set to 5, in you will see in that log that we iterate through all the records, but we only fetch the results every 5 rows since the max results is set to 5.</p>
<pre class="brush: plain;">
Fetching results from 0 to 5
Person [id=6825, name=JUANITA LAMBERT, address=139 MANNING HWY,CLYO,76604, email=mbeasley@everyma1l.biz
Person [id=5740, name=GREG CABRERA, address=736 GENESSEE BLVD,CORDELE,17433, email=cholder@b1zmail.biz
Person [id=8599, name=ALISSA WISE, address=205 ALICE RD,CAMILLA,14855, email=theyweb@eyec0de.net
Person [id=9282, name=SHARON WINTERS, address=955 COHEN PIKE,TYRONE,811, email=jlogan@hotma1l.com
Person [id=2150, name=KRISTY FRANKS, address=1471 ALEXIS PKWY,BALDWIN,85, email=jgates3@somema1l.com
Fetching results from 5 to 10
Person [id=9927, name=JEFF RICE, address=104 DUNDEE PKWY,HOGANSVILLE,3741, email=diedlots@b1zmail.org
Person [id=7972, name=TAMARA BRYANT, address=1382 WOGAN BLVD,CITY OF CALHOUN,43790, email=hotworn@everyma1l.us
Person [id=5824, name=ALISHA YANG, address=716 HOGANS DR,HARDING,58932, email=foundwrong@hotma1l.net
Person [id=3402, name=JASON NGUYEN, address=527 MICHAEL CRES,FORT STEWART,14664, email=haveothers@ma1l2u.com
Person [id=3620, name=LINDSEY CABRERA, address=1420 LAZELERE HTS,FORT STEWART,21650, email=askeddreams@b1zmail.com
Fetching results from 10 to 15
Person [id=3511, name=ANTHONY MATHEWS, address=1325 OKEY LN,THUNDERBOLT,63656, email=cfarrell@everyma1l.co.uk
Person [id=572, name=JARED FORD, address=722 EUCLID RD,FORSYTH,42014, email=ortrying@b1zmail.co.uk
Person [id=9720, name=AUTUMN WILLIAMS, address=260 HILL PARK,NORCROSS,58355, email=roomwhere@hotma1l.net
Person [id=3447, name=MARION BROWN, address=739 MIDDLE PATH,MACON,9944, email=hwagner@b1zmail.co.uk
Person [id=9356, name=HOPE HAYNES, address=1023 COOPERRIDERS CRES,STATENVILLE,34247, email=sacrificeit@eyec0de.com
Fetching results from 15 to 20
Person [id=2259, name=JEANNIE RANDOLPH, address=672 EDISON PATH,CENTERVILLE,48580, email=wornto@eyec0de.net
Person [id=8264, name=RACHAEL CONLEY, address=1223 STEVENS CT,CARROLLTON,40084, email=smokewhite20@eyec0de.net
</pre>
</li>
</ol>
<h2>Creating a Swing Client</h2>
<p>DataValve provides an interface for data access that can be used by different clients. Lets look at using our provider with a Swing <code>JTable</code>.</p>
<ol>
<li>Start by creating a new class that will be the Swing frame that contains the table and the scroll pane.
<pre class="brush: java;">
public class CsvTableFrame extends JFrame {

	private JTable table;
	private JScrollPane pane;

	public CsvTableFrame(CommaDelimitedProvider&lt;Person&gt; provider) {
		initControls();
		initModel(provider);
	}

        //here we will create the table model and attach the provider
	private void initModel(CommaDelimitedProvider&lt;Person&gt; provider) {
	}

        //construct the gui table and scrollable panel
 	private void initControls() {
		setTitle(&quot;CSV Data&quot;);
		setSize(400, 400);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);

		table = new JTable();
		pane = new JScrollPane(table);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		getContentPane().add(pane);
	}
}
</pre>
<p>This will setup the display for showing a frame with a scrollable table in it.
</li>
<li>Now we need to implement the <code>initModel</code> method which will create a <code>ProviderTableModel</code> and attach the provider passed in. The table model class enables us to present our data to the Swing table in a way it understands. The <code>ProviderTableModel</code> implements a method which supplies column values to the model from the data supplied by the provider. The columns are defined in the latter half of the method and determines the order used to supply data to the table for each column.
<pre class="brush: java;">
        //here we will create the table model and attach the provider
	private void initModel(CommaDelimitedProvider&lt;Person&gt; provider) {
		ProviderTableModel&lt;Person&gt; model = new ProviderTableModel&lt;Person&gt;(
				provider) {

			@Override
			protected Object getColumnValue(Person person, int column) {
				switch (column) {
				case 0:
					return person.getId();
				case 1:
					return person.getName();
				case 2:
					return person.getEmail();
				case 3:
					return person.getAddressText();
				default:
					throw new RuntimeException(
							&quot;Unexpected column for person object &quot; + column);
				}
			}
		};

		//add the columns to the model
		model.addColumn(&quot;Id&quot;);
		model.addColumn(&quot;Name&quot;);
		model.addColumn(&quot;Email&quot;);
		model.addColumn(&quot;Address&quot;);

		//assign this model to the table
		table.setModel(model);
	}
</pre>
</li>
<li>The last piece we need to change is in the <code>main</code> method where we will create our provider and then pass it into the creation of our Swing frame.
<pre class="brush: java;">
public static void main(String[] args) {

	CommaDelimitedProvider&lt;Person&gt; provider;

	provider = ProviderFactory.createProvider();

	new CsvTableFrame(provider);

}
</pre>
<p>Creating the <code>CsvTableFrame</code> initializes and shows the Swing window.
</li>
<li>If we run this now, we will get a Swing Window which contains a table with our data in it.
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/csv_swing_table.png" target="_blank"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/csv_swing_table-300x163.png" alt="CSV Swing Table DataValve" title="CSV Swing Table DataValve" width="300" height="163" border=0/></a>
</div>
</li>
</ol>
<p>The model controls the flow of the data and even includes built-in caching and look-ahead loading so no matter how big your CSV dataset is, there is no long delay while the data is loaded and converted to Java objects.  In this case, we pass only the provider to the model and the model is responsible for how much data is fetched in each batch. </p>
<p>If you look in the log as you scroll down the list, you will see that it is loading in the data as you scroll. If you go to the end of the list, and start slowly scrolling back up, you won&#8217;t see any more loading messages until you get to the top of the list. This is because the values are cached, but if you have a large dataset, the least recently used items (i.e. those at the top of the table) are removed from the cache and therefore need re-loading when you go back to the start of the list. </p>
<h1>Creating a JSF Client</h1>
<p>The DataValve API allows us to re-use providers with many different clients which we&#8217;ll demonstrate with JSF. </p>
<ol>
<li>Start by creating a new JSF web application, or use the <a href="http://www.andygibson.net/blog/projects/knappsack">Knappsack Archetypes</a> for Maven to get started quickly. Use the basic archetype so there is no existing application in there or alternative <code>Person</code> objects to clash with.</li>
<li>Add the <code>datavalve-dataset</code> API and the <code>datavalve-faces</code> dependencies to the project,
<pre class="brush: xml;">
		&lt;dependency&gt;
			&lt;groupId&gt;org.fluttercode.datavalve&lt;/groupId&gt;
			&lt;artifactId&gt;datavalve-dataset&lt;/artifactId&gt;
			&lt;version&gt;0.9.0.CR2&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.fluttercode.datavalve&lt;/groupId&gt;
			&lt;artifactId&gt;datavalve-faces&lt;/artifactId&gt;
			&lt;version&gt;0.9.0.CR2&lt;/version&gt;
		&lt;/dependency&gt;
</pre>
</li>
<li>For convenience, copy the <code>ProviderFactory.java</code>,<code>Person.java</code> and <code>PersonRowMapper.java</code> classes over to the new project.
</li>
<li>Create a new class called that will be our backing bean that will hold the dataset the JSF page will go against.
<pre class="brush: java;">
@Named(&quot;csvDataset&quot;)
@RequestScoped
public class CsvDatasetBean {

	CommaDelimitedDataset&lt;Person&gt; dataset =
	     new CommaDelimitedDataset&lt;Person&gt;(ProviderFactory.createProvider());

	public CsvDatasetBean() {
		//initialize the dataset settings
		dataset.setMaxRows(10);
	}

	public CommaDelimitedDataset&lt;Person&gt; getDataset() {
		return dataset;
	}
}
</pre>
</li>
<li>Now we have created the backing bean pieces, open <code>home.xhtml</code> to edit it, and replace the hello world text with the following :
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
	xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
	xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
	xmlns:dv=&quot;http://java.sun.com/jsf/composite/datavalve&quot;
	template=&quot;/WEB-INF/templates/template.xhtml&quot;&gt;
	&lt;ui:define name=&quot;content&quot;&gt;
		&lt;h:dataTable value=&quot;#{csvDataset.dataset.resultList}&quot; var=&quot;v_person&quot;&gt;
			&lt;h:column&gt;
				&lt;f:facet name=&quot;header&quot;&gt;ID&lt;/f:facet&gt;
				&lt;h:outputText value=&quot;#{v_person.id}&quot; /&gt;
			&lt;/h:column&gt;

			&lt;h:column&gt;
				&lt;f:facet name=&quot;header&quot;&gt;Name&lt;/f:facet&gt;
				&lt;h:outputText value=&quot;#{v_person.name}&quot; /&gt;
			&lt;/h:column&gt;

			&lt;h:column&gt;
				&lt;f:facet name=&quot;header&quot;&gt;Email&lt;/f:facet&gt;
				&lt;h:outputText value=&quot;#{v_person.email}&quot; /&gt;
			&lt;/h:column&gt;

		&lt;/h:dataTable&gt;
		&lt;h:form&gt;
			&lt;dv:simplePaginator paginator=&quot;#{csvDataset.dataset}&quot; /&gt;
		&lt;/h:form&gt;
	&lt;/ui:define&gt;
&lt;/ui:composition&gt;
</pre>
<p>This page contains a table that takes the results from <code>#{csvDataset.dataset.resultList}</code> and displays the id, name and email fields. The last item wrapped in a form is the <code>datavalve-faces</code> default paginator which allows to you scroll across the data. This is provided as part of <code>datavalve-faces</code> and the namespace is added at the top of the page.  With JSF 2.0 including support for AJAX, you can have AJAX enabled pagination by setting the attributes on the component.</p>
<div class="contentBox alignCenter">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/csv_jsf_table.png" target="_blank"><img border=0 src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/csv_jsf_table-300x181.png" alt="CSV JSF Table DataValve" title="CSV JSF Table DataValve" width="300" height="181" border=0 /></a>
</div>
</li>
</ol>
<h2>Summary</h2>
<p>This tutorial has shown how to consume csv files in a way that is re-usable across different client applications using DataValve. Alternatively, if you change the implementation of <code>ProviderFactory.createProvider</code> to return a different type of provider (i.e. JDBC, ORM, Hibernate) as long is it returns the same kind of <code>Person</code> object, your code will run unchanged in the clients you create. Given the simplicity of the DataValve interfaces, it is not hard to see how easy it is to create providers for other file types whether they be text or binary based.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/accessing-and-paginating-csv-files-with-datavalve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing User Selectable Themes In JSF</title>
		<link>http://www.andygibson.net/blog/tutorial/implementing-user-selectable-themes-in-jsf/</link>
		<comments>http://www.andygibson.net/blog/tutorial/implementing-user-selectable-themes-in-jsf/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 16:44:36 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Journeyman]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1116</guid>
		<description><![CDATA[

Prerequisites
Install Maven
Install the Knappsack Archetypes


Many web applications offer users the option to change the appearance of user interface. One of the easiest ways to implement this is by offering different page color schemes by selecting different css style sheets. This article describes how to implement themes in JSF using CDI backing beans that the user [...]]]></description>
			<content:encoded><![CDATA[<div class="prereq floatRight" >
<ul>
<lh>Prerequisites</lh></p>
<li>Install Maven</li>
<li><a href="http://www.andygibson.net/tutorial/installing-the-knappsack-archetypes/">Install the Knappsack Archetypes</a></li>
</ul>
</div>
<p>Many web applications offer users the option to change the appearance of user interface. One of the easiest ways to implement this is by offering different page color schemes by selecting different css style sheets. This article describes how to implement themes in JSF using CDI backing beans that the user can select as their default theme.<br />
<span id="more-1116"></span><br />
<a href='http://www.andygibson.net/blog/wp-content/uploads/2010/07/jsfthemes.zip'>Download project source</a><br/><br />
Each style sheet implements a different color scheme and when they user picks a theme, you simply have to provide the style sheet assigned to that theme. The application will be based on an existing archetype, so we&#8217;ll start by creating a new Maven application using the <code>jee6-sandbox-demo-archetype</code>. </p>
<p>As it is, the application has a stylesheet called <code>screen.css</code> which includes color information for the pages. We want to add another style sheet that overrides those color choices for the elements that we want to change per theme. </p>
<p>Of course, we could change much more css than the colors in the theme style sheet, we could change the layout and sizing information also, but the tradeoff is that the more content we put into the theme stylesheet, the more content we have to duplicate in each theme, and the more we have to change each time there is a minor change. We could resolve this problem by giving the user two different theming option, the first would select the layout stylesheet and the other would select the color stylesheet.</p>
<ol>
<li>In the package explorer locate the <code>bean</code> package and right click on the package folder.</li>
<li>Select <i>New->Class</i> and in the class dialog, enter <code>StyleBean</code> as the name of the class<br />
<img src="img"/><br />
This bean will hold the value of the current theme name and return the style sheet name to our view. It will also hold the list of available style sheets.
</li>
<li>We&#8217;ll start by annotating the bean with the <code>@Named</code> annotation so we can reference it from our JSF view pages and make the bean <code>@SessionScoped</code> so it will remember the settings between each request. </li>
<li>Since our bean is session scoped, it needs to be passivation capable which means adding the <code>Serializable</code> interface to the implements clause.</li>
<li>We add fields for the currently selected theme, and also a theme map which will contain the name of the themes and the stylesheet associated with it. Getters and setters for the <code>theme</code> have been omitted.</li>
<pre class="brush: java;">
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;

@Named(&quot;styleBean&quot;)
@SessionScoped
public class StyleBean implements Serializable {

	private String theme;

	private Map&lt;String, String&gt; themeMap;

	public StyleBean() {
		themeMap = new LinkedHashMap&lt;String, String&gt;();
		// read this list from the db or something
		themeMap.put(&quot;Default&quot;, &quot;default.css&quot;);
		themeMap.put(&quot;Blue&quot;, &quot;blue.css&quot;);
		themeMap.put(&quot;Green&quot;, &quot;green.css&quot;);
	}

}
</pre>
<li>Because JSF cannot iterate over a <code>Map</code> or <code>Set</code> we need to convert the list of theme names into a <code>List</code>. We do this with another method that we annotate with the <code>@Produces</code> method to indicate that this produces values. We give it the name <code>themes</code> and make it application scoped so this will be produced only once per application.
<pre class="brush: java;">

	@Produces
	@Named(&quot;themes&quot;)
	@ApplicationScoped
	public List&lt;String&gt; getThemes() {
		return new ArrayList&lt;String&gt;(themeMap.keySet());
	}
</pre>
</li>
<li>We have one more method to implement and that is the method that returns the name of the CSS stylesheet for the selected theme. We do this by using our theme <code>Map</code> as a lookup to get the filename</li>
<pre class="brush: java;">

	public String getThemeCss() {
		return themeMap.get(getTheme());
	}
</pre>
<p>If you get an error at this point you forgot to put in the getter/setters for the theme field. </p>
</ol>
<p>Now we have put all our code together in one bean, given that bean a name so it can be referenced from JSF, and implemented the list of themes and converting themes to a CSS file name. It&#8217;s time to implement our options page that lists the themes available and lets the user select one. </p>
<ol>
<li>Create a new JSF page called <code>options.xhtml</code> and paste in the following code :
<pre class="brush: xml; highlight: [12,13,14];">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
	xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
	xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
	xmlns:fc=&quot;http://java.sun.com/jsf/composite/fluttercode/component&quot;
	template=&quot;/WEB-INF/templates/template.xhtml&quot;&gt;
	&lt;ui:define name=&quot;content&quot;&gt;
		&lt;h:form&gt;
			&lt;fc:panel caption=&quot;Visual Options&quot;&gt;
				&lt;fc:property caption=&quot;Theme&quot;&gt;
					&lt;h:selectOneListbox value=&quot;#{styleBean.theme}&quot; style=&quot;width : 180px;height : 180px&quot;&gt;
						&lt;f:selectItems value=&quot;#{styleBean.themes}&quot; /&gt;
					&lt;/h:selectOneListbox&gt;
				&lt;/fc:property&gt;
				&lt;h:commandButton value=&quot;Update&quot;/&gt;
			&lt;/fc:panel&gt;

		&lt;/h:form&gt;

	&lt;/ui:define&gt;
&lt;/ui:composition&gt;
</pre>
<p>Most of this code is boilerplate so I&#8217;ve highlighted the relevant parts. The list box that is wrapped by the property component, takes the list of themes from our <code>themes</code> producer and is bound to the <code>theme</code> property of our <code>styleBean</code>. When the user selects an item and clicks the Update button the <code>theme</code> property is set to the name of the selected theme.Since this is stateful, the new value holds across page requests so next time the page is rendered we can look at the <code>themeCss</code> property to get the file name of the css file for the selected theme.</p>
<li>To render the css style sheet we need to add it to the style sheets in the header. Open up the <code>template.xhtml</code> file and locate the line with <code>&lt;h:outputStylesheet name="css/screen.css" /&gt;</code>. Underneath it, add a new line to include our user selected style sheet.
<pre class="brush: xml;">
&lt;h:outputStylesheet name=&quot;css/#{styleBean.themeCss}&quot; /&gt;
</pre>
</li>
<li>Now the only thing left is to create the additional stylesheets for our themes. In the <code>src/main/webapp/resources/css/</code> folder create a new stylesheet called <code>default.css</code> but leave it blank.</li>
<li>Create a new stylesheet called <code>blue.css</code> with the following content :
<pre class="brush: css;">

body {
	background-color: #E0E0FF;
	color: #102040;
}

#header {
	background: #204080;
	color: #f0f0fF;
}

.panel {
	border: 1px solid #D0D0F0;
	background: #f0f0ff;
}

.panel h1 {
	background: #e0e0f0;
	border-bottom: solid 1px #D0D0F0;
	color: #102040;
}

.odd {
	background: #f0f0fF;
}

.even {
	background: #f7f7ff;
}

.dataTable th {
	background: #204080;
	color: #f0f0ff;
}
</pre>
</li>
<li>Add one more stylesheet called <code>green.css</code> with the following content :
<pre class="brush: css;">
body {
	background-color: #E0FFE0;
	color: #104020;
}

#header {
	background: #208040;
	color: #f0fFF0;
}

.panel {
	border: 1px solid #D0F0D0;
	background: #f0fff0;
}

.panel h1 {
	background: #e0f0e0;
	border-bottom: solid 1px #D0F0D0;
	color: #104020;
}

.odd {
	background: #f0fFf0;
}

.even {
	background: #f7fFf7;
}

.dataTable th {
	background: #208040;
	color: #f0fff0;
}
</pre>
</li>
<p>If you deploy the application now and go to the <a href="http://localhost:8080/jsfthemes/options.jsf">http://localhost:8080/jsfthemes/options.jsf</a> you can pick a different theme,click update and the application will start rendering pages with the new themes.</p>
<h1>Extending the Implementation</h1>
<p>There are a number of ways we can improve this implementation, especially since we are keeping the list of styles and the selection information in a backing bean in the session. Chances are that the session already has some kind of User entity, and it would be a good idea to store the selected theme, or better yet, the name of the css file as part of the user profile. The list of themes is only needed when the user is on the options page and is only used to provide the list of themes and to convert from the theme name to the css file. It would be easy to re-implement these as request scoped elements once the state is moved to the user entity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/implementing-user-selectable-themes-in-jsf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing JBoss Developer Tools</title>
		<link>http://www.andygibson.net/blog/tutorial/installing-jboss-developer-tools/</link>
		<comments>http://www.andygibson.net/blog/tutorial/installing-jboss-developer-tools/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 01:55:01 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1126</guid>
		<description><![CDATA[This article describes how to install the JBoss Developer Tools plug-ins into the Eclipse IDE. You should already have Eclipse installed and configured.


Prerequisites
Installing and Configuring Eclipse


JBoss Developer Tools is a bundle of Eclipse plug-ins for Eclipse which help when developing applications using a various frameworks, some of which are JBoss specific and some which are [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes how to install the JBoss Developer Tools plug-ins into the Eclipse IDE. You should already have Eclipse installed and configured.<br />
<span id="more-1126"></span></p>
<div class="prereq">
<ul><lh>Prerequisites</lh></p>
<li><a href="http://www.andygibson.net/blog/tutorial/installing-and-configuring-eclipse/">Installing and Configuring Eclipse</a></li>
</ul>
</div>
<p>JBoss Developer Tools is a bundle of Eclipse plug-ins for Eclipse which help when developing applications using a various frameworks, some of which are JBoss specific and some which are standards based, but still JBoss related. In particular this helps developers get to grips with Java EE 6 web development using JSF, CDI, EJB and JPA by integrating the use of these individual frameworks in the IDE.</p>
<div class="sidenote_right">
<h1>64 Bit Windows</h1>
<p>Currently, JBoss Developer Tools does not support 64 bit JVMs on Windows. There is a version for 64 bit Linux, but not for 64 bit windows. Therefore you will need to install a 32-bit JDK to use them, and we will tell Eclipse to use that JDK instead (see [node:3] for more details). This also means you will be unable to use a 64-bit version of Eclipse.</p>
</div>
<p>For example, it provides tooling for the JPA standard and specifically the Hibernate implementation of JPA. Of most interest is the new Java Contexts and Dependency Injection (CDI , JSR 299) tooling which can go hand in hand with their excellent JSF page editing.</p>
<p>You should start with an Eclipse installation that will support JBoss Tools (see the <a href="http://www.jboss.org/tools/download.html">download page</a> for more details on which Eclipse versions are supported.</p>
<h2>Prerequisite Eclipse Plug-ins</h2>
<p>Before we install JBoss tools, there are a some additional plug-ins that need installing first as prerequisites as described in the JBoss Tools install <a href="http://download.jboss.org/jbosstools/updates/stable/galileo/" target="_blank">instructions</a>.  These plug-ins, as well as the JBoss Tools plug-ins themselves will be installed using the Eclipse update manager which is opened by opening the menu <em>Help-&gt;Install New Software&#8230;</em>.  This manager has a list of URLs that Eclipse can use to locate and download plug-ins from remote locations called update sites.</p>
<ol>
<li>Open the install manager by clicking the menu item  <em>Help-&gt;Install New Software&#8230;</em>.</li>
<li>In the install manager, click the <em>Add</em> button to add a new update site.</li>
<li>In the dialog that pops up, add BIRT as the  Name, and set Location to <a href="http://download.eclipse.org/birt/update-site/2.5/">http://download.eclipse.org/birt/update-site/2.5/</a>. Click OK to close the dialog.</li>
<li>Back in the install manager, in the top drop down box select the BIRT site and you should see a list of available plug-ins appear in the main list area</li>
<li>Click the check box next to each of the plug-ins and click <em>Next</em>.</li>
<li>Once you agree to the licenses and click <em>Finish</em> Eclipse will download and install the plug-ins. Once complete, it will ask if you want to restart Eclipse now or later. Restart Eclipse now before we install additional plug-ins.</li>
<li>Repeat the above steps for the Maven m2Eclipse plug-ins. In the &#8220;Add Site&#8221; dialog, set the Name to m2Eclipse and the Location to <a href="http://m2eclipse.sonatype.org/sites/m2e/">http://m2eclipse.sonatype.org/sites/m2e/</a>.</li>
<li>Once added, select the m2Eclipse site and check all the items in the plug-in list.</li>
<li>Once the m2Eclipse plug-ins are installed, opt to restart eclipse</li>
</ol>
<h2>Installing JBoss Tools</h2>
<p>Now we will install the plug-ins for Boss Tools, again using update sites as in the previous steps.</p>
<ol>
<li>Click <em>Help-&gt;Install New Software&#8230;</em> to open the install manager.</li>
<li>Add a new site called JBoss Tools. The Location for the site is <a href="http://download.jboss.org/jbosstools/updates/stable/galileo/">http://download.jboss.org/jbosstools/updates/stable/galileo/</a>. Click <em>OK</em>.</li>
<li>In the install manager, select the JBoss Tools site to download plug-ins from. You should see a long list of available plug-ins. Again, check them all and click <em>Next</em>.</li>
<li> Once it has calculated requirements and dependencies, you should be able to click <em>Next</em> again, and check the license agreement and click <em>Next</em>.</li>
<li>Finally, it will download and install the JBoss Tools plug-ins. This may take a while since the contents are in the region of just under 100 megabytes.</li>
<li>Again, once complete, you should restart Eclipse</li>
<li>You are done, you should now have a working installation of JBoss Developer Tools</li>
</ol>
<h2>Dependency Issues</h2>
<p>Eclipse can have problems with missing dependencies indicating that there are missing required plug-ins. In such a case, see what plug-ins are missing in the <em>Install Details</em> tab in the <em>Details</em> section.  Verify that you have downloaded the correct version of the Eclipse SDK as per the <a href="http://www.jboss.org/tools/download/">JBoss Tools instructions</a>. Also make sure you downloaded the Eclipse SDK version for Java EE. If you need to access older versions of the Eclipse SDK, you can do so from this <a href="http://download.eclipse.org/eclipse/downloads/">download page</a>. Try searching online for the error message to see if it is a common problem.</p>
<div class="notes">
<ul><lh> Next Steps</lh></p>
<li><a href="http://www.andygibson.net/blog/tutorial/installing-servers-into-eclipse/">Installing Servers Into Eclipse</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/installing-jboss-developer-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Servers into Eclipse</title>
		<link>http://www.andygibson.net/blog/tutorial/installing-servers-into-eclipse/</link>
		<comments>http://www.andygibson.net/blog/tutorial/installing-servers-into-eclipse/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 01:53:12 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1129</guid>
		<description><![CDATA[
Prerequisites
Installing and configuring Eclipse
Download and install a web server

JBoss Application Server
Tomcat




If you want to do some web development with Eclipse, you will need a web server for it to run on. The process for adding a server to Eclipse is usually the same for different server vendors. Typically though each vendor has different configuration options [...]]]></description>
			<content:encoded><![CDATA[<div class="prereq" style="float: right;">
<ul><lh>Prerequisites</lh></p>
<li><a href="http://www.andygibson.net/blog/tutorial/installing-and-configuring-eclipse/">Installing and configuring Eclipse</a></li>
<li>Download and install a web server
<ul>
<li><a href="http://www.jboss.org/jbossas/downloads.html">JBoss Application Server</a></li>
<li><a href="http://tomcat.apache.org/">Tomcat</a></li>
</ul>
</li>
</ul>
</div>
<p>If you want to do some web development with Eclipse, you will need a web server for it to run on. The process for adding a server to Eclipse is usually the same for different server vendors. Typically though each vendor has different configuration options for setting up the server. For now, we&#8217;ll look at adding the server into the Eclipse environment.<br />
<span id="more-1129"></span></p>
<h1>Adding Servers</h1>
<p>Servers are added by letting Eclipse know what type of server you want to install and where it is installed locally. You must have already downloaded and installed a web server before adding it into the Eclipse environment.</p>
<div class="diagram alignCenter contentBox">
<img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/server_views.png" alt="Server Views in Eclipse" title="Server Views" width="311" height="438"  />
</div>
<ol>
<li>Select <em>Window-&gt;Show-&gt;Other&#8230;</em> to bring up the view selector.</li>
<li>Start typing <strong>server</strong> and you will see the view list is filtered.</li>
<li>We want the <em>Servers</em> view, <strong>not</strong> the <em>JBoss Server View</em>, that is now deprecated.</li>
<li>Double click on the <em>Servers</em> item and the view selector will close and the Servers tab will open up in the bottom half of the IDE window.</li>
<li>In the Servers window, right click and select <em>New-&gt;Server</em> to bring up the New Server dialog</li>
<div class="diagram alignCenter contentBox">
<a href="http://www.andygibson.net/blog/wp-content/uploads/2010/07/runtime_list1.png"><img src="http://www.andygibson.net/blog/wp-content/uploads/2010/07/runtime_list1-272x300.png" alt="List of runtimes installed in Eclipse" title="Runtime List" width="272" height="300" /></a>
</div>
<li>Select the appropriate server runtime for the server you are using from the list. If your server doesn&#8217;t appear in the list then click the  &#8220;Download additional server adapters&#8221; link above the list.
<ol> Adding a new server adapater</p>
<li> In the Install New Extension dialog, wait for it to finish downloading the list of available server adapters and try and find the right one for your server.</li>
<li>Once found, select your server and click <em>Next</em>, agree to any license terms and click <em>Finish</em> to install the adapter.</li>
<li>Once installed, you should restart Eclipse when asked. Upon restarting, you will need to go back to step 5 of this process except this time, your server should appear in the initial list.</li>
</ol>
</li>
<li>When you have found your server type in the list of servers, click <em>Next</em> and fill in any required details. This should mostly be about telling Eclipse in which directory the server installation is located and click <em>Next</em>. For most servers it will let you know if you are pointing it to the wrong directory or it cannot find the installed server in that directory.</li>
<li>The Add and Remove tab lets you add existing projects in the workspace to the new server. Unless you have any open projects, you don&#8217;t need to worry about this right now.</li>
<li>When you click finish, your new server should appear in the Servers panel. Click on it, expand it and right click on it, and you can see there are options for starting, stopping  and restarting the servers. When you add projects to the server, you will be able to select them for republishing.</li>
</ol>
<p>With a server installed, you can develop web applications using Eclipse and it will deploy the application for you when needed. This is if you downloaded the version of Eclipse for Java EE developers. If you download and install the m2Eclipse plugins you will be able to develop and deploy Maven web projects in Eclipse with the same benefits.</p>
<div class="notes">
<ul><lh>See Also</lh></p>
<li><a href="http://www.andygibson.net/blog/tutorial/installing-jboss-developer-tools/">Installing JBoss Developer Tools</a></li>
<li style="display:none"><a href="http://www.andygibson.net/2010/05/23/fluttercode-java-ee-6-application-archetypes">Fluttercode Java EE 6 Application Archetypes</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/installing-servers-into-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing libraries into Maven from source</title>
		<link>http://www.andygibson.net/blog/tutorial/installing-libraries-into-maven-from-source/</link>
		<comments>http://www.andygibson.net/blog/tutorial/installing-libraries-into-maven-from-source/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:18:39 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1119</guid>
		<description><![CDATA[This article describes how to install artifacts into Maven from the source code. To start with you should have installed Maven and downloaded the source code you want to install.  This same mechanism can be used for library jar files to archetypes that you want to install.

Open a command prompt and navigate to the [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes how to install artifacts into Maven from the source code. To start with you should have installed Maven and downloaded the source code you want to install.  This same mechanism can be used for library jar files to archetypes that you want to install.<span id="more-1119"></span></p>
<ol>
<li>Open a command prompt and navigate to the directory where the Maven source code is. This is usually indicated by the presence of a <code>pom.xml</code> file in that directory.
<pre class="brush: plain;">

&gt; cd dev\projects\myproject
</pre>
</li>
<li>Once in the maven project folder, there are a number of different commands you can use to install the project depending on what you need. The simplest form will compile, test, and install the artifacts into Maven.
<pre class="brush: plain;">

&gt;mvn install
</pre>
</li>
</ol>
<p>In some cases, you want to install the source and java doc files as well as the main jar file. This can be done by adding it onto the command line.</p>
<pre class="brush: plain;">

&gt;mvn javadoc:jar source:jar install
</pre>
<p>There may be times you want to make sure your build is completely clean before you start.  You can do this by adding the <code>clean</code> target onto the command. This deletes any current compiled sources so they will be regenerated from scratch. </p>
<pre class="brush: plain;">

&gt;mvn clean javadoc:jar source:jar install
</pre>
<p>While we added it at the start of the command, you don&#8217;t need to, you can put it at the end and it will still be executed first.</p>
<h2>Skipping Tests</h2>
<p>If you need to skip tests, you can do so by setting a command line parameter on the command line depending on how you want to skip the tests. While skipping tests is not advised, there are many cases where you might need to do so.</p>
<pre class="brush: plain;">
-Dmaven.test.skip=true
</pre>
<p>This will skip the compilation and execution of the tests.</p>
<pre class="brush: plain;">
-DskipTests=true
</pre>
<p>This will compile the tests, but skip the execution of them.</p>
<p>See <a href="http://maven.apache.org/plugins/maven-surefire-plugin/examples/skipping-test.html"> here</a> for more information on controlling test skipping in the <code>pom.xml</code> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/installing-libraries-into-maven-from-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install DataValve into Maven</title>
		<link>http://www.andygibson.net/blog/tutorial/install-datavalve-into-maven/</link>
		<comments>http://www.andygibson.net/blog/tutorial/install-datavalve-into-maven/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:16:56 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[DataValve]]></category>
		<category><![CDATA[Maven]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1122</guid>
		<description><![CDATA[This tutorial will show you how to install DataValve into your local Maven repository. You should already have Maven installed locally on your machine into which we will be installing the DataValve libraries.


Prerequisites
Install Maven



First, download the DataValve framework and unzip it into a temporary folder of your choice.
Open a command prompt and change directory to [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to install DataValve into your local Maven repository. You should already have Maven installed locally on your machine into which we will be installing the DataValve libraries.<br />
<span id="more-1122"></span></p>
<div class="prereq">
<ul><lh>Prerequisites</lh></p>
<li>Install Maven</li>
</ul>
</div>
<ol>
<li>First, <a href="http://kenai.com/projects/datavalve/downloads">download</a> the DataValve framework and unzip it into a temporary folder of your choice.</li>
<li>Open a command prompt and change directory to the <code>&lt;install-dir&gt;\modules\</code> folder</li>
<li>in the modules folder, type the command :
<pre class="brush: plain;">
mvn clean javadoc:jar source:jar install
</pre>
</li>
<li>This will compile the code, source and javadocs and install them into the local maven repository for use in your local maven applications.</li>
</ol>
<p>Once installed, to use DataValve in a Maven project you will need to add the necessary DataValvel modules as dependencies :</p>
<pre class="brush: xml;">
		&lt;dependency&gt;
			&lt;groupId&gt;org.fluttercode.datavalve&lt;/groupId&gt;
			&lt;artifactId&gt;datavalve-dataset&lt;/artifactId&gt;
			&lt;version&gt;0.9.0.CR2&lt;/version&gt;
		&lt;/dependency&gt;
</pre>
<p>Typically, adding the <code>datavalve-dataset</code> artifact pulls in the core module also. From there, you just need to add modules that your development environment will be dependent on (Wicket, JSF, Swing etc).</p>
<div class="notes">
<ul>
<lh>See Also :</lh></p>
<li><a href="http://www.andygibson.net/blog/tutorials/installing-libraries-into-maven-from-source">Installing libraries into Maven from source</a></li>
<li><a href="http://www.andygibson.net/blog/projects/datavalve/">DataValve project page</a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/install-datavalve-into-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating Weld in Glassfish V3</title>
		<link>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/</link>
		<comments>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:08:40 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[QuickBytes]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Glassfish]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1146</guid>
		<description><![CDATA[(updated : This post refers to Glassfish installations prior to version 3.0.1 which was recently released and includes Weld version 3.0.1. Given the new version, this manual update is not necessary and should not be performed if you have an updated installation of Glassfish 3.0.1+)
Even some of the recent versions of Glassfish include a version [...]]]></description>
			<content:encoded><![CDATA[<p>(<b>updated</b> : This post refers to Glassfish installations prior to version 3.0.1 which was recently released and includes Weld version 3.0.1. Given the new version, this manual update is not necessary and should not be performed if you have an updated installation of Glassfish 3.0.1+)</p>
<p>Even some of the recent versions of Glassfish include a version of Weld, the reference implementation for CDI (JSR 299), that has some major issues. Since Glassfish uses OSGI, upgrading isn&#8217;t as easy as just replacing the jar with a new one. This tutorial shows you how to upgrade Glassfish to Weld 1.0.1.Final as well as including a pre-built distribution of the two files that need re-deploying.</p>
<p>One of the ways to get around the faulty version of Weld currently in Glassfish is to moving up to Glassfish 3.0.1 nightly builds (<b>update</b> : 3.0.1 has been released and should be used) . A less bleeding edge solution would be to upgrade the version of Weld that is deployed on your current version of Glassfish by updating the <code>weld-integration</code> and <code>weld-osgi-bundle</code> jar files. However, one must be careful of the integration jar version as one of the major interfaces changed after the initial release of Weld introducing incompatibilities.</p>
<p>Updating the OSGI bundle is easy since it can be built from the Weld source code. Just download and compile it and locate the osgi-bundle.jar file.</p>
<p>We also need to grab a new version of the <code>weld-integration.jar</code> file.  There are all sorts of <a href="http://download.java.net/maven/glassfish/org/glassfish/web/weld-integration/">versions</a> of this file, but the one I found working for Weld 1.0.1.final was <a href="http://download.java.net/maven/glassfish/org/glassfish/web/weld-integration/3.0.1-b11/">version 3.0.1-b11/</a>. </p>
<p>I&#8217;ve already built the osgi-bundle and grabbed the integration jar and verified that they work so I&#8217;ve renamed and zipped them so you can just <a href='http://www.andygibson.net/blog/wp-content/uploads/2010/07/Weld-glassfish.zip'>download</a> and unzip them into the <code>modules</code> directory of your Glassfish v3 installation.</p>
<p>This is also a necessary step to get the <a href="http://www.andygibson.net/projects/knappsack">Knappsack Java EE 6 demo project</a> working under Glassfish. You can find more details on the <a href="http://www.andygibson.net/projects/knappsack/deploying-knappsack-projects">server compatability page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/quickbyte/updating-weld-in-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing DataValve</title>
		<link>http://www.andygibson.net/blog/article/introducing-datavalve/</link>
		<comments>http://www.andygibson.net/blog/article/introducing-datavalve/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 14:05:07 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Apprent]]></category>
		<category><![CDATA[DataValve]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1105</guid>
		<description><![CDATA[DataValve is a free open source library that facilitates the creation of re-usable view and data access components as well as providing a number of features for pagination, sorting and parameterizing queries. This article defines the problems DataValve aims to solve and how it solves them.

The need for DataValve
Most data driven applications have a need [...]]]></description>
			<content:encoded><![CDATA[<p>DataValve is a free open source library that facilitates the creation of re-usable view and data access components as well as providing a number of features for pagination, sorting and parameterizing queries. This article defines the problems DataValve aims to solve and how it solves them.<br />
<span id="more-1105"></span></p>
<h1>The need for DataValve</h1>
<p>Most data driven applications have a need for displaying data that is organized into pages. Whether it is search results or sales reports, dumping a complete set of data results into a web page or a Swing grid is sooner or later going to run into problems as the datasets grow larger. </p>
<p>Visual web frameworks such as Wicket or JSF usually have some components that facilitate pagination and most data access frameworks such as JDBC, Hibernate or JPA have facilities to access results in a paginated manner. Typically however, you need to write your own code to bridge the gap between the view and the data access mechanism.  If you write your own glue code you will probably need to re-write it again and again if you want to re-use the back end code with a different view layer or change the data access mechanism.</p>
<div class="diagram" style="width : 540px">
<h1>Applications With DataValve</h1>
<p><img src="/img/apps_with_dv.png"/>
</div>
<h2>Exotic Data Sources</h2>
<p>There may even be times when you have a sudden request to provide paginated data access to more exotic data sources such as XML, CSV, and binary files, even pulling data from a web service. In such a scenario not only do you have to write most of the pagination yourself, but again, your view layer will need some work to handle the new data access mechanism.  This also includes paginated access to in-memory data that is regularly used, but changes rarely and is cached in memory. </p>
<p>Most of you are probably thinking that this isn&#8217;t a big problem because you write layered code with an interface that can have different implementations. You are right, logical organization of code can help with all these problems, however, at the end of the day, you still have to write something that integrates with the new datasource in the same way as the old datasource in the implementation.</p>
<p>If you are thinking that you will never need to change your view layer or data providers, there are still some problems you might want to consider that DataValve can help with.</p>
<h2>Dynamic Querying</h2>
<p>One common feature in data driven applications is to query a set of data using parameters with the ability to exclude query clauses where the parameter is not set. If you are searching for people, why filter by address if the user didn&#8217;t enter an address? The solutions to get around this problem involve either building the query at run time and ignoring restrictions with missing parameter values or accommodating the potentially null parameter in the query itself which makes it look ugly and can harm performance.</p>
<h2>Ordering data safely</h2>
<p>Another problem is the abstraction of the ordering of data, especially with web applications. You don&#8217;t want to store the actual SQL columns used for sorting data on the web page in case of SQL injection attacks. The best way is to use a key that maps to how you want the data ordered . You would also have to allow for ascending and descending ordering. </p>
<h2>Parameterizing queries</h2>
<p>Dynamic queries should be parameterized to allow variables in the query to be set in a safe manner as opposed to changing the query text which can again lead to SQL injection attacks. Typically though most parameters have to be set manually and many times we add new parameters and forget to set them. The process of adding and assigning parameters can require lengthy boilerplate code. DataValve offers vastly improved parameter handling for queries.</p>
<h1>How DataValve solves all these problems</h1>
<p>DataValve works by using a well defined interface to access and paginate data that comes from a data provider. There are different data providers for each kind of data source (JDBC,ORM,Hibernate,File based) and you can even write your own using an interface with just 2 methods. Because we have a well defined interface to the data, we can create components for the view to connect to that interface. Since we are coupled to the interface only, we can change the implementation and as long as it returns the same kind of entity objects, our view code remains unchanged. The view doesn&#8217;t care whether the list of <code>Person</code> entities comes from a database, an XML file, a web service or an in-memory list. When the dataset is connected up to a different view layer, it is coupled to the same interface and accesses the data in the same defined way.</p>
<p>Here&#8217;s a quick example of how we create a data provider and paginate the results. </p>
<pre class="brush: java;">
DataProvider&lt;Person&gt; provider = new SomeDataProvider&lt;Person&gt;();
Paginator paginator = new DefaultPaginator();
paginator.setMaxRows(10);
pagiantor.setFirstResult(15);
List&lt;Person&gt; results = provider.fetchResults(paginator);
for (Person p : results) {
  //do something with the 10 Person objects from 15-25
}
</pre>
<p>We can also use a <code>Dataset</code> that is a stateful combination of a <code>Paginator</code> and a data provider reference.</p>
<pre class="brush: java;">
DataProvider&lt;Person&gt; provider = new SomeDataProvider&lt;Person&gt;();
ObjectDataset&lt;Person&gt; dataset = new DataProviderDataset(provider);
dataset.setMaxRows(10);
dataset.setFirstResult(35);
List&lt;Person&gt; results = dataset.getResults();
for (Person p : results) {
...some code...
}
</pre>
<p>Each time we call <code>getResults()</code> on the dataset, it will return the same list of results until we move to another page of results or manually invalidate the result set. Every time you call <code>fetchResults</code> on a data provider the list of results is re-fetched each time.  The Dataset also implements the iterator interface so you could iterate over the whole set of data and it would go through each row, but load them in batches as sized by the paginator. </p>
<h1>Queried Results</h1>
<p>Let&#8217;s load a result set that uses some filtering and sorting. </p>
<pre class="brush: java;">
QueryProvider&lt;Person&gt; provider = new JpaDataProvider&lt;Person&gt;(em);
QueryDataset&lt;Person&gt; dataset = new QueryDataset&lt;Person&gt;(provider);

provider.setSelectStatement(&quot;select p from Person p&quot;);
provider.setCountStatement(&quot;select count(p) from Person p&quot;);

//we can also access the provider using
// dataset.getProvider()

//add simple restriction
provider.addRestriction(&quot;p.department.id = 4&quot;);

List&lt;Person&gt; results = dataset.getResultList();
for (Person p : results) {
    System.out.println(p.getName());
}
</pre>
<p>Alternatively, we could specify the parameters using : </p>
<pre class="brush: java;">
//:param is a magic value for this method call only
provider.addRestriction(&quot;p.firstName = :param&quot;,someFirstName);

//alternatively

provider.addRestriction(&quot;p.firstName = :aFirstName&quot;);
provider.addParameter(&quot;aFirstName&quot;,someFirstName);
</pre>
<p>A few things to note here. The second method of using a parameter requires two method calls, but you can change the parameter value later on prior to execution and if <code>aFirstName</code> is null, then the restriction won&#8217;t be included in the executed final query. Typically, restrictions are excluded at the time of query execution, but if you use the first syntax, the restriction is left out immediately if the value is null since you are setting the parameter as a constant and if the value is null, then it will always be null.</p>
<p>Here are some alternative ways of defining parameters, all of which are subject to the rule that if the parameter is null, then the restriction isn&#8217;t added. All these examples can be used with either Hibernate, JPA or JDBC data providers with the only changes being the query specification and the field names in the restrictions. </p>
<pre class="brush: java;">
  //WRONG - if first name is null, then the param value is 'null%' and will be added
  provider.addRestriction(&quot;p.firstName like :param&quot;,criteria.firstName+&quot;%&quot;);

  //CORRECT - this checks one value, but assigns another to the actual parameter
  provider.addRestriction(&quot;p.firstName like :param&quot;,criteria.firstName,criteria.firstName+&quot;%&quot;);
</pre>
<p>This is really useful where we want to use one value for the null check, but assign another value to the actual parameter so we can use &#8217;starts-with&#8217; in searches by adding a wildcard on the end.</p>
<pre class="brush: java;">
  provider.addRestriction(&quot;p.department.id = 4&quot;);
  provider.addRestriction(&quot;or p.managerFlag = 1&quot;);
</pre>
<p>All restrictions are joined together with &#8220;AND&#8221;s unless they actually start with a logical operator. Parenthesis can be introduced into the query, but care must be taken that opening or closing parentheses would not be removed in the event of a null parameter.</p>
<p>If you are using JSF or some other EL enabled environment, you can also use EL expressions directly in the queries as long as you attach an <code>ELParameterResolver</code> to the provider.</p>
<pre class="brush: java;">
  provider.addRestriction(&quot;p.firstName = #{criteria.firstName}&quot;);
  provider.addRestriction(&quot;p.lastName = #{criteria.lastName}&quot;);
</pre>
<p>Again, if these expressions evaluate to null then the restriction is not used. This makes it really easy to create a search criteria bean that hooks up to the JSF front end and back end without any additional glue code. </p>
<h2>Parameter Resolvers</h2>
<p>DataValve has a concept of parameter resolvers that can be used on any data provider that implements the <code>ParameterizedDataset</code> interface. Parameter resolvers are like plugins that provide parameter resolution through code. The <code>ReflectionParameterResolver</code> uses reflection to find parameter values where the property name is the same as the parameter name.</p>
<pre class="brush: java;">
provider.addRestriction(&quot;p.firstName like :firstName&quot;);
provider.addRestriction(&quot;p.lastName like :lastName&quot;);
provider.addParameterResolver(new ReflectionParameterResolver(criteria));
</pre>
<p>Our <code>criteria</code> object has first and last name properties that are used to resolve the parameter values in the restrictions. Again, if the values resolve to null, the restriction is not used when the query is executed. </p>
<p>Also, multiple parameter resolvers can be attached to a provider so you could use an EL parameter resolver and a reflection parameter resolver. This can be useful for mixing it up if you have multiple sources for parameters. You can also combine different combinations of adding restrictions.</p>
<pre class="brush: java;">
provider.addRestriction(&quot;p.firstName like :firstName&quot;);
provider.addRestriction(&quot;p.lastName like :lastName&quot;);
provider.addRestriction(&quot;p.salesRep.id = #{currentUser.id}&quot;);
provider.addRestriction(&quot;p.dept.id = &quot;,selectedDepartment.getId());
provider.addParameterResolver(new ReflectionParameterResolver(criteria));
provider.addParameterResolver(new ElParameterResolver());
</pre>
<h1>Ordering Results</h1>
<p>Configuring the order is simple, we add the order key values and associate information with each key to indicates how the ordering is executed which in most cases, it is the list of fields we use to order.</p>
<pre class="brush: java;">
provider.getOrderKeyMap().put(&quot;name&quot;,&quot;p.lastName,p.firstName&quot;);
provider.getOrderKeyMap().put(&quot;age&quot;,&quot;p.dateOfBirth&quot;);
provider.getOrderKeyMap().put(&quot;id&quot;,&quot;p.id&quot;);
</pre>
<p>To order data when we fetch it from the provider, we need to assign a key order value on the paginator used to fetch the data from the provider.</p>
<pre class="brush: java;">
Paginator paginator = new DefaultPaginator();
paginator.setOrderKey(&quot;name&quot;); //order by the persons name
paginator.setOrderAscending(false);
List&lt;Person&gt; orderedList = provider.fetchResults(paginator);
</pre>
<p>If you are using  a dataset, you can just set the <code>orderKey</code> and <code>orderAscending</code> properties on the dataset instead. These key values can be embedded in your web page and passed back to the server side components without having to worry about SQL injection. If the order key is not recognized as one of the available values in the order key map then no order is used and no SQL is injected.</p>
<h1>State management</h1>
<p>Paginators and data providers are separate instances while object datasets  are made up of a paginator with a data provider reference that keeps a hold of the most recent set of results. The reason for this is so you can modify the degree of statelessness used. </p>
<p>You can make the whole thing stateless with the paginator info being passed between the client and the server. With Wicket, Seam, CDI and Spring Web Flow you might want to keep the paginator state on the server side but keep refreshing the results each time you postback. This can be done by keeping it in a Conversation, a Spring web flow, or a Wicket page. If you want to go fully stateful, you can use the Dataset which includes the paginator and the data provider and caches the recent resultset and put it in a Wicket page, a conversation or a page flow. By default, the JSF Components for paginating a DataValve result set is stateless.</p>
<h1>Client Side</h1>
<p>Briefly, lets look at the options for creating clients for DataValve datasets. There are components for a simple JSF paginator and a sortable column header for JSF 2.0 in the <code>datavalve-faces</code> module, and a <code>SortableDataProvider</code> for Wicket. For Swing, there is a special <code>TableModel </code> that caches and pre-emptively loads data for display in a Swing <code>JTable</code>. This means you can easily navigate thousands of rows of data in a Swing Table without having a long initial load time or taking up a lot of memory for object storage. </p>
<p>In the DataValve download there are demos for each of these examples in projects that are easy to run using the Jetty plugin for Maven so no server is required.  The Wicket demo even demonstrates how different pieces of server side code can be reused with JDBC, CSV and Hibernate driven data providers.</p>
<h1>Get Started</h1>
<p>In addition to the <a href="http://www.andygibson.net/blog/projects/DataValve">DataValve project page</a> you can see the documentation in <a href="html/index.html">HTML</a>, <a href="html_single/index.html">Single HTML</a>, or <a href="pdf/index.pdf">PDF</a>.   The download includes source that can be <a href="http://www.andygibson.net/tutorial/install-datavalve-into-maven/">built and installed with maven</a> as well as pre-built binaries.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/article/introducing-datavalve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing and Configuring Eclipse</title>
		<link>http://www.andygibson.net/blog/tutorial/installing-and-configuring-eclipse/</link>
		<comments>http://www.andygibson.net/blog/tutorial/installing-and-configuring-eclipse/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 02:19:33 +0000</pubDate>
		<dc:creator>Andy Gibson</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://www.andygibson.net/blog/?p=1070</guid>
		<description><![CDATA[This article shows you how to download and set up Eclipse in preparation for developing Java applications and includes configuring memory settings and if necessary alternate JDK versions.  Eclipse is an Integrated Development Environment that provides a set of basic elements for a development environment. This environment is extended by different plug-ins that provide [...]]]></description>
			<content:encoded><![CDATA[<p>This article shows you how to download and set up Eclipse in preparation for developing Java applications and includes configuring memory settings and if necessary alternate JDK versions. <span id="more-1070"></span> Eclipse is an Integrated Development Environment that provides a set of basic elements for a development environment. This environment is extended by different plug-ins that provide different features for different development tools, environments and frameworks. It is assumed the user is starting from scratch and will be downloading everything fresh. Once downloaded, we will install everything, and set up our environment.</p>
<div class="sidenote_right">
<h1>64 Bit Windows</h1>
<p>Some plug-ins do not support 64 bit JVMs on Windows, JBoss Developer Tools being one example. If you need to use these plug-ins, you will need to install a 32-bit JDK to use them, and we will configure Eclipse to use that JDK instead. This also means you will be unable to use a 64-bit version of Eclipse.
</p></div>
<h2>Installing and setting up Eclipse</h2>
<p>We&#8217;ll start by downloading the Eclipse SDK which is the base IDE that we will be installing plug-ins into. At the time of writing, Eclipse SDK 3.5.2 is the most recent version.  You need to download the version for Java EE developers since it contains most of the other required plug-ins for things like web development. You can download Eclipse from the <a href="http://www.eclipse.org/downloads/" target="_blank">Eclipse download site</a>. Once downloaded, unzip it into a folder of your choice. The zip file usually creates a directory called <code>eclipse</code> in the target directory that you unzipped the contents into.</p>
<h3>Memory Settings</h3>
<p>By default, Eclipse uses lousy memory settings, but we can alter the <code>eclipse.ini</code> file in the eclipse install directory to give us a better environment to work in. In the eclipse directory that appeared when you unzipped eclipse, there is an <code>eclipse.ini</code> file. Edit this file and you will see a section that starts with <code>-vmargs</code>. After this sections, you will see a couple of items starting with <code>-xms</code> and <code>-xmx</code>. Edit this section so that it reads something like : </p>
<pre class="brush: plain;">
-Xms256m
-Xmx512m
-XX:MaxPermSize=256m
</pre>
<p>Don&#8217;t delete any other items in this section, just replace any that are existing and add others that are not already there.</p>
<p>The values you use depends on how much memory you have, but this is a decent amount. You can go with less, or more depending on how much free memory you have. See <a href="http://blog.xam.dk/?p=58">here</a> for more details on Eclipse memory settings.</p>
<h3>Running Eclipse under a different JVM</h3>
<p>You can also tell Eclipse to run using a specific JVM or JDK in the <code>eclipse.ini</code> file by adding a <code>-vm</code> entry. You may need to do this if you have a 64-bit JVM and you need to run Eclipse under a 32-bit JVM. Another reason to add this to the configuration is because the Maven plug-ins we&#8217;ll be adding later prefers to run under a JDK instead of a JRE.</p>
<p>Open up <code>eclipse.ini</code> and add the following 2 lines :</p>
<pre class="brush: plain;">
-vm
C:\Program Files\Java\jdk1.6.xxx\bin\javaw.exe
</pre>
<p><b>Note : </b> This must be on 2 separate lines and they must be placed before the <code>-vm</code> arguments. Otherwise it will not work. </p>
<p>Now we have Eclipse installed and the environment configured, we&#8217;ll take it for a test. Run <code>eclipse.exe</code> and Eclipse should launch. If not, check that you are using a valid path and filename for the <code>-vm</code> option. If you are pointing to a 64-bit JVM and have 32-bit only plugins installed, this can cause silent failures.</p>
<p>When Eclipse starts up, if you go to <i>Help->About Eclipse</i> and the about dialog pops up. Click on the <i>Installation Details</i> button and in the window that pops up, click on the <i>Configuration</i> tab. In the big configuration listing, near the bottom of the window (you might have to scroll down a little)  you should see something like : </p>
<pre class="brush: plain;">
eclipse.vm=C:\Program Files\Java\jdk1.6.xxxx\bin\javaw.exe
eclipse.vmargs=-Dosgi.requiredJavaVersion=1.5
-Xms256m
-Xmx512m
-XX:MaxPermSize=256m
</pre>
<p>This confirms that our memory settings are being picked up, and the JDK we specified is being used.</p>
<h3>Adding Maven Support</h3>
<p>While this article doesn&#8217;t intend to cover any other plugins, Maven support in Eclipse is a rather fundamental one for getting started with projects. Here are the steps to install the m2Eclipse Maven plug-ins.</p>
<ol>
<li>Open the install manager by clicking the menu item  <i>Help->Install New Software&#8230;</i>.</li>
<li>In the install manager, click the <i>Add</i> button to add a new update site.</li>
<li>In the dialog that pops up, add m2Eclipse as the  Name, and set Location to <a href="http://m2eclipse.sonatype.org/sites/m2e/">http://m2eclipse.sonatype.org/sites/m2e/</a>. Click OK to close the dialog.</li>
<li>Select the m2Eclipse URL in the drop down and click the check box next to the Maven Integration for Eclipse plug-in in the list and click <i>Next</i>.</li>
<li>Once you agree to the licenses and click <i>Finish</i> Eclipse will download and install the plug-ins. Once complete, it will ask if you want to restart Eclipse now or later. It is best to re-start Eclipse before you start a new project or adding more plug-ins.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.andygibson.net/blog/tutorial/installing-and-configuring-eclipse/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
