<?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>Alessandro Melandri &#187; Java</title>
	<atom:link href="http://www.melandri.net/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.melandri.net</link>
	<description>J2EE Developer &#38; Photography enthusiast</description>
	<lastBuildDate>Tue, 27 Jul 2010 19:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JTextFileParser 1.4</title>
		<link>http://www.melandri.net/2010/03/26/jtextfileparser-1-4/</link>
		<comments>http://www.melandri.net/2010/03/26/jtextfileparser-1-4/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 12:47:31 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jtextfileparser]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://www.melandri.net/?p=978</guid>
		<description><![CDATA[I&#8217;ve just released a small update to JTexFileParser adding the ability to export text file data to XML. Check it out at google code. JTexFileParser is a java package built for simplifing delimited text files parsing. It gives you a quick way for parsing a delimited text file, managing rows and row’s fields.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released a small update to <a href="http://www.melandri.net/projects/jtextfileparser/">JTexFileParser</a> adding the ability to export text file data to XML.<br />
<a href="http://code.google.com/p/jtextfileparser/"><strong>Check it out</strong></a> at <a href="http://code.google.com/p/jtextfileparser/">google code</a>.</p>
<p><a href="http://www.melandri.net/projects/jtextfileparser/">JTexFileParser</a> is a java package built for simplifing delimited text files parsing. It gives you a quick way for parsing a delimited text file, managing rows and row’s fields.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2010/03/26/jtextfileparser-1-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scriptlet and JSTL variable sharing</title>
		<link>http://www.melandri.net/2009/09/16/scriptlet-and-jstl-variable-sharing/</link>
		<comments>http://www.melandri.net/2009/09/16/scriptlet-and-jstl-variable-sharing/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:15:23 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[JSTL]]></category>
		<category><![CDATA[scriptlet]]></category>
		<category><![CDATA[sharing]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.melandri.net/?p=596</guid>
		<description><![CDATA[I know that mixing scriplets and JSTL in JSP is a bad practice, but sometimes you can&#8217;t avoid it and every time I do it I can&#8217;t remember how to share variables between scriplets and JSTL so this post is a sort of reminder for the future. Hope it can be useful for other forgetful [...]]]></description>
			<content:encoded><![CDATA[<p>I know that mixing <a href="http://java.sun.com/products/jsp/syntax/2.0/syntaxref206.html">scriplets</a> and <a href="http://java.sun.com/products/jsp/jstl/reference/docs/index.html">JSTL</a> in <a href="http://java.sun.com/products/jsp/">JSP</a> is a bad practice, but sometimes you can&#8217;t avoid it and every time I do it I can&#8217;t remember how to share variables between scriplets and JSTL so this post is a sort of reminder for the future. Hope it can be useful for other forgetful persons like me :-)</p>
<h3>Access scriptlet variable with JSTL</h3>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>
<span style="color: #003399;">String</span> myVariable <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Test&quot;</span><span style="color: #339933;">;</span>
pageContext.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myVariable&quot;</span>, myVariable<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">%&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;c:out <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;myVariable&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<h3>Access JSTL variable with scriptlet</h3>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;c:set var<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;myVariable&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Test&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&lt;%</span>
<span style="color: #003399;">String</span> myVariable <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>pageContext.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;myVariable&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
out.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>myVariable<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">%&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/09/16/scriptlet-and-jstl-variable-sharing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When Runtime.exec() won&#8217;t &#8211; JavaWorld</title>
		<link>http://www.melandri.net/2009/08/04/when-runtime-exec-wont-javaworld/</link>
		<comments>http://www.melandri.net/2009/08/04/when-runtime-exec-wont-javaworld/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 09:12:31 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[link]]></category>

		<guid isPermaLink="false">http://www.melandri.net/?p=254</guid>
		<description><![CDATA[A well written article on JavaWorld that explains how to effectively use the Runtime.exec() method. It really saved me a lot of time. When Runtime.exec() won&#8217;t &#8211; JavaWorld]]></description>
			<content:encoded><![CDATA[<p>A well written article on <a title="JavaWorld Homepage" href="http://www.javaworld.com/" target="_blank">JavaWorld</a> that explains how to <span class="clickable" onclick="dr4sdgryt(event,&quot;Ox&quot;)"><span class="hg"><span class="hw">effectively </span></span></span>use the <em><a title="Javadoc" href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html" target="_blank">Runtime.exec()</a> </em>method. It really saved me a lot of time.</p>
<p><strong><a href="http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html">When Runtime.exec() won&#8217;t &#8211; JavaWorld</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/08/04/when-runtime-exec-wont-javaworld/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing text files using Java</title>
		<link>http://www.melandri.net/2009/06/18/writing-text-files-using-java/</link>
		<comments>http://www.melandri.net/2009/06/18/writing-text-files-using-java/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 07:16:53 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[FileWriter]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://www.melandri.net/?p=78</guid>
		<description><![CDATA[This simple method shows hot to write to text files using Java. If the file exists it will append the new text to it, otherwise it creates a new file. This is achieved using the FileWriter class and its constructor: public FileWriter&#40;String fileName, boolean append&#41; throws IOException Constructs a FileWriter object given a file name [...]]]></description>
			<content:encoded><![CDATA[<p>This simple method shows hot to write to text files using Java.<br />
If the file exists it will append the new text to it, otherwise it creates a new file. This is achieved using the FileWriter class and its constructor:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">FileWriter</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> fileName, <span style="color: #000066; font-weight: bold;">boolean</span> append<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span></pre></div></div>

<p><em>Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.</em> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html#FileWriter(java.lang.String, boolean)" title="FileWriter JavaDoc" target="_blank">JavaDoc</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeToFile<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> text, <span style="color: #003399;">String</span> filePath<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003399;">File</span> thisFile <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>filePath<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">BufferedWriter</span> writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedWriter</span><span style="color: #009900;">&#40;</span>
                                <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileWriter</span><span style="color: #009900;">&#40;</span>filePath, thisFile.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    writer.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span> text <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    writer.<span style="color: #006633;">newLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    writer.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    writer.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/06/18/writing-text-files-using-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java tail</title>
		<link>http://www.melandri.net/2009/05/29/java-tail/</link>
		<comments>http://www.melandri.net/2009/05/29/java-tail/#comments</comments>
		<pubDate>Fri, 29 May 2009 20:18:35 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.melandri.net/?p=57</guid>
		<description><![CDATA[A java implementation of the Unix tail command. This is a small customization of the java tail class created by Luigi Viggiano. I&#8217;ve just added some controls and added the update time parameter. import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; &#160; /** * Java implementation of the Unix tail command * * @param args[0] File name [...]]]></description>
			<content:encoded><![CDATA[<p>A java implementation of the Unix tail command. This is a small customization of the <a href="http://it.newinstance.it/2005/11/19/listening-changes-on-a-text-file-unix-tail-implementation-with-java/" title="Java Tail Class" target="_blank">java tail class</a> created by <a href="http://it.newinstance.it" title="Luigi Viggiano Blog" target="_blank">Luigi Viggiano</a>. I&#8217;ve just added some controls and added the update time parameter.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Java implementation of the Unix tail command
 * 
 * @param args[0] File name
 * @param args[1] Update time (seconds). Optional. Default value is 1 second
 * 
 * @author Luigi Viggiano (original author) http://it.newinstance.it/2005/11/19/listening-changes-on-a-text-file-unix-tail-implementation-with-java/
 * @author Alessandro Melandri (modified by)
 * */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Tail <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">long</span> sleepTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
        sleepTime <span style="color: #339933;">=</span> <span style="color: #003399;">Long</span>.<span style="color: #006633;">parseLong</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #003399;">BufferedReader</span> input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #003399;">String</span> currentLine <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>currentLine <span style="color: #339933;">=</span> input.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>currentLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span>sleepTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003399;">Thread</span>.<span style="color: #006633;">currentThread</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">interrupt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
      <span style="color: #009900;">&#125;</span>
      input.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Missing parameter!<span style="color: #000099; font-weight: bold;">\n</span>Usage: java JavaTail fileName [updateTime (Seconds. default to 1 second)]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/05/29/java-tail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Sun JDK on Linux</title>
		<link>http://www.melandri.net/2009/05/28/install-sun-jdk-on-linux/</link>
		<comments>http://www.melandri.net/2009/05/28/install-sun-jdk-on-linux/#comments</comments>
		<pubDate>Thu, 28 May 2009 07:19:13 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDK]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://localhost/blog/?p=17</guid>
		<description><![CDATA[I&#8217;ve tested this procedure on Fedora 10 and Ubuntu 9.04 but It should work on other distributions too. First of all download the latest JDK package from the SUN page: be sure to download the bin file and not the rpm. From now on you&#8217;ll need to run commands using &#8221;sudo&#8221;. Move the package to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tested this procedure on Fedora 10 and Ubuntu 9.04 but It should work on other distributions too.</p>
<p>First of all download the latest JDK package from the <a href="http://java.sun.com/">SUN page</a>: be sure to download the bin file and not the rpm.</p>
<p>From now on you&#8217;ll need to run commands using &#8221;sudo&#8221;.</p>
<p>Move the package to /opt/ and make it executable.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>folder
<span style="color: #c20cb9; font-weight: bold;">mv</span> jdk-versionnumber-linux-i586.bin <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x jdk-versionnumber-linux-i586.bin</pre></div></div>

<p>Now start the installation and follow the onscreen instructions</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>jdk-versionnumber-linux-i586.bin</pre></div></div>

<p>When the installation is done you&#8217;ll need to set the JAVA_HOME enviroment variable and add java executable to the system pah.</p>
<p>Open the file /etc/profile and add the following lines</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">JAVA_HOME</span>=<span style="color: #ff0000;">&quot;/opt/jdk_versionnumber&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> JAVA_HOME
&nbsp;
<span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>jdk_versionnumber<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> PATH</pre></div></div>

<p>Now add a symbolic link for the java command</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>jdk_versionnumber<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>java <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>java</pre></div></div>

<p>Log off and log in back and you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/05/28/install-sun-jdk-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the WEB-INF folder path</title>
		<link>http://www.melandri.net/2009/05/28/get-the-web-inf-folder-path/</link>
		<comments>http://www.melandri.net/2009/05/28/get-the-web-inf-folder-path/#comments</comments>
		<pubDate>Thu, 28 May 2009 07:15:00 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://localhost/blog/?p=14</guid>
		<description><![CDATA[This is a simple example on how to get the WEB-INF directory path in a J2EE web application. public class MyClassName&#123; &#160; private static final String WEBINF = &#34;WEB-INF&#34;; &#160; public String getWebInfPath&#40;&#41;&#123; &#160; String filePath = &#34;&#34;; &#160; URL url = MyClassName.class.getResource&#40;&#34;MyClassName.class&#34;&#41;; String className = url.getFile&#40;&#41;; &#160; filePath = className.substring&#40;0,className.indexOf&#40;WEBINF&#41; + WEBINF.length&#40;&#41;&#41;; return filePath; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple example on how to get the WEB-INF directory path in a J2EE web application.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyClassName<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> WEBINF <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;WEB-INF&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getWebInfPath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #003399;">String</span> filePath <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> MyClassName.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyClassName.class&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> className <span style="color: #339933;">=</span> url.<span style="color: #006633;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    filePath <span style="color: #339933;">=</span> className.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,className.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span>WEBINF<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> WEBINF.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> filePath<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/05/28/get-the-web-inf-folder-path/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Connect to MySql using Java</title>
		<link>http://www.melandri.net/2009/05/15/connect-to-mysql-using-java/</link>
		<comments>http://www.melandri.net/2009/05/15/connect-to-mysql-using-java/#comments</comments>
		<pubDate>Fri, 15 May 2009 09:42:09 +0000</pubDate>
		<dc:creator>amelandri</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://localhost/blog/?p=1</guid>
		<description><![CDATA[This is a simple class that I usually use to connect to a MySQL database. Obviously the right MySQL JDBC driver must be in your classpath. import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; &#160; public class ConnectionManager &#123; &#160; // Connection data -- START &#160; static final String driver = [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple class that I usually use to connect to a MySQL database. Obviously the right <a href="http://www.mysql.com/products/connector/j/">MySQL JDBC driver</a> must be in your classpath.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Connection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.DriverManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.PreparedStatement</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.Statement</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnectionManager <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Connection data -- START</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> driver   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;com.mysql.jdbc.my_driver_version&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> dbserver <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql.server.name&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> dbport   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql.database.port&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> dbname   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql.database.name&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> dbuser   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql.database.username&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> dbpass   <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mysql.database.password&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Connection data -- END</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Opens a connection to the database
     *
     * @return Returns a Connection object
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Connection</span> getConnection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #003399;">Connection</span> con <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span>driver<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">String</span> conString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;jdbc:mysql://&quot;</span><span style="color: #339933;">+</span>dbserver<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">+</span>dbport<span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">+</span>dbname<span style="color: #339933;">;</span>
            con <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span>conString,dbuser, dbpass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InstantiationException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IllegalAccessException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> con<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> close<span style="color: #009900;">&#40;</span><span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">Connection</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Connection</span><span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">Statement</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Statement</span><span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">PreparedStatement</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">PreparedStatement</span><span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> <span style="color: #003399;">ResultSet</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span><span style="color: #009900;">&#41;</span>object<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
                object <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.melandri.net/2009/05/15/connect-to-mysql-using-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
