<?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>byteco.de &#187; Java</title>
	<atom:link href="http://byteco.de/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://byteco.de</link>
	<description>In a world of 1s and 0s...are you a zero, or The One?</description>
	<lastBuildDate>Sun, 05 Feb 2012 05:44:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Eclipse Code Formatter &#8211; IntelliJ IDEA</title>
		<link>http://byteco.de/2011/12/02/eclipse-code-formatter-intellij-idea/</link>
		<comments>http://byteco.de/2011/12/02/eclipse-code-formatter-intellij-idea/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 16:24:38 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[code formatter]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[intellij]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=6395</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>When working with a team of developers spread across globe, one challenge is to maintain code formatting.</p>
<p>Most of teams using Eclipse as their primary IDE, rely on Eclipse code formatter that can be configured by enabling project specific setting and then adding <strong>/.settings</strong> directory to version control system. This directory contains <strong>org.eclipse.jdt.core.prefs</strong> which has formatting details.</p>
<p>Since these files are part of version control, all developers now has these settings file and formatting changes gets applied automatically on saving file.</p>
<p>But if you are an IDEA user, then there <del datetime="2011-12-02T16:06:10+00:00">is</del> was no way to use these Eclipse code formatting.</p>
<p>To make life somewhat easy, over the weekend I created a small plugin which basically let you use the Eclipse Code Formatter from IDEA. The main feature of this is that you can apply these on a Change List. Change List in IDEA is basically list of files that you have modified/created and are going to commit.</p>
<p>For more details visit project page &#8211; <a href="http://code.google.com/p/eclipse-code-formatter-on-change-list/" title="eclipse-code-formatter-on-change-list/" target="_blank">eclipse-code-formatter-on-change-list</a></p>
<p>The plugin is also available in <a href="http://plugins.intellij.net/plugin/?idea&#038;id=6566" target="_blank">IDEA plugin repository</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2011/12/02/eclipse-code-formatter-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Map Interface Examples</title>
		<link>http://byteco.de/2011/04/25/java-map-interface-examples/</link>
		<comments>http://byteco.de/2011/04/25/java-map-interface-examples/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 07:58:33 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[HashMap]]></category>
		<category><![CDATA[IdentityHashMap]]></category>
		<category><![CDATA[java collection framework]]></category>
		<category><![CDATA[LinkedHashMap]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[TreeMap]]></category>
		<category><![CDATA[WeakHashMap]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=3559</guid>
		<description><![CDATA[Recently I was explaining someone about Java Map and various implementations that are available as part of JDK. I had wrote a simple program to explain him that. Thought of putting it here. Below it is - TreeMap &#8211; The map is sorted according to the natural ordering of its keys, or by a Comparator [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was explaining someone about Java Map and various implementations that are available as part of JDK.</p>
<p>I had wrote a simple program to explain him that. Thought of putting it here. Below it is -</p>
<p><strong>TreeMap</strong> &#8211; The map is sorted according to the natural ordering of its keys, or by a Comparator provided at map creation time, depending on which constructor is used. Below example you will notice that treeMap toString shows that entries are ordered by performing natural ordering on Int keys.</p>
<p><strong>HashMap</strong> &#8211; This class makes no guarantees as to the order of the map. Uses object equality to check if key already exist in map and replace value if it exist. As in example while trying to put <em>key11</em> as it equals with <em>key1</em> value &#8220;One&#8221; is replaced with &#8220;Eleven&#8221;.</p>
<p><strong>IdentityHashMap </strong>- Unlike above HashMap, this uses reference-equality in place of object-equality when comparing keys. As in following example even after key11 equals key1, but as their references are not equals so a new key/value is inserted. </p>
<p><strong>LinkedHashMap</strong> &#8211; This implementation keeps track of order in which keys were inserted into the map. In below example you will notice that the toString shows entries in same order in which they were inserted. This also has another feature discussed next.</p>
<p><strong>LRU Caching using LinkedHashMap</strong> &#8211; Another feature of LinkedHashMap is that it provide constructor  to create a linked hash map whose order of iteration is the order in which its entries were last accessed, from least-recently accessed to most-recently (access-order). In following example, you will notice that when elements are inserted and none is accessed yet, the order of Entries is same as that of above example. But after accessing elements, you will notice that the entries order is changed based on when last it was accessed. Using this feature one can create a LRU(accessed) cache as shown in example. You will need to override removeEldestEntry method of LinkedHashMap and add your logic for caching. Each put operation will call this removeEldestEntry by passing least-recently-accessed element to it and based on removeEldestEntry&#8217;s return value it will either be kept or removed from the map.</p>
<p><strong>WeakHashMap</strong>- In this implementation keys are held as WeakReferences. This way if there is no strong reference for key, on next Garbage Collection this key and corresponding value will be removed from the Map. Read <a href="http://weblogs.java.net/blog/2006/05/04/understanding-weak-references">this </a>article for details on Java References. As in below example we are adding three keys to map and then clearing one strong reference to key6 by setting it to null. Then we request GC by calling System.gc() and in next statement you will notice that the key/value for key6 is removed from Map.</p>
<p><span id="more-3559"></span></p>
<pre class="brush: java">
package collections;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.WeakHashMap;

public class DemoMap {

    public static void main(String[] args) {
        // TreeMap
        Map&lt;Integer, String&gt; treeMap = new TreeMap&lt;Integer, String&gt;();
        treeMap.put(4, &quot;Four&quot;);
        treeMap.put(1, &quot;One&quot;);
        treeMap.put(5, &quot;Five&quot;);
        treeMap.put(3, &quot;Three&quot;);
        treeMap.put(2, &quot;Two&quot;);
        System.out.println(&quot;TreeMap - &quot; + treeMap);
        // TreeMap - {1=One, 2=Two, 3=Three, 4=Four, 5=Five}

        // HashMap
        Key key1 = new Key(1);
        Key key11 = new Key(1);
        Key key2 = new Key(2);
        Key key3 = new Key(3);
        Map&lt;Key, String&gt; map = new HashMap&lt;Key, String&gt;();
        map.put(key1, &quot;One&quot;);
        map.put(key11, &quot;Eleven&quot;);
        map.put(key2, &quot;Two&quot;);
        map.put(key3, &quot;Three&quot;);
        System.out.println(&quot;HashMap - &quot; + map);
        // HashMap - {3=Three, 1=Eleven, 2=Two}

        // IdentityHashMap
        Map&lt;Key, String&gt; idMap = new IdentityHashMap&lt;Key, String&gt;();
        idMap.put(key1, &quot;One&quot;);
        idMap.put(key11, &quot;One&quot;);
        idMap.put(key2, &quot;Two&quot;);
        idMap.put(key3, &quot;Three&quot;);
        System.out.println(&quot;IdentityHashMap - &quot; + idMap);
        // IdentityHashMap - {1=One, 1=One, 3=Three, 2=Two}

        // LinkedHashMap
        Map&lt;Integer, String&gt; linkedMap = new LinkedHashMap&lt;Integer, String&gt;(5);
        linkedMap.put(4, &quot;Four&quot;);
        linkedMap.put(1, &quot;One&quot;);
        linkedMap.put(5, &quot;Five&quot;);
        linkedMap.put(3, &quot;Three&quot;);
        linkedMap.put(2, &quot;Two&quot;);
        System.out.println(&quot;LinkedHashMap - &quot; + linkedMap);
        //LinkedHashMap - {4=Four, 1=One, 5=Five, 3=Three, 2=Two}

        // LinkedHashMap for Caching using access-order
        Map&lt;Integer, String&gt; cachedLinkedMap = new CacheUsingLinkedHashMap&lt;Integer, String&gt;(5);
        cachedLinkedMap.put(4, &quot;Four&quot;);
        cachedLinkedMap.put(1, &quot;One&quot;);
        cachedLinkedMap.put(5, &quot;Five&quot;);
        cachedLinkedMap.put(3, &quot;Three&quot;);
        cachedLinkedMap.put(2, &quot;Two&quot;);
        System.out.println(&quot;LinkedHashMap at full capacity no access performed yet - &quot; + cachedLinkedMap);
        // LinkedHashMap at full capacity no access performed yet - {4=Four, 1=One, 5=Five, 3=Three, 2=Two}
        cachedLinkedMap.get(1);
        cachedLinkedMap.get(2);
        cachedLinkedMap.get(4);
        cachedLinkedMap.get(5);
        cachedLinkedMap.get(3);
        System.out.println(&quot;LinkedHashMap at full capacity after accessing few elements - &quot; + cachedLinkedMap);
        // LinkedHashMap at full capacity after accessing few elements - {1=One, 2=Two, 4=Four, 5=Five, 3=Three}
        cachedLinkedMap.put(6, &quot;Six&quot;);
        System.out.println(&quot;LinkedHashMap after adding new entry - &quot; + cachedLinkedMap);
        // As 1 is least recently accessed.
        // LinkedHashMap after adding new entry - {2=Two, 4=Four, 5=Five, 3=Three, 6=Six}

        // WeakHashMap
        Map&lt;Key, String&gt; weakMap = new WeakHashMap&lt;Key, String&gt;();
        Key key4 = new Key(4);
        Key key5 = new Key(5);
        Key key6 = new Key(6);
        weakMap.put(key4, &quot;Four&quot;);
        weakMap.put(key5, &quot;Five&quot;);
        weakMap.put(key6, &quot;Six&quot;);
        System.out.println(&quot;WeakHashMap before GC - &quot; + weakMap);
        // WeakHashMap before GC - {6=Six, 5=Five, 4=Four}
        key6 = null;
        System.gc();
        System.out.println(&quot;WeakHashMap after GC - &quot; + weakMap);
        // WeakHashMap after GC - {5=Five, 4=Four}
    }

    static class CacheUsingLinkedHashMap&lt;K, V&gt; extends LinkedHashMap&lt;K, V&gt; {

        int capacity;

        public CacheUsingLinkedHashMap(int cap) {
            super(cap + 1, 1.1f, true);
            capacity = cap;
        }

        @Override
        protected boolean removeEldestEntry(java.util.Map.Entry&lt;K, V&gt; eldest) {
            return size() &gt; capacity;
        }

    }

    static class Key {
        int key;

        public Key(int key) {
            this.key = key;
        }

        @Override
        public int hashCode() {
            final int prime = 31;
            int result = 1;
            result = prime * result + key;
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Key other = (Key) obj;
            if (key != other.key)
                return false;
            return true;
        }

        @Override
        public String toString() {
            return String.valueOf(key);
        }
    }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2011/04/25/java-map-interface-examples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Publishing Webservice on Multiple Network Interfaces</title>
		<link>http://byteco.de/2011/04/06/publishing-webservice-on-multiple-network-interfaces/</link>
		<comments>http://byteco.de/2011/04/06/publishing-webservice-on-multiple-network-interfaces/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 10:43:17 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=2777</guid>
		<description><![CDATA[Recently our IT support group decided to move one of component to a new VCS Cluster. This component is a service component exposing various web services which are consumed by another .Net based UI component. The initial attempt was not successful as the component was incompatible with multi-homed hosts (those with multiple IP addresses / [...]]]></description>
			<content:encoded><![CDATA[<p>Recently our IT support group decided to move one of component to a new VCS Cluster.</p>
<p>This component is a service component exposing various web services which are consumed by another .Net based UI component.</p>
<p>The initial attempt was not successful as the component was incompatible with multi-homed hosts (those with multiple IP addresses / network interfaces), because it listen to port 80 on the primary network interface only.</p>
<p>As currently the component was running on a single-homed host, there’s no problem, since there’s only one IP address, and no ambiguity.</p>
<p>But VCS clusters are multi-homed devices – they have local IP, and cluster IP.</p>
<p>And in VCS world, nobody is connecting to host name / IP directly, connection should be established to cluster name / IP.</p>
<p>So to make the component publish web service on all interfaces, instead of using localhost or host address, use 0.0.0.0 as address. With 0.0.0.0 you tell it to &#8216;listen&#8217; to incoming connections to any ip-address (associated with box).</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2011/04/06/publishing-webservice-on-multiple-network-interfaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TestDox and IntelliJ IDEA 9</title>
		<link>http://byteco.de/2010/02/14/testdox-and-intellij-idea-9/</link>
		<comments>http://byteco.de/2010/02/14/testdox-and-intellij-idea-9/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 16:31:26 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[testdox]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=882</guid>
		<description><![CDATA[I really missed TestDox plugin for IDEA. There is no official version as of now for IDEA 9.0 I tried to install latest available version but its not compatible. I played around with plugin.xml by removing until-build=&#8221;IU-93.94&#8243;, it got enabled but then threw following exception, Caused by: java.lang.NumberFormatException: For input string: "IU-93.94" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at [...]]]></description>
			<content:encoded><![CDATA[<p>I really missed <a href="http://testdox.codehaus.org">TestDox</a> plugin for IDEA. There is no official version as of now for IDEA 9.0</p>
<p>I tried to install latest available version but its not compatible. I played around with plugin.xml by removing <em>until-build=&#8221;IU-93.94&#8243;</em>, it got enabled but then threw following exception,</p>
<pre>Caused by: java.lang.NumberFormatException: For input string: "IU-93.94"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
	at java.lang.Integer.parseInt(Integer.java:449)
	at java.lang.Integer.parseInt(Integer.java:499)
	at org.codehaus.testdox.intellij.IntelliJApiFactory.&lt;init&gt;(IntelliJApiFactory.java:24)</pre>
<p>I had patched the IntelliJApiFactory and updated .class file in the testdox-plugin-1.1.12-diana.jar. I am using it for some time and my usage is limited to navigate between class and its test. Not seeing any exceptions but overall IDEA 9.x plugin api are changed a lot and using a patched plugin might crash IDEA.</p>
<p>But for those who can&#8217;t live without it, can download it <a href="http://drop.io/testdox_idea_plugin/asset/testdox-plugin-zip">here</a>. Extract it to your IDEA plugins directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2010/02/14/testdox-and-intellij-idea-9/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Maven, dbdeploy, HSQLDB without Ant</title>
		<link>http://byteco.de/2010/01/31/maven-dbdeploy-hsqldb-without-ant/</link>
		<comments>http://byteco.de/2010/01/31/maven-dbdeploy-hsqldb-without-ant/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 17:29:18 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[dbdeploy]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=880</guid>
		<description><![CDATA[Believe me, integrating Maven and dbdeploy is a pain using Ant. For some weird reasons, dbdeploy ant task was causing maven build to crash. So tried to integrate dbdeploy with maven without ant on my Snow Leopard &#8211; You will need following jars - dbdeploy-cli-3.0M2.jar hsqldb-1.8.0.7.jar keep above jars in dir &#8220;db&#8221; in same dir [...]]]></description>
			<content:encoded><![CDATA[<p>Believe me, integrating Maven and dbdeploy is a pain using Ant. For some weird reasons, dbdeploy ant task was causing maven build to crash.</p>
<p>So tried to integrate dbdeploy with maven without ant on my Snow Leopard &#8211;<br />
<span id="more-880"></span></p>
<p>You will need following jars -</p>
<p>dbdeploy-cli-3.0M2.jar<br />
hsqldb-1.8.0.7.jar</p>
<p>keep above jars in dir &#8220;db&#8221; in same dir of pom.xml and keep your dbdeploy sql scripts in dir &#8220;db/scripts&#8221;. This will look like -</p>
<pre class="brush: text">
|-db
|----lib
|-------dbdeploy-cli-3.0M2.jar
|-------hsqldb-1.8.0.7.jar
|----scripts
|-------createSchemaVersionTable.sql
|-pom.xml
</pre>
<p>Next configure following Maven plugins -</p>
<pre class="brush: xml">
            &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                &lt;artifactId&gt;sql-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;1.1&lt;/version&gt;
                &lt;dependencies&gt;
                    &lt;dependency&gt;
                        &lt;groupId&gt;hsqldb&lt;/groupId&gt;
                        &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
                        &lt;version&gt;1.8.0.7&lt;/version&gt;
                    &lt;/dependency&gt;
                &lt;/dependencies&gt;
                &lt;configuration&gt;
                    &lt;driver&gt;${test.jdbc.driverClassName}&lt;/driver&gt;
                    &lt;url&gt;${test.jdbc.url}&lt;/url&gt;
                    &lt;username&gt;${test.jdbc.username}&lt;/username&gt;
                    &lt;password&gt;${test.jdbc.password}&lt;/password&gt;
                &lt;/configuration&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;create-change-log&lt;/id&gt;
                        &lt;phase&gt;process-test-sources&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;execute&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;srcFiles&gt;
                                &lt;srcFile&gt;${basedir}/db/scripts/createSchemaVersionTable.sql&lt;/srcFile&gt;
                            &lt;/srcFiles&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                    &lt;execution&gt;
                        &lt;id&gt;apply-db-changes&lt;/id&gt;
                        &lt;phase&gt;process-test-classes&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;execute&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;srcFiles&gt;
                                &lt;srcFile&gt;${basedir}/target/consolidated_script.sql&lt;/srcFile&gt;
                            &lt;/srcFiles&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
</pre>
<p>createSchemaVersionTable.sql is part of dbdeploy distribution. Copy HSQLDB version.</p>
<p>And the following </p>
<pre class="brush: xml">
            &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;1.1&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;id&gt;dbdeploy&lt;/id&gt;
                        &lt;phase&gt;test-compile&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;exec&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;executable&gt;java&lt;/executable&gt;
                            &lt;workingDirectory&gt;${basedir}/db&lt;/workingDirectory&gt;
                            &lt;commandlineArgs&gt;
                                -cp ${test.hsql.jar}:lib/dbdeploy-cli-3.0M2.jar com.dbdeploy.CommandLineTarget -U ${test.jdbc.username} -D ${test.jdbc.driverClassName} -u ${test.jdbc.url.escaped} -d ${test.dbdeploy.dbms.type} -o ${basedir}/target/consolidated_script.sql -s scripts/
                            &lt;/commandlineArgs&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;
</pre>
<p>Following are the important maven properties that are to be set -</p>
<pre class="brush: xml">
        &lt;test.jdbc.driverClassName&gt;org.hsqldb.jdbcDriver&lt;/test.jdbc.driverClassName&gt;
        &lt;test.jdbc.url&gt;jdbc:hsqldb:file:${basedir}/target/testdb;shutdown=true&lt;/test.jdbc.url&gt;
        &lt;test.jdbc.url.escaped&gt;jdbc:hsqldb:file:${basedir}/target/testdb\\;shutdown=true&lt;/test.jdbc.url.escaped&gt;
        &lt;test.jdbc.username&gt;sa&lt;/test.jdbc.username&gt;
        &lt;test.jdbc.password&gt;&lt;/test.jdbc.password&gt;
        &lt;test.dbdeploy.dbms.type&gt;hsql&lt;/test.dbdeploy.dbms.type&gt;
        &lt;test.hsql.jar&gt;lib/hsqldb-1.8.0.7.jar&lt;/test.hsql.jar&gt;
</pre>
<p>How it works &#8211; </p>
<p>We are using dbdeploy command line interface to achieve integration. The HSQLDB is used in a file mode which is evident by test.jdbc.url, since maven exec task executes by using bash semi-colon used in jdbc url needs to be escaped, thats the reason for defining test.jdbc.url.escaped property.</p>
<p>The sql-maven-plugin&#8217;s execution &#8220;create-change-log&#8221; is configured to run after phase &#8220;process-test-sources&#8221;, which creates change log table which is required by dbdeploy.</p>
<p>The exec-maven-plugin&#8217;s execution &#8220;dbdeploy&#8221; is configured to run after phase &#8220;test-compile&#8221;, executes dbdeploy command line interface, creates &#8220;${basedir}/target/consolidated_script.sql&#8221; which contains sql changes to be applied.</p>
<p>The sql-maven-plugin&#8217;s execution &#8220;apply-db-changes&#8221; is configured to run after phase &#8220;process-test-classes&#8221;, which applies consolidated change log script.</p>
<p>Hope it helps somebody..</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2010/01/31/maven-dbdeploy-hsqldb-without-ant/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integrating Spring and EHCache</title>
		<link>http://byteco.de/2010/01/26/integrating-spring-and-ehcache/</link>
		<comments>http://byteco.de/2010/01/26/integrating-spring-and-ehcache/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 16:15:37 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[ehcache]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=875</guid>
		<description><![CDATA[Using Spring Modules and EHCache, one can transparently cache method results. Spring Modules uses a proxy which intercepts call to the method of bean; consults the cache to check if method was called with same parameters before, if so will return cached result. EHCache is the actual provider of caching solution and Spring Module handles [...]]]></description>
			<content:encoded><![CDATA[<p>Using <a href="https://springmodules.dev.java.net/">Spring Modules</a> and <a href="http://ehcache.org/">EHCache</a>, one can transparently cache method results. Spring Modules uses a proxy which intercepts call to the method of bean; consults the cache to check if method was called with same parameters before, if so will return cached result.</p>
<p>EHCache is the actual provider of caching solution and Spring Module handles method interception and result storing in cache.<br />
<span id="more-875"></span><br />
Since I am using Maven2, so added following dependancies -</p>
<pre class="brush: xml">
        &lt;dependency&gt;
            &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
            &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
            &lt;version&gt;1.6.1&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springmodules&lt;/groupId&gt;
            &lt;artifactId&gt;spring-modules-cache&lt;/artifactId&gt;
            &lt;version&gt;0.9&lt;/version&gt;
        &lt;/dependency&gt;
</pre>
<p>My complete pom.xml -</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;Spring&lt;/groupId&gt;
    &lt;artifactId&gt;Spring&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;junit&lt;/groupId&gt;
            &lt;artifactId&gt;junit&lt;/artifactId&gt;
            &lt;version&gt;4.7&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;cglib&lt;/groupId&gt;
            &lt;artifactId&gt;cglib&lt;/artifactId&gt;
            &lt;version&gt;2.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
            &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
            &lt;version&gt;1.6.6&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;mysql&lt;/groupId&gt;
            &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
            &lt;version&gt;5.1.10&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
            &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
            &lt;version&gt;1.2.2&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
            &lt;version&gt;3.0.0.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
            &lt;artifactId&gt;ehcache&lt;/artifactId&gt;
            &lt;version&gt;1.6.1&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springmodules&lt;/groupId&gt;
            &lt;artifactId&gt;spring-modules-cache&lt;/artifactId&gt;
            &lt;version&gt;0.9&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/project&gt;
</pre>
<p>Contact Table sql -</p>
<pre class="brush: sql">
 CREATE TABLE `contact` (
  `ID` int(15) NOT NULL AUTO_INCREMENT,
  `FIRSTNAME` varchar(50) DEFAULT NULL,
  `LASTNAME` varchar(50) DEFAULT NULL,
  `EMAIL` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `EMAIL` (`EMAIL`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1
</pre>
<p>Adding ehcache namespace to Spring config file -</p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
       xmlns:ehcache=&quot;http://www.springmodules.org/schema/ehcache&quot;
       xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd&quot;&gt;
...
&lt;/beans&gt;
</pre>
<p>Created ehcache.xml file in classpath.</p>
<pre class="brush: xml">
&lt;ehcache&gt;
    &lt;defaultCache
            maxElementsInMemory=&quot;500&quot; eternal=&quot;true&quot; overflowToDisk=&quot;false&quot; memoryStoreEvictionPolicy=&quot;LFU&quot;/&gt;
    &lt;cache name=&quot;contactCache&quot; maxElementsInMemory=&quot;500&quot; eternal=&quot;true&quot; overflowToDisk=&quot;false&quot;
           memoryStoreEvictionPolicy=&quot;LFU&quot;/&gt;
&lt;/ehcache&gt;
</pre>
<p>Adding caching to application-context.xml  &#8211; </p>
<pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot;
       xmlns:ehcache=&quot;http://www.springmodules.org/schema/ehcache&quot;
       xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd&quot;&gt;

    &lt;ehcache:config configLocation=&quot;classpath:ehcache.xml&quot; /&gt;

    &lt;ehcache:proxy id=&quot;contactDAO&quot; refId=&quot;contactDAOTarget&quot;&gt;
        &lt;ehcache:caching cacheName=&quot;contactCache&quot; methodName=&quot;findAll&quot;/&gt;
        &lt;ehcache:flushing cacheNames=&quot;contactCache&quot; methodName=&quot;createContact&quot; when=&quot;after&quot;/&gt;
    &lt;/ehcache:proxy&gt;

    &lt;bean id=&quot;contactDAOTarget&quot; class=&quot;byteco.de.spring.ContactDAOImpl&quot;&gt;
        &lt;property name=&quot;namedParameterJdbcTemplate&quot; ref=&quot;jdbcTemplate&quot;&gt;&lt;/property&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;datasource&quot; class=&quot;org.apache.commons.dbcp.BasicDataSource&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;
        &lt;property name=&quot;username&quot; value=&quot;root&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;password&quot;/&gt;
        &lt;property name=&quot;initialSize&quot; value=&quot;5&quot;/&gt;
        &lt;property name=&quot;url&quot; value=&quot;jdbc:mysql://localhost:3306/springjpa&quot;/&gt;
    &lt;/bean&gt;

    &lt;bean id=&quot;jdbcTemplate&quot; class=&quot;org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate&quot;&gt;
        &lt;constructor-arg type=&quot;javax.sql.DataSource&quot; ref=&quot;datasource&quot;/&gt;
    &lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>Here is my test class -</p>
<pre class="brush: java">
package byteco.de.spring;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.test.annotation.ExpectedException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

import static org.junit.Assert.assertTrue;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = &quot;/application-context.xml&quot;)
public class ContactDAOTest {

    @Autowired
    ContactDAO contactDAO;

    @Test
    public void shouldCreateNewContact(){
         assertTrue(contactDAO.createContact(&quot;gabbar&quot;,&quot;singh&quot;,&quot;gabbar@singh.com&quot;));
         assertTrue(contactDAO.createContact(&quot;kalia&quot;,&quot;singh&quot;,&quot;kalia@singh.com&quot;));
    }

    @Test
    public void shouldReturnListOfContact(){
        assertTrue(contactDAO.findAll().size()&gt;0);
        assertTrue(contactDAO.findAll().size()&gt;0);
        assertTrue(contactDAO.findAll().size()&gt;0);
        // This will cause the cache to be cleared. refer to logs.
        assertTrue(contactDAO.createContact(&quot;samba&quot;,&quot;singh&quot;,&quot;samba@singh.com&quot;));
        assertTrue(contactDAO.findAll().size()&gt;0);
        assertTrue(contactDAO.findAll().size()&gt;0);
        assertTrue(contactDAO.findAll().size()&gt;0);
    }
}
</pre>
<p>Executed test shouldCreateNewContact first then shouldReturnListOfContact. Below is the console output -</p>
<pre class="brush: plain">
DEBUG [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - Autowiring by type from bean name &#039;byteco.de.spring.ContactDAOTest&#039; to bean named &#039;contactDAO&#039;
DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean &#039;org.springframework.aop.aspectj.AspectJPointcutAdvisor#0&#039;
DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean &#039;org.springframework.aop.aspectj.AspectJPointcutAdvisor#0&#039;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;null&gt;
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL query
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL statement [select * from contact]
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to store the object &lt;[0. 1 gabbar singh , 1. 2 kalia singh ]&gt; in the cache using key &lt;2056181503|2056171012&gt; and model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Object was successfully stored in the cache
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;[0. 1 gabbar singh , 1. 2 kalia singh ]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;[0. 1 gabbar singh , 1. 2 kalia singh ]&gt;
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL update
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL statement [insert into contact (firstname,lastname,email) values (?,?,?)]
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - SQL update affected 1 rows
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to flush the cache using model &lt;org.springmodules.cache.provider.ehcache.EhCacheFlushingModel@2dd59d3c[cacheNames={&#039;contactCache&#039;}, flushBeforeMethodExecution=false]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Cache has been flushed.
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;null&gt;
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL query
DEBUG [org.springframework.jdbc.core.JdbcTemplate] - Executing prepared SQL statement [select * from contact]
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to store the object &lt;[0. 1 gabbar singh , 1. 2 kalia singh , 2. 3 samba singh ]&gt; in the cache using key &lt;2056181503|2056171012&gt; and model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Object was successfully stored in the cache
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;[0. 1 gabbar singh , 1. 2 kalia singh , 2. 3 samba singh ]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Attempt to retrieve a cache entry using key &lt;2056181503|2056171012&gt; and cache model &lt;org.springmodules.cache.provider.ehcache.EhCacheCachingModel@1531164[cacheName=&#039;contactCache&#039;, blocking=false, cacheEntryFactory=null]&gt;
DEBUG [org.springmodules.cache.provider.ehcache.EhCacheFacade] - Retrieved cache element &lt;[0. 1 gabbar singh , 1. 2 kalia singh , 2. 3 samba singh ]&gt;
</pre>
<p>Here are my DAO classes &#8211; </p>
<pre class="brush: java">
package byteco.de.spring;
import java.util.List;
public interface ContactDAO {
    boolean createContact(String firstName, String lastName, String email);
    List findAll();
}
</pre>
<pre class="brush: java">
package byteco.de.spring;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ContactDAOImpl implements ContactDAO {

    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
        this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
    }

    public boolean createContact(String firstName, String lastName, String email) {
        Map&lt;String,String&gt; map = new HashMap&lt;String, String&gt;();
        map.put(&quot;firstname&quot;,firstName);
        map.put(&quot;lastname&quot;,lastName);
        map.put(&quot;email&quot;,email);
        int i = namedParameterJdbcTemplate.update(&quot;insert into contact (firstname,lastname,email) values (:firstname,:lastname,:email)&quot;, map);
        return i&gt;0;
    }

    public List findAll() {
        return namedParameterJdbcTemplate.query(&quot;select * from contact&quot;, (Map&lt;String, ?&gt;) null, new RowMapper() {
            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                return i + &quot;. &quot; + resultSet.getString(1) + &quot; &quot; + resultSet.getString(2) + &quot; &quot; + resultSet.getString(3) + &quot; &quot;;
            }
        });
    }
}
</pre>
<p>We are caching the result of findAll and clearing cache when createContact is executed.</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2010/01/26/integrating-spring-and-ehcache/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Jetty Remote Debugging using IntelliJ IDEA</title>
		<link>http://byteco.de/2009/12/10/jetty-remote-debugging-using-intellij-idea/</link>
		<comments>http://byteco.de/2009/12/10/jetty-remote-debugging-using-intellij-idea/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:58:19 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://byteco.de/2009/12/10/jetty-remote-debugging-using-intellij-idea/</guid>
		<description><![CDATA[Recently wanted to remotely debug Jetty instance, which was using mvn jetty:run. Using following MAVEN_OPTS worked for me - $ export MAVEN_OPTS=&#8221;-Xms256m -Xmx512m -agentlib:jdwp=transport=dt_socket,address=7848,server=y,suspend=n&#8221; After setting above executed - mvn jetty:run Then configured IDEA Remote Server by connecting to server on above configured port 7848]]></description>
			<content:encoded><![CDATA[<p style="clear: both">Recently wanted to remotely debug Jetty instance, which was using <strong>mvn jetty:run.</strong></p>
<p style="clear: both">Using following MAVEN_OPTS worked for me -</p>
<blockquote style="clear: both"><p>$ export MAVEN_OPTS=&#8221;-Xms256m -Xmx512m -agentlib:jdwp=transport=dt_socket,address=7848,server=y,suspend=n&#8221;</p>
</blockquote>
<p style="clear: both">After setting above executed -</p>
<blockquote style="clear: both"><p>mvn jetty:run</p>
</blockquote>
<p style="clear: both">Then configured IDEA Remote Server by connecting to server on above configured port 7848</p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2009/12/10/jetty-remote-debugging-using-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSF Validations</title>
		<link>http://byteco.de/2009/06/16/jsf-validations/</link>
		<comments>http://byteco.de/2009/06/16/jsf-validations/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 09:30:15 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[validations]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=626</guid>
		<description><![CDATA[<strong>Using JSF Standard Built-in Validations</strong>
JSF provides built-in support for validations of input component tags. You can supply it a attribute <strong>required="true"</strong> which will check if a value is supplied or not. There are built-in validators which you can nest in all JSF input tags.]]></description>
			<content:encoded><![CDATA[<p><strong>Using JSF Standard Built-in Validations</strong><br />
JSF provides built-in support for validations of input component tags. You can supply it a attribute <strong>required=&#8221;true&#8221;</strong> which will check if a value is supplied or not. There are built-in validators which you can nest in all JSF input tags.</p>
<p>Below are the built-in Validators -</p>
<ol>
<li>f:validateDoubleRange</li>
<li>f:validateLongRange</li>
<li>f:validateLength</li>
</ol>
<p><em>One should be cautious as when the required attribute is not set and user supplies a blank input, then no validation are performed.</em></p>
<p>Below is a example of using JSF Validator -</p>
<pre class="brush: xml">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;%@ taglib uri=&quot;http://myfaces.apache.org/tomahawk&quot; prefix=&quot;t&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JSF Validations Example Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;f:view&gt;
&lt;h2&gt;JSF Validations Example Form&lt;/h2&gt;
&lt;h:form id=&quot;helloForm&quot;&gt;

&lt;ul&gt;
&lt;li&gt;&lt;h:outputText value=&quot;Enter your name :&quot; /&gt; &lt;br /&gt;
&lt;t:message id=&quot;usernameMessage&quot; for=&quot;username&quot; style=&quot;color:red;&quot; /&gt; &lt;br /&gt;
&lt;h:inputText value=&quot;#{userBean.name}&quot; id=&quot;username&quot; required=&quot;true&quot; /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h:commandButton action=&quot;#{userBean.sayHello}&quot; value=&quot;Enter&quot; /&gt;
&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>When user does not supply value for username -</p>
<p><img class="alignnone size-full wp-image-633" title="jsf14" src="http://byteco.de/wp-content/uploads/2009/06/jsf14.jpg" alt="jsf14" width="432" height="181" /></p>
<p><strong>Creating a Custom Validator</strong><br />
JSF also provides support for writing your own custom Validators. Below are the steps which you would need to do in order to write your own custom validator. I am writing a custom validator for verifying a email address using commons-validator.</p>
<p><strong>Step 1:</strong><br />
Implement interface, javax.faces.validator.Validator</p>
<pre class="brush: java">
package com.test.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class EmailValidator implements Validator {
	public void validate(FacesContext facesContext, UIComponent component, Object object)
			throws ValidatorException {
		org.apache.commons.validator.EmailValidator instance = org.apache.commons.validator.EmailValidator.getInstance();
		if(!instance.isValid(object.toString())){
			FacesMessage facesMessage = new FacesMessage(&quot;Invalid email address&quot;);
			throw new ValidatorException(facesMessage);
		}
	}
}
</pre>
<p><strong>Step 2:</strong></p>
<p>Register above validator in faces-config.xml.</p>
<pre class="brush: xml">

&lt;validator&gt;
	&lt;description&gt;&lt;/description&gt;
	&lt;display-name&gt;EmailValidator&lt;/display-name&gt;
	&lt;validator-id&gt;EmailValidator&lt;/validator-id&gt;
	&lt;validator-class&gt;com.test.validator.EmailValidator&lt;/validator-class&gt;
&lt;/validator&gt;
</pre>
<p><strong>Step 3:</strong></p>
<p>Use above registered validator in your page &#8211; </p>
<pre class="brush: xml">

&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;%@ taglib uri=&quot;http://myfaces.apache.org/tomahawk&quot; prefix=&quot;t&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JSF Validations Example Form&lt;/title&gt;
&lt;/head&gt;
&lt;body style=&quot;font:Arial 12px;&quot;&gt;
&lt;f:view&gt;
	&lt;h2&gt;JSF Validations Example Form&lt;/h2&gt;
	&lt;h:form id=&quot;helloForm&quot;&gt;

		&lt;ul&gt;
			&lt;li&gt;&lt;h:outputText value=&quot;Enter email :&quot; /&gt; &lt;br /&gt;
			&lt;t:message id=&quot;emailMessage&quot; for=&quot;email&quot; style=&quot;color:red;&quot; /&gt; &lt;br /&gt;
			&lt;h:inputText value=&quot;#{userBean.email}&quot; id=&quot;email&quot; required=&quot;true&quot;&gt;
				&lt;f:validator validatorId=&quot;EmailValidator&quot;&gt;&lt;/f:validator&gt;
			&lt;/h:inputText&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
		&lt;h:commandButton action=&quot;#{userBean.sayHello}&quot; value=&quot;Enter&quot; /&gt;
	&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Output:</strong></p>
<p><img src="http://byteco.de/wp-content/uploads/2009/06/jsf2.jpg" alt="jsf2" title="jsf2" width="362" height="184" class="alignnone size-full wp-image-638" /></p>
<p><strong>Interdependant Fields Validation using Custom Validator</strong></p>
<p>Though not a perfect example for dependant field validation, I couldn&#8217;t come up with any other in short time, we have a check box [are you married?] which when selected then marriage date should be valid.</p>
<p>I have created a custom validator for Date which I am using here -</p>
<pre class="brush: java">

package com.test.validator;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

public class MarriedDateValidator extends DateValidator {

	@Override
	public void validate(FacesContext facesContext, UIComponent component,
			Object object) throws ValidatorException {
		UIInput input = (UIInput) component.findComponent(&quot;married&quot;);
		if(input.isValid()){
			if(input.getValue().toString().equals(&quot;true&quot;)){
				super.validate(facesContext, component, object);
			}
		}
	}
}
</pre>
<p>If you notice line where I get access to the input component <em>component.findComponent(&#8220;married&#8221;);</em> and then uses it for further decisions on validations. </p>
<p>Just for reference &#8211; below is the class DateValidator.</p>
<pre class="brush: java">

package com.test.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class DateValidator implements Validator {

	public void validate(FacesContext facesContext, UIComponent component, Object object)
			throws ValidatorException {
		org.apache.commons.validator.DateValidator instance = org.apache.commons.validator.DateValidator.getInstance();
		if(!instance.isValid(object.toString(), &quot;dd/MM/yyyy&quot;, true)){
			FacesMessage facesMessage = new FacesMessage(&quot;Invalid date&quot;);
			throw new ValidatorException(facesMessage);
		}
	}

}
</pre>
<p>The next step is to define above in faces-config.xml.</p>
<pre class="brush: xml">

&lt;validator&gt;
	&lt;description&gt;&lt;/description&gt;
	&lt;display-name&gt;MarriedDateValidator&lt;/display-name&gt;
	&lt;validator-id&gt;MarriedDateValidator&lt;/validator-id&gt;
	&lt;validator-class&gt;com.test.validator.MarriedDateValidator&lt;/validator-class&gt;
&lt;/validator&gt;
</pre>
<p>And then using it in your page -</p>
<pre class="brush: xml">

&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;%@ taglib uri=&quot;http://myfaces.apache.org/tomahawk&quot; prefix=&quot;t&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JSF Validations Example Form&lt;/title&gt;
&lt;/head&gt;
&lt;body style=&quot;font:Arial 12px;&quot;&gt;
&lt;f:view&gt;
	&lt;h2&gt;JSF Validations Example Form&lt;/h2&gt;
	&lt;h:form id=&quot;helloForm&quot;&gt;
		&lt;ul&gt;
			&lt;li&gt;&lt;h:outputText value=&quot;Are you married? :&quot; /&gt; &lt;h:selectBooleanCheckbox value=&quot;#{userBean.married}&quot; id=&quot;married&quot; /&gt; &lt;br /&gt;
			&lt;h:outputText value=&quot;Enter marriage date :&quot; /&gt; &lt;br /&gt;
			&lt;t:message id=&quot;domMessage&quot; for=&quot;dom&quot; style=&quot;color:red;&quot; /&gt; &lt;br /&gt;
			&lt;h:inputText value=&quot;#{userBean.dateOfMarriage}&quot; id=&quot;dom&quot;&gt;
				&lt;f:validator validatorId=&quot;MarriedDateValidator&quot;&gt;&lt;/f:validator&gt;
			&lt;/h:inputText&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
		&lt;h:commandButton action=&quot;#{userBean.sayHello}&quot; value=&quot;Enter&quot; /&gt;
	&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>In above notice that there is no required=&#8221;true&#8221; for the userBean.dateOfMarriage input tag. When the check box is not selected no validations are performed on the field.</p>
<p><img src="http://byteco.de/wp-content/uploads/2009/06/jsf3.jpg" alt="jsf3" title="jsf3" width="356" height="203" class="alignnone size-full wp-image-642" /></p>
<p>Only when the checkbox is selected, validations are performed and you get following message &#8211; </p>
<p><img src="http://byteco.de/wp-content/uploads/2009/06/jsf4.jpg" alt="jsf4" title="jsf4" width="371" height="192" class="alignnone size-full wp-image-644" /></p>
<p><strong>Creating Custom Converters</strong></p>
<p>A custom converter is called after custom validations are performed and any errors during conversion step, the errors are displayed in the same input page while all orignal input values are retained. </p>
<p>The good thing about convertors is unlike a validator which is only called when required=&#8221;true&#8221; is set for the input tag, it gets called even if the input field is having a empty value. </p>
<p>We can use this to handle validations of non mandatory fields where if the user enters the data then it should be valid. For eg. We are having a field &#8220;Date Of Joining&#8221; which is not a mandatory field, but if user enters a value we want it to be a valid date.</p>
<p>Below are the steps on writing a custom converters -</p>
<p><strong>Step 1:</strong></p>
<p>Implement a interface, javax.faces.convert.Converter.</p>
<pre class="brush: java">

package com.test.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class DateConverter implements Converter {

	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String val)
			throws ConverterException {
		String pattern = &quot;dd/MM/yyyy&quot;;
		boolean required = ((UIInput)uiComponent).isRequired();
		if((val==null || val.trim().isEmpty()) &amp;amp;&amp;amp; !required )
			return null;
		org.apache.commons.validator.DateValidator instance = org.apache.commons.validator.DateValidator.getInstance();
		if(!instance.isValid(val.toString(), pattern, true)){
			FacesMessage facesMessage = new FacesMessage(&quot;Using Converter - Invalid date&quot;);
			throw new ConverterException(facesMessage);
		}
		try {
			return new SimpleDateFormat(pattern).parse(val);
		} catch (ParseException e) {
			FacesMessage facesMessage = new FacesMessage(&quot;Using Converter - Invalid date&quot;);
			throw new ConverterException(facesMessage);
		}
	}

	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object val)
			throws ConverterException {
		return val.toString();
	}

}
</pre>
<p>Please note following -</p>
<p><em>boolean required = ((UIInput)uiComponent).isRequired();</em> &#8211; Using this we can check if the field was required or not. Based on it we can either ignore the conversion or perform it.</p>
<p><strong>Step 2:</strong></p>
<p>The next step is registering this convertor in faces-config.xml.</p>
<pre class="brush: xml">

	&lt;converter&gt;
		&lt;display-name&gt;DateConverter&lt;/display-name&gt;
		&lt;converter-for-class&gt;java.util.Date&lt;/converter-for-class&gt;
		&lt;converter-class&gt;com.test.converter.DateConverter&lt;/converter-class&gt;
	&lt;/converter&gt;
</pre>
<p>The JSF will call our converter when it finds the type of field in a bean as java.util.Date.</p>
<p>Below is our UserBean.java</p>
<pre class="brush: java">

package com.test.beans;

import java.util.Date;

import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import com.test.validator.DateValidator;

public class UserBean {

	private Date dateOfJoining;

	public Date getDateOfJoining() {
		return dateOfJoining;
	}

	public void setDateOfJoining(Date dateOfJoining) {
		this.dateOfJoining = dateOfJoining;
	}

	public String sayHello() {
		return &quot;hello&quot;;
	}
}
</pre>
<p><strong>Step 3:</strong></p>
<p>As you have mapped the converter for Date classes you don&#8217;t need to specify anything in page &#8211; </p>
<pre class="brush: xml">

&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;%@ taglib uri=&quot;http://myfaces.apache.org/tomahawk&quot; prefix=&quot;t&quot;%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;JSF Validations Example Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;f:view&gt;
	&lt;h2&gt;JSF Validations Example Form&lt;/h2&gt;
	&lt;h:form id=&quot;helloForm&quot;&gt;

		&lt;ul&gt;
			&lt;li&gt;&lt;h:outputText value=&quot;Enter date of joining :&quot; /&gt; &lt;br /&gt;
			&lt;t:message id=&quot;dojMessage&quot; for=&quot;doj&quot; style=&quot;color:red;&quot; /&gt; &lt;br /&gt;
			&lt;h:inputText value=&quot;#{userBean.dateOfJoining}&quot; converterMessage=&quot;Please enter valid date of joining&quot; id=&quot;doj&quot; /&gt;
			&lt;/li&gt;
		&lt;/ul&gt;
		&lt;h:commandButton action=&quot;#{userBean.sayHello}&quot; value=&quot;Enter&quot; /&gt;
	&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Notice that the required=&#8221;true&#8221; is not set and you can specify your own custom message to be shown in case of conversion error by using <em>converterMessage</em>.</p>
<p><strong>Output:</strong></p>
<p><img src="http://byteco.de/wp-content/uploads/2009/06/jsf5.jpg" alt="jsf5" title="jsf5" width="423" height="180" class="alignnone size-full wp-image-645" /></p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2009/06/16/jsf-validations/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Ant Input and Passwords</title>
		<link>http://byteco.de/2009/05/01/ant-input-and-passwords/</link>
		<comments>http://byteco.de/2009/05/01/ant-input-and-passwords/#comments</comments>
		<pubDate>Fri, 01 May 2009 08:13:18 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[password]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=591</guid>
		<description><![CDATA[Ant input task does not has a feature which will allow not to echo what user inputs, a necessity in case you are prompting for a password. As per the ant input task documentation &#8211; A regular complaint about this task is that it echoes characters to the console, this is a critical security defect, [...]]]></description>
			<content:encoded><![CDATA[<p>Ant input task does not has a feature which will allow not to echo what user inputs, a necessity in case you are prompting for a password. As per the <a href="http://ant.apache.org/manual/CoreTasks/input.html">ant input task documentation</a> &#8211; </p>
<blockquote><p>A regular complaint about this task is that it echoes characters to the console, this is a critical security defect, we must fix it immediately, etc, etc. We know it leaves something to be desired, but the problem is Java, not Ant. There is nothing we can do to stop the console echoing. </p></blockquote>
<p><span id="more-591"></span></p>
<p>But as of JDK 1.6, which allows you to <a href="http://java.sun.com/javase/6/docs/api/java/io/Console.html#readPassword%28%29">read password using console</a>, I have created following ant task which allows you to prompt a message to user and accept a password and it will be set as a ant property.</p>
<p>You can also use the same to accept normal input.</p>
<pre class="brush: java">

package com.shivprasad.anttask;
import java.io.Console;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

public class YetAnotherInputTask extends Task {

	private String outputproperty;
	private String message;
	private Boolean password;

	public void setPassword(String password) {
		this.password = Boolean.parseBoolean(password);
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void setOutputproperty(String outputproperty) {
		this.outputproperty = outputproperty;
	}

	@Override
	public void execute() throws BuildException {
		Console cons = System.console();
		String text=null;
		if (cons != null){
			if(password.booleanValue()){
				char[] passwd = cons.readPassword(&quot;[yainput] %s&quot;, message);
				text = new String(passwd);
			}else{
				text = cons.readLine(&quot;[yainput] %s&quot;, message);
			}
			getProject().setProperty(outputproperty, text);
		}
	}
}
</pre>
<p>You can download above as a jar.</p>
<p>Download <a href="http://byteco.de/files/ya-ant-input-task.jar">ya-ant-input-task.jar</a></p>
<p>In order to use it in ant, you will have to have the above jar as part of classpath. Then define, ant task -</p>
<pre class="brush: xml">

        &lt;taskdef name=&quot;yainput&quot; classname=&quot;com.shivprasad.anttask.YetAnotherInputTask&quot;&gt;
            &lt;classpath&gt;
                &lt;fileset dir=&quot;${dependency.lib}&quot;&gt;
                    &lt;include name=&quot;ya-ant-input-task.jar&quot;/&gt;
                &lt;/fileset&gt;
            &lt;/classpath&gt;
        &lt;/taskdef&gt;
</pre>
<p>For actually using it -</p>
<pre class="brush: xml">

    	&lt;yainput outputproperty=&quot;db.tns&quot; message=&quot;Enter the TNS entry for the database : &quot; password=&quot;false&quot; /&gt;
    	&lt;yainput outputproperty=&quot;db.password&quot; message=&quot;Enter the password for the database : &quot; password=&quot;true&quot; /&gt; 
</pre>
<p>The outputproperty is the property which will be available in ant after user enters the text.</p>
<p>Updated: Above code is licensed under : http://ant.apache.org/license.html</p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2009/05/01/ant-input-and-passwords/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Killing Java Process from Ant in Windows</title>
		<link>http://byteco.de/2009/04/30/killing-java-process-from-ant-in-windows/</link>
		<comments>http://byteco.de/2009/04/30/killing-java-process-from-ant-in-windows/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 16:38:37 +0000</pubDate>
		<dc:creator>shiv</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[pskill]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://byteco.de/?p=583</guid>
		<description><![CDATA[I wanted to write a ant script for one of the environment, which would perform following tasks in order which will be repeated 1. Take Latest Code 2. Compile 3. Create WAR 4. Undeploy currently installed WAR from tomcat 5. Stop the tomcat 6. Copy the WAR to tomcat webapps folder 7. Start the tomcat [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to write a ant script for one of the environment, which would perform following tasks in order which will be repeated<br />
	1. Take Latest Code<br />
	2. Compile<br />
	3. Create WAR<br />
	4. Undeploy currently installed WAR from tomcat<br />
	5. Stop the tomcat<br />
	6. Copy the WAR to tomcat webapps folder<br />
	7. Start the tomcat<br />
<span id="more-583"></span><br />
Starting the tomcat -</p>
<pre class="brush: xml">
	&lt;target name=&quot;tomcat.start&quot;&gt;
		 &lt;exec executable=&quot;${tomcat.home}/bin/startup.bat&quot; spawn=&quot;true&quot;&gt;
		 	&lt;env key=&quot;CATALINA_HOME&quot; value=&quot;${tomcat.home}&quot;/&gt;
		 &lt;/exec&gt;
		&lt;sleep seconds=&quot;10&quot;/&gt;
	&lt;/target&gt;
</pre>
<p>Stopping the tomcat -</p>
<p>I was facing some issues using the tomcat shutdown.bat as tomcat server was not stopping due to one of the application deployed was not getting stopped gracefully. And the next time tomcat tried to start it used to give &#8220;JVM_BIND Exception -Port already in use&#8221;.</p>
<p>As Windows doesn&#8217;t have a native kill command, I have used following which allowed me to kill any java process using ant.</p>
<p><a href="http://technet.microsoft.com/en-us/sysinternals/bb896683.aspx">PsKill</a> &#8211; Running PsKill with a process ID directs it to kill the process of that ID on the local computer.<br />
<a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html">jps</a> &#8211; The jps command will report the process ID of each JVM running on local computer.</p>
<pre class="brush: xml">
	&lt;target name=&quot;tomcat.stop&quot;&gt;
	    &lt;exec executable=&quot;${env.JAVA_HOME}/bin/jps&quot; output=&quot;pid.out.file&quot;/&gt;
		&lt;loadfile srcfile=&quot;pid.out.file&quot; property=&quot;pid.out&quot;&gt;
		  &lt;filterchain&gt;
				&lt;linecontains&gt;
				  &lt;contains value=&quot;Bootstrap&quot;/&gt;
				&lt;/linecontains&gt;
				&lt;tokenfilter&gt;
					&lt;deletecharacters chars=&quot;Bootstrap&quot;/&gt;
					&lt;trim/&gt;
					&lt;ignoreblank/&gt;
				&lt;/tokenfilter&gt;
				&lt;striplinebreaks/&gt;
		  &lt;/filterchain&gt;
		&lt;/loadfile&gt;
		&lt;echo&gt;Killing tomcat instance with PID - &quot;${pid.out}&quot;&lt;/echo&gt;
		&lt;exec executable=&quot;pskill&quot;&gt;
			&lt;arg value=&quot;${pid.out}&quot;/&gt;
		&lt;/exec&gt;
		&lt;delete file=&quot;pid.out.file&quot;/&gt;
	&lt;/target&gt;
</pre>
<p>The above way can be used to kill any java process using the ant. </p>
]]></content:encoded>
			<wfw:commentRss>http://byteco.de/2009/04/30/killing-java-process-from-ant-in-windows/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

