<?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>Vineet Manohar's blog &#187; java</title>
	<atom:link href="http://www.vineetmanohar.com/category/tech/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vineetmanohar.com</link>
	<description>Java, Web 2.0 and other Tech topics</description>
	<lastBuildDate>Wed, 23 Mar 2011 22:34:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally</title>
		<link>http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-7-try-with-auto-closable-resources</link>
		<comments>http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 20:30:58 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[java 7]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1590</guid>
		<description><![CDATA[Try with resources is a new feature in Java 7 which lets us write more elegant code by automatically closing resources like FileInputStream at the end of the try-block.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/' rel='bookmark' title='New Java 7 Feature: String in Switch support'>New Java 7 Feature: String in Switch support</a></li>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
<li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/';
var dzone_title = 'Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p><strong>Try with resources</strong> is a new feature in <a href="http://www.vineetmanohar.com/tag/java-7/">Java 7</a> which lets us write more elegant code by automatically closing resources like <code>FileInputStream</code> at the end of the try-block.</p>
<h3>Old Try Catch Finally</h3>
<p>Dealing with resources like InputStreams is painful when it comes to the<code> try-catch-finally blocks</code>. You need to declare the resources outside the <code>try</code> so that they are is accessible from <code>finally</code>, then you must initialize the variable to <code>null</code> and check for non-null when closing the resource in <code>finally</code>.</p>
<pre name="code" class="java">  File file = new File("input.txt");

   InputStream is = null;

   try {
     is = new FileInputStream(file);

     // do something with this input stream
     // ...

   }
   catch (FileNotFoundException ex) {
     System.err.println("Missing file " + file.getAbsolutePath());
   }
   finally {
     if (is != null) {
       is.close();
     }
   }
</pre>
<h3>Java 7: Try with resources</h3>
<p>With Java 7, you can create one or more &#8220;resources&#8221; in the try statement. A &#8220;resources&#8221; is something that implements the <code>java.lang.AutoCloseable</code> interface. This resource would be automatically closed and the end of the try block.</p>
<pre name="code" class="java">
File file = new File("input.txt");

try (InputStream is = new FileInputStream(file)) {
  // do something with this input stream
  // ...
}
catch (FileNotFoundException ex) {
  System.err.println("Missing file " + file.getAbsolutePath());
}</pre>
<h3>Exception handling</h3>
<p>If <strong>both</strong> the (explicit) try block and the (implicit) resource handling code throw an exception, then the try block exception is the one which will be thrown. The resource handling exception will be made available via the Throwable.getSupressed() method of the thrown exception. <a rel="nofollow" href="http://download.java.net/jdk7/archive/b123/docs/api/java/lang/Throwable.html#getSuppressed%28%29" target="_blank">Throwable.getSupressed()</a> is a new method added to the Throwable class since 1.7 specifically for this purpose. If there were no suppressed exceptions then this will return an empty array.</p>
<h3>Reference</h3>
<p><a rel="nofollow" href="http://download.java.net/jdk7/docs/technotes/guides/language/try-with-resources.html" target="_blank">http://download.java.net/jdk7/docs/technotes/guides/language/try-with-resources.html</a></p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/' rel='bookmark' title='New Java 7 Feature: String in Switch support'>New Java 7 Feature: String in Switch support</a></li>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
<li><a href='http://www.vineetmanohar.com/2010/04/how-to-configure-multiple-page-xml-files-in-seam-2-2/' rel='bookmark' title='How to configure multiple page.xml files in Seam 2.2'>How to configure multiple page.xml files in Seam 2.2</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New Java 7 Feature: String in Switch support</title>
		<link>http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-java-7-feature-string-in-switch-support</link>
		<comments>http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 20:56:18 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[java 7]]></category>
		<category><![CDATA[java7]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1579</guid>
		<description><![CDATA[One of the new features added in Java 7 is the capability to switch on a String. See an example of how to use this feature and the pros of this feature.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/' rel='bookmark' title='Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally'>Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally</a></li>
<li><a href='http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/' rel='bookmark' title='3 ways to serialize Java Enums'>3 ways to serialize Java Enums</a></li>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/';
var dzone_title = 'New Java 7 Feature: String in Switch support';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>One of the new features added in <a href="http://www.vineetmanohar.com/tag/java7/">Java 7</a> is the capability to switch on a <code>String</code>. </p>
<p><strong>With Java 6, or less<br />
</strong></p>
<pre name="code" class="java"> String color = "red";

 if (color.equals("red")) {
   System.out.println("Color is Red");
 } else if (color.equals("green")) {
   System.out.println("Color is Green");
 } else {
   System.out.println("Color not found");
 }
</pre>
<p><strong>With Java 7:</strong></p>
<pre name="code" class="java"> String color = "red";

 switch (color) {
 case "red":
   System.out.println("Color is Red");
   break;
 case "green":
   System.out.println("Color is Green");
   break;
 default:
   System.out.println("Color not found");
 }
</pre>
<h3>Conclusion</h3>
<p>The switch statement when used with a <code>String</code> uses the <code>equals()</code> method to compare the given expression to each value in the case statement and is therefore case-sensitive and will throw a <code>NullPointerException</code> if the expression is null. It is a small but useful feature which not only helps us write more readable code but the compiler will <a href="http://download.oracle.com/javase/7/docs/technotes/guides/language/strings-switch.html" target="_blank" rel="nofollow">likely</a> generate more efficient bytecode as compared to the<code> if-then-else</code> statement.</p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/' rel='bookmark' title='Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally'>Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally</a></li>
<li><a href='http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/' rel='bookmark' title='3 ways to serialize Java Enums'>3 ways to serialize Java Enums</a></li>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Java 7 on Mac OS X</title>
		<link>http://www.vineetmanohar.com/2011/03/installing-java-7-on-mac-os-x/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=installing-java-7-on-mac-os-x</link>
		<comments>http://www.vineetmanohar.com/2011/03/installing-java-7-on-mac-os-x/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 16:28:32 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[java 7]]></category>
		<category><![CDATA[java7]]></category>
		<category><![CDATA[jdk7]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mac osx]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1561</guid>
		<description><![CDATA[While you can download the binaries for Java 7 for Windows and Linux, you need to go through a tedious build and install instructions for Mac OS X. This article links to the official Mac OS X Java 7 instructions, and also lists some things that are likely to go wrong and how to avoid them.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/' rel='bookmark' title='New Java 7 Feature: String in Switch support'>New Java 7 Feature: String in Switch support</a></li>
<li><a href='http://www.vineetmanohar.com/2010/09/java-barcode-api/' rel='bookmark' title='Java Barcode API'>Java Barcode API</a></li>
<li><a href='http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/' rel='bookmark' title='Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally'>Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2011/03/installing-java-7-on-mac-os-x/';
var dzone_title = 'Installing Java 7 on Mac OS X';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>While you can download the binaries for <a href="http://www.vineetmanohar.com/tag/java7/">Java 7</a> for Windows and Linux from <a rel="nofollow" href="http://download.java.net/jdk7/" target="_blank">here</a>, the instructions for setting up Java 7 for Mac OS X are a lot more tedious.</p>
<p>Here are the <strong>official instructions</strong> for Mac OS X: <a href="http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port" target="_blank">http://wikis.sun.com/display/OpenJDK/Mac+OS+X+Port</a></p>
<p>You can follow the instructions line by line and get Java 7 installed on your machine. However, these are the things that might go wrong:</p>
<h3>Missing binaries in /bin</h3>
<p>The installation expects a bunch of binaries to be present in /bin. However, on my Mac OS X, these binaries were present in /usr/bin/. My workaround was to create symlinks in the /bin directories to make the build happy.</p>
<pre name="code" class="xml">cd /bin/
ln -s /usr/bin/sed
ln -s /usr/bin/grep</pre>
<p>Repeat the above for each binary that is reported missing in /bin.</p>
<h3>Missing jni.h</h3>
<p>Make sure that the version of <strong>XCode</strong> is <strong>3.2.5</strong> or more. I had a 3.2.4 version and that didn&#8217;t work.</p>
<h3>Building JTReg did not work due to a known bug</h3>
<p>It is mentioned in the JTReg build documentation but easy to miss it. The following does not work due to a know bug:</p>
<pre name="code" class="xml">make -C make
</pre>
<p>Instead try this:</p>
<pre name="code" class="xml">make -C make build
</pre>
<h3>Wrong installation directory in the official instructions</h3>
<p>The official instructions ask you to do this:</p>
<pre name="code" class="xml">mkdir -p ~/Library/Java/JavaVirtualMachines
cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk ~/Library/Java/JavaVirtualMachines
</pre>
<p>That didn&#8217;t work for me. Here&#8217;s what worked for me:</p>
<pre name="code" class="xml">mkdir -p /System/Library/Java/JavaVirtualMachines
cp -R build/macosx-universal/j2sdk-bundle/1.7.0.jdk /System/Library/Java/JavaVirtualMachines</pre>
<h3>Finally, setting up env vars</h3>
<p>The easiest way to make confirm that Java 7 is successfully installed is:</p>
<pre name="code" class="xml">/usr/libexec/java_home --version 1.7</pre>
<p>The output of the above should be:</p>
<pre name="code" class="xml">/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
</pre>
<p>Then type &#8216;java -version&#8217; against the above installation </p>
<pre name="code" class="xml">
/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java -version
openjdk version "1.7.0-internal"
OpenJDK Runtime Environment (build 1.7.0-internal-root_2011_03_16_17_41-b00)
OpenJDK 64-Bit Server VM (build 21.0-b03, mixed mode)
</pre>
<p>Since I use Java 1.6 on the same machine, I saved the 1.7 path as follows:</p>
<pre name="code" class="xml">export JAVA7_HOME=/System/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
</pre>
<p>This lets me conveniently switch to Java7, when I need to, and back:</p>
<pre name="code" class="xml">export JAVA_HOME=$JAVA7_HOME
</pre>
<p>Switch back:</p>
<pre name="code" class="xml">export JAVA_HOME=$JAVA6_HOME
</pre>
<h3>Using Java7</h3>
<p>Simplest way to use test Java7 is via command line</p>
<pre name="code" class="xml">export JAVA_HOME=$JAVA7_HOME
export PATH=$JAVA_HOME/bin:$PATH</pre>
<p><strong>Compile</strong></p>
<pre name="code" class="xml">javac Test.java</pre>
<p><strong>Run</strong></p>
<pre name="code" class="xml">java Test
</pre>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2011/03/new-java-7-feature-string-in-switch-support/' rel='bookmark' title='New Java 7 Feature: String in Switch support'>New Java 7 Feature: String in Switch support</a></li>
<li><a href='http://www.vineetmanohar.com/2010/09/java-barcode-api/' rel='bookmark' title='Java Barcode API'>Java Barcode API</a></li>
<li><a href='http://www.vineetmanohar.com/2011/03/java-7-try-with-auto-closable-resources/' rel='bookmark' title='Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally'>Java 7: New Feature &#8211; automatically close Files and resources in try-catch-finally</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2011/03/installing-java-7-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JBoss Tools bug: SeamListener not found</title>
		<link>http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jboss-tools-bug-seamlistener-not-found</link>
		<comments>http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/#comments</comments>
		<pubDate>Sat, 18 Dec 2010 07:25:11 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[jboss tools]]></category>
		<category><![CDATA[seam]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1396</guid>
		<description><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/';
var dzone_title = 'JBoss Tools bug: SeamListener not found';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
Overview If you use JBoss Tools Plugin for Eclipse to deploy apps to JBoss 5.1 container and get a &#8220;SeamListener not found&#8221;, this post provides a simple workaround. I deployed a webapp to JBoss 5.1 container from Eclipse using JBoss Tools plugin. The app failed to start with the following error: 19:01:14,762 WARN [JAXWSDeployerHookPreJSE] Cannot [...]
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/05/maven-cargo-jboss/' rel='bookmark' title='Maven Cargo JBoss'>Maven Cargo JBoss</a></li>
<li><a href='http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/' rel='bookmark' title='Securing a JBoss web application'>Securing a JBoss web application</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/';
var dzone_title = 'JBoss Tools bug: SeamListener not found';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<h3>Overview</h3>
<p>
If you use <a href="http://www.vineetmanohar.com/tag/jboss/">JBoss</a> Tools Plugin for Eclipse to deploy apps to JBoss 5.1 container and get a  &#8220;<a href="http://www.vineetmanohar.com/tag/seam/">Seam</a>Listener not found&#8221;, this post provides a simple workaround.
</p>
<p>I deployed a webapp to JBoss 5.1 container from <a href="http://www.vineetmanohar.com/tag/eclipse/">Eclipse</a> using JBoss Tools plugin. The app failed to start with the following error:</p>
<pre name="code" class="java">19:01:14,762 WARN  [JAXWSDeployerHookPreJSE] Cannot load servlet class: org.jboss.seam.servlet.SeamResourceServlet
19:01:14,787 INFO  [TomcatDeployment] deploy, ctxPath=/hcf
19:01:15,143 ERROR [[/hcf]] Error configuring application listener of class org.jboss.seam.servlet.SeamListener
java.lang.ClassNotFoundException: org.jboss.seam.servlet.SeamListener
 at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
 at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:262)
 at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:256)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3859)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4393)
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
 at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
 at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
 at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
 at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
 at $Proxy38.start(Unknown Source)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
 at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
 at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
 at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
 at org.jboss.system.ServiceController.start(ServiceController.java:460)
 at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
 at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
 at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
 at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
 at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
 at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
 at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
19:01:15,196 ERROR [[/hcf]] Skipped installing application listeners due to previous error(s)
19:01:15,196 ERROR [StandardContext] Error listenerStart
19:01:15,196 ERROR [StandardContext] Context [/hcf] startup failed due to previous errors
19:01:15,201 ERROR [AbstractKernelController] Error installing to Start: name=jboss.web.deployment:war=/hcf state=Create mode=Manual requiredState=Installed
org.jboss.deployers.spi.DeploymentException: URL file:/C:/software/jboss-5.1.0.GA/server/default/tmp/5c4o12w-udpgi-gf7dk40e-1-gf7dli4l-9o/hcf.war/ deployment failed
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:331)
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
 at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
 at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
 at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
 at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
 at $Proxy38.start(Unknown Source)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
 at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
 at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
 at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
 at org.jboss.system.ServiceController.start(ServiceController.java:460)
 at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
 at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
 at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
 at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
 at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
 at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
 at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
19:01:15,209 ERROR [AbstractKernelController] Error installing to Real: name=vfsfile:/C:/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1286220891669/deploy/hcf.war/ state=PreReal mode=Manual requiredState=Real
org.jboss.deployers.spi.DeploymentException: URL file:/C:/software/jboss-5.1.0.GA/server/default/tmp/5c4o12w-udpgi-gf7dk40e-1-gf7dli4l-9o/hcf.war/ deployment failed
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:331)
 at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)
 at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)
 at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)
 at org.jboss.web.deployers.WebModule.start(WebModule.java:97)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
 at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
 at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
 at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
 at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)
 at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
 at $Proxy38.start(Unknown Source)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)
 at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
 at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
 at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
 at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
 at org.jboss.system.ServiceController.start(ServiceController.java:460)
 at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
 at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
 at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
 at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
 at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
 at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
 at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
 at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
 at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
 at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
 at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
 at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
 at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
19:01:15,229 WARN  [HDScanner] Failed to process changes
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

*** DEPLOYMENTS IN ERROR: Name -&gt; Error

vfsfile:/C:/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1286220891669/deploy/hcf.war/ -&gt; org.jboss.deployers.spi.DeploymentException: URL file:/C:/software/jboss-5.1.0.GA/server/default/tmp/5c4o12w-udpgi-gf7dk40e-1-gf7dli4l-9o/hcf.war/ deployment failed

DEPLOYMENTS IN ERROR:
 Deployment "vfsfile:/C:/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1286220891669/deploy/hcf.war/" is in error due to the following reason(s): org.jboss.deployers.spi.DeploymentException: URL file:/C:/software/jboss-5.1.0.GA/server/default/tmp/5c4o12w-udpgi-gf7dk40e-1-gf7dli4l-9o/hcf.war/ deployment failed

 at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:993)
 at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:939)
 at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)
 at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:369)
 at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
 at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
</pre>
<p>This seemed to be a bug, as the above class is contained in the jboss-seam.jar, which I included in the classpath via the following <a href="http://www.vineetmanohar.com/tag/maven/">maven snippet</p>
<pre name="code" class="xml">&lt;dependency&gt;
 &lt;groupId&gt;org.jboss.seam&lt;/groupId&gt;
 &lt;artifactId&gt;jboss-seam&lt;/artifactId&gt;
 &lt;version&gt;2.2.0.GA&lt;/version&gt;
 &lt;/dependency&gt;</pre>
<p>I confirmed that the jar was not present in the deployed app, by going to the &#8220;Server&#8221; tab in eclipse and right-clicking on my app and &#8220;Explore&#8221;. The explore option launched a new window and listed the actual deployed app. I confirmed that the jboss-seam.jar was not present. Your deployment directory will be something like this:</p>
<pre name="code" class="xml">C:\workspace\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_5.1_Runtime_Server1286220891669\deploy\hcf.war
</pre>
<p>Upon Googling, I found that this is due to a <a href="https://jira.jboss.org/browse/JBIDE-6596" target="_blank">known bug</a> in JBoss Tools.</p>
<p>This issue has apparently been fixed in 3.2.0 M1.</p>
<p>Here &#8220;hcf&#8221; is the name of my app.</p>
<h3>Workaround</h3>
<p>By hit and trial, I found a simple workaround. After you deploy your  webapp, simply copy the missing jar to the &#8220;lib&#8221; directory of the  deployed app and restart Jboss.</p>
<p><strong>Wrong location</strong></p>
<p>You will find the file &#8216;jboss-seam-2.2.0.GA.jar&#8217; in this directory.</p>
<pre name="code" class="xml">C:\workspace\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_5.1_Runtime_Server1286220891669\deploy\hcf.war</pre>
<p><strong>Correct </strong><strong>location</strong></p>
<pre name="code" class="xml">C:\workspace\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_5.1_Runtime_Server1286220891669\deploy\hcf.war\WEB-INF\lib
</pre>
<p>Move the seam jar from the wrong location to the correct location.  Restart Jboss after moving the file, and the error should go away.</p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/05/maven-cargo-jboss/' rel='bookmark' title='Maven Cargo JBoss'>Maven Cargo JBoss</a></li>
<li><a href='http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/' rel='bookmark' title='Securing a JBoss web application'>Securing a JBoss web application</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing a JBoss web application</title>
		<link>http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=securing-a-jboss-web-application</link>
		<comments>http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 23:18:09 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[basic auth]]></category>
		<category><![CDATA[jboss]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[web application]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1517</guid>
		<description><![CDATA[This articles describes how to secure a Java web application in JBoss using BASIC authentication.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/03/implementing-context-senstive-permissions-and-authorization-in-jsf-seam/' rel='bookmark' title='Implementing context senstive permissions and authorization in JSF Seam'>Implementing context senstive permissions and authorization in JSF Seam</a></li>
<li><a href='http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/' rel='bookmark' title='JBoss Tools bug: SeamListener not found'>JBoss Tools bug: SeamListener not found</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/';
var dzone_title = 'Securing a JBoss web application';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>This articles describes how to secure a Java web application in JBoss using BASIC authentication.</p>
<h3>Step1: Edit web.xml in your application</h3>
<p>Edit the web.xml file in your webapp at the following location.</p>
<pre class="xml" name="code">WEB-INF/web.xml</pre>
<p>Edit your web.xml and put the following contents (generally towards the bottom of the file)</p>
<pre class="xml" name="code">&lt;web-app&gt;
....

 &lt;security-constraint&gt;
  &lt;web-resource-collection&gt;
   &lt;web-resource-name&gt;All resources&lt;/web-resource-name&gt;
   &lt;description&gt;Protects all resources&lt;/description&gt;
   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/web-resource-collection&gt;

  &lt;auth-constraint&gt;
   &lt;role-name&gt;myrole&lt;/role-name&gt;
  &lt;/auth-constraint&gt;
 &lt;/security-constraint&gt;

 &lt;security-role&gt;
  &lt;role-name&gt;myrole&lt;/role-name&gt;
 &lt;/security-role&gt;

 &lt;login-config&gt;
  &lt;auth-method&gt;BASIC&lt;/auth-method&gt;
  &lt;realm-name&gt;Authorized access only.&lt;/realm-name&gt;
 &lt;/login-config&gt;
&lt;/web-app&gt;</pre>
<p>This is a way of telling the container to restrict all URLs to any user with the role &#8216;<em>myrole</em>&#8216;.</p>
<h3>Step 2: Create jboss-web.xml in your application</h3>
<p>Edit or create the jboss-web.xml file in your webapp at the following location.</p>
<pre class="xml" name="code">WEB-INF/jboss-web.xml</pre>
<p>Put the following contents:</p>
<pre class="xml" name="code">&lt;jboss-web&gt;
 &lt;security-domain&gt;java:/jaas/myappname&lt;/security-domain&gt;
&lt;/jboss-web&gt;</pre>
<p>This tells JBoss to use application policy &#8216;<em>myappname&#8217;</em> for this application.</p>
<h3>Step 3: Create Application policy on JBoss server</h3>
<p>We now need to define the application policy &#8216;<em>myappname</em>&#8216; on JBoss server.</p>
<p>Edit the login-config.xml file in the JBoss server directory at the following location.</p>
<pre class="xml" name="code">jboss/server/default/conf/login-config.xml</pre>
<p>Edit the contents of login-config.xml and add an application policy as follows:</p>
<pre class="xml" name="code">&lt;policy&gt;
...

&lt;!-- application policy for myappname --&gt;
&lt;application-policy name="myappname"&gt;
 &lt;authentication&gt;
  &lt;login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"&gt;
   &lt;module-option name="usersProperties"&gt;props/users.properties&lt;/module-option&gt;
   &lt;module-option name="rolesProperties"&gt;props/roles.properties&lt;/module-option&gt;
  &lt;/login-module&gt;
 &lt;/authentication&gt;
&lt;/application-policy&gt;
&lt;/policy&gt;</pre>
<p>This tells JBoss to user &#8216;UsersRolesLoginModule&#8217; which uses property files to store users and roles.</p>
<h3>Step 4: Create users on JBoss server</h3>
<p>Now we create a new user with the role &#8216;myrole&#8217;.</p>
<h4>Create a new User</h4>
<p>Edit the users.properties file used by your application policy in Step 3.</p>
<pre class="xml" name="code">jboss/server/default/conf/props/users.properties</pre>
<p>Add a line to create a new user as follows.</p>
<pre class="xml" name="code">myuser=mypassword</pre>
<h4>Roles</h4>
<p>Finally, we assign the role &#8216;myrole&#8217; to the user &#8216;myuser&#8217;. Edit the following file</p>
<h4>Create a new role</h4>
<p>Edit the roles.properties file used by your application policy in Step 3.</p>
<pre class="xml" name="code">jboss/server/default/conf/props/roles.properties</pre>
<p>Add a line to create a assign the role &#8216;myrole&#8217; to &#8216;myuser&#8217; as follows.</p>
<pre class="xml" name="code">myuser=myrole</pre>
<h3>Test your settings</h3>
<p>Restart the JBoss server and deploy your application. When you access your application, you should see a basic authentication popup.</p>
<p><img class="alignnone size-full wp-image-1519" title="jboss-basic-auth" src="http://www.vineetmanohar.com/wp-content/uploads/2010/11/jboss-basic-auth1.png" alt="" width="641" height="176" /></p>
<p>If your setup is correct, you should be able to login using &#8216;myuser&#8217; and  &#8216;mypassword&#8217; as defined in the Step 4.</p>
<h3>Conclusion</h3>
<p>This approach is equivalent to defining users, passwords and roles in tomcat-users.xml. While this is an easy approach and helps you get started, a real production web application should not store its passwords unencrypted on disk. We used BASIC authentication in this example. For production quality applications, you should use <a href="http://docs.jboss.org/jbossas/guides/webguide/r2/en/html/ch05.html">DIGEST</a>, FORM or CLIENT-CERT.</p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/03/implementing-context-senstive-permissions-and-authorization-in-jsf-seam/' rel='bookmark' title='Implementing context senstive permissions and authorization in JSF Seam'>Implementing context senstive permissions and authorization in JSF Seam</a></li>
<li><a href='http://www.vineetmanohar.com/2010/12/jboss-tools-bug-seamlistener-not-found/' rel='bookmark' title='JBoss Tools bug: SeamListener not found'>JBoss Tools bug: SeamListener not found</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/11/securing-a-jboss-web-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access to www.w3.org DTDs blocked from Java</title>
		<link>http://www.vineetmanohar.com/2010/11/w3-org-dtds-blocked-from-java-http-500/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=w3-org-dtds-blocked-from-java-http-500</link>
		<comments>http://www.vineetmanohar.com/2010/11/w3-org-dtds-blocked-from-java-http-500/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 01:59:08 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[w3c]]></category>
		<category><![CDATA[wget]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1494</guid>
		<description><![CDATA[While parsing an XML file, I discovered that www.w3.org blocks requests to certain resources originating from the Java program, identified by the User-Agent. If your XML refers to w3.org DTDs, you might see an error like this: [java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent]. 

This is a known issue. The URLs have been deliberately blocked by w3.org due to 'abusive' use by Java programs.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li>
<li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/11/w3-org-dtds-blocked-from-java-http-500/';
var dzone_title = 'Access to www.w3.org DTDs blocked from Java';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>I was trying to parse an XML file with Java <a href="http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/" target="_blank">JAXB</a>. The XML file had the following header at the beginning of the file.</p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE appspec [
 &lt;!ENTITY % HTMLlat1 PUBLIC
 "-//W3C//ENTITIES Latin 1 for XHTML//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent"&gt;
 &lt;!ENTITY % HTMLspec PUBLIC
 "-//W3C//ENTITIES Special for XHTML//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent"&gt;
 %HTMLlat1;
 %HTMLspec;
]&gt;</pre>
<p>The program failed with the following error:<br />
<strong>Server returned HTTP response code: 500 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent</strong></p>
<p>Full stacktrace:</p>
<pre name="code" class="java">[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Could not read the xml, make sure that it is a valid xml and it validates against the schema

Server returned HTTP response code: 500 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Could not read the xml, make sure that it is a valid xml and it validates against the schema
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not read the xml, make sure that it is a valid xml and it validates against the schema
        at org.clickframes.mavenplugin.ClickframesGenPlugin.readProject(ClickframesGenPlugin.java:246)
        at org.clickframes.mavenplugin.ClickframesGenPlugin.execute(ClickframesGenPlugin.java:126)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
Caused by: javax.xml.bind.UnmarshalException
 - with linked exception:
[java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent]
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:197)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:174)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:225)
        at org.clickframes.AppspecJaxbWrapper.readAppspecType(AppspecJaxbWrapper.java:53)
        at org.clickframes.AppspecReader.readProject(AppspecReader.java:54)
        at org.clickframes.mavenplugin.ClickframesGenPlugin.readProject(ClickframesGenPlugin.java:244)
        ... 20 more
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1252)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.startPE(XMLDTDScannerImpl.java:722)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.skipSeparator(XMLDTDScannerImpl.java:2069)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDecls(XMLDTDScannerImpl.java:2032)
        at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.scanDTDInternalSubset(XMLDTDScannerImpl.java:377)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1141)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1090)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:977)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
        ... 25 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34 seconds
[INFO] Finished at: Fri Oct 29 17:18:58 EDT 2010
[INFO] Final Memory: 17M/177M
[INFO] ------------------------------------------------------------------------</pre>
<p>The  program complained about not being able to download the file from  www.w3.org. I tried to view the file in Firefox and was able to view it  successfully. My hypothesis at that point was that w3.org is allowing  Firefox but blocking Java. I confirmed that using wget and manually  setting the User-Agent.</p>
<h3>Using wget with User-Agent set to Firefox</h3>
<p>You can set the user-agent using the -U option in wget</p>
<pre name="code" class="java">wget http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent -U "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"
--11:24:08--  http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
Resolving www.w3.org... 128.30.52.37
Connecting to www.w3.org|128.30.52.37|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11775 (11K) [application/xml-external-parsed-entity]
Saving to: `xhtml-lat1.ent'
100%[======================================================================================================================&gt;] 11,775      --.-K/s   in 0.07s
11:24:08 (157 KB/s) - `xhtml-lat1.ent' saved [11775/11775]</pre>
<h3>Using wget with User-Agent set to Java</p>
<pre name="code" class="java">
wget http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent -U "Java/1.6.0_20"
--11:24:17--  http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent
Resolving www.w3.org... 128.30.52.37
Connecting to www.w3.org|128.30.52.37|:80... connected.
HTTP request sent, awaiting response... 500 Server Error
11:24:48 ERROR 500: Server Error.</h3>
</pre>
<p>The above verified that www.w3.org was blocking the request from Java.</p>
<h3>Conclusion</h3>
<p>W3.org blocks requests to certain resources originating from the Java program, identified by the User-Agent header &#8216;Java/1.6.0_20&#8242;. This is a known issue. The URLs have been deliberately blocked by w3.org due to &#8216;abusive&#8217; use by Java programs. Read the full story here: <a href="http://www.w3.org/2005/06/blog/systeam/2008/02/08/w3c_s_excessive_dtd_traffic" target="_blank">W3C&#8217;s Excessive DTD Traffic</a>.</p>
<p>The bottom line is that you, or your program, should download and cache a copy of this resource and not hit w3.org with a request to the same static resource over and over. Respect the <a href="http://www.vineetmanohar.com/2010/10/java-expiry-date-header/" target="_blank">Expiry date HTTP header</a>.</p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/03/cache-java-webapps-with-squid-reverse-proxy/' rel='bookmark' title='Cache Java webapps with Squid Reverse Proxy'>Cache Java webapps with Squid Reverse Proxy</a></li>
<li><a href='http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/' rel='bookmark' title='3 ways to run Java main from Maven'>3 ways to run Java main from Maven</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/11/w3-org-dtds-blocked-from-java-http-500/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Spring Quartz code snippets for beginners</title>
		<link>http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spring-quartz-code-snippets-for-beginners</link>
		<comments>http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 19:19:38 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[quartz]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1263</guid>
		<description><![CDATA[Add cronjob like capability to Java web applications in 4 simple steps using Spring and Quartz. This article outlines the steps needed for scheduling, with code snippets for each step.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/' rel='bookmark' title='Spring classpath scan breaks when migrating from JBoss4 to JBoss5'>Spring classpath scan breaks when migrating from JBoss4 to JBoss5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/';
var dzone_title = 'Spring Quartz code snippets for beginners';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<h3>Overview</h3>
<p>Some applications need to run periodic jobs in the background. On linux/unix systems, background processes can be run using the &#8220;cronjob&#8221; scheduling service. In Java web applications, you can add scheduling to any app in 4 simple steps using Spring and Quartz. This article outlines the steps needed for scheduling, with code  snippets required for each step.</p>
<h3>Step 1: web.xml</h3>
<p>To initialize Spring in your webapp, add this snippet to your web.xml file. If you are already using Spring, you probably already have this in your web.xml.</p>
<pre name="code" class="xml">&lt;!-- Initialize Spring --&gt;
&lt;listener&gt;
 &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
&lt;/listener&gt;</pre>
<h3>Step 2: applicationContext.xml snippet</h3>
<p>There are 3 concepts when configuring your scheduled jobs:</p>
<p>1) <strong>The Job</strong>: the java code that you want to run in the background periodically</p>
<p>2) <strong>A Trigge</strong>r: a trigger adds scheduling information to your job. There are different types of triggers (e.g. SimpleTrigger, CronTrigger). They differ in the way you specify scheduling information. For example, CronTrigger takes a cronexpression, whereas SimpleTrigger takes a repeatInterval.</p>
<p>3) <strong>The Scheduler</strong>: this is the actual service which runs in the background and invokes &#8216;triggers&#8217;. You can register multiple triggers with this service.</p>
<p>Add this snippet to your spring xml file.</p>
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
 "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
&lt;beans&gt;

 &lt;!-- The 'Scheduler': quartz scheduler --&gt;
 &lt;bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"&gt;
  &lt;!-- list of triggers registered with the scheduler --&gt;
  &lt;property name="triggers"&gt;
   &lt;list&gt;
    &lt;!-- Trigger1: JobExample using CronTrigger --&gt;
    &lt;bean id="jobDetailTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"&gt;
     &lt;!-- job class --&gt;
     &lt;property name="jobDetail"&gt;
      &lt;bean class="org.springframework.scheduling.quartz.JobDetailBean"&gt;
       &lt;!-- CHANGE THIS to the actual implementation class (see step 4)  --&gt;
       &lt;property name="jobClass" value="com.vineetmanohar.example.quartz.JobExample" /&gt;
      &lt;/bean&gt;
     &lt;/property&gt;

     &lt;!-- job schedule: every 5 minutes: CHANGE THIS --&gt;
     &lt;property name="cronExpression" value="0 0/30 * * * ?" /&gt;
    &lt;/bean&gt;

    &lt;!-- Trigger2: JobExample2 using SimpleTrigger --&gt;
    &lt;bean class="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;
     &lt;property name="jobDetail"&gt;
      &lt;bean&gt;
       &lt;!-- CHANGE THIS to the actual implementation class (see step 4)  --&gt;
       &lt;property name="jobClass" value="com.vineetmanohar.example.quartz.JobExample2" /&gt;
      &lt;/bean&gt;
     &lt;/property&gt;

     &lt;!-- wait 4 minutes after startup --&gt;
     &lt;property name="startDelay" value="240000" /&gt;

     &lt;!-- every 1 min (60 sec) --&gt;
     &lt;property name="repeatInterval" value="60000" /&gt;
    &lt;/bean&gt;
   &lt;/list&gt;
  &lt;/property&gt;
 &lt;/bean&gt;

&lt;/beans&gt;
</pre>
<h3>Step 3: pom.xml snippet</h3>
<p>If you are using maven, add this to your pom.xml to add spring and quartz dependency to your project.</p>
<pre name="code" class="xml">&lt;project&gt;
 &lt;dependencies&gt;
  &lt;dependency&gt;
   &lt;groupId&gt;org.opensymphony.quartz&lt;/groupId&gt;
   &lt;artifactId&gt;quartz&lt;/artifactId&gt;
   &lt;version&gt;1.6.1&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;2.5&lt;/version&gt;
  &lt;/dependency&gt;

  &lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
   &lt;version&gt;2.5&lt;/version&gt;
  &lt;/dependency&gt;
 &lt;/dependencies&gt;
&lt;/project&gt;</pre>
<h3>Step 4: Java code snippet</h3>
<p>Finally, write the actual implementation. Make sure that job class you specified in step 2 points to this file.</p>
<pre name="code" class="java">
package com.vineetmanohar.example.quartz.JobExample;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class JobExample extends QuartzJobBean {
  protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException {
   System.out.println("Job invoked at : " + new java.util.Date());

   // TODO: implement the job here
 }
}</pre>
<h3>Cron expression</h3>
<p>The format of cron expression is &lt;Seconds&gt; &lt;Minutes&gt; &lt;Hours&gt; &lt;Day-of-Month&gt; &lt;Month&gt; &lt;Day-of-Week&gt; &lt;Year (optional field)&gt;. For example:</p>
<p>
<strong>Every 30 minutes</strong>
</p>
<pre name="code" class="xml">0 0/30 * * * ?</pre>
<p>See full reference documentation <a href="http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson06.html">here</a>.</p>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/04/spring-classpath-scan-issue-jboss5/' rel='bookmark' title='Spring classpath scan breaks when migrating from JBoss4 to JBoss5'>Spring classpath scan breaks when migrating from JBoss4 to JBoss5</a></li>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/04/ejb3-jpa-error-when-migrating-from-jboss-version-4-to-5/' rel='bookmark' title='EJB3 JPA error when migrating from JBoss version 4 to 5'>EJB3 JPA error when migrating from JBoss version 4 to 5</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Barcode API</title>
		<link>http://www.vineetmanohar.com/2010/09/java-barcode-api/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-barcode-api</link>
		<comments>http://www.vineetmanohar.com/2010/09/java-barcode-api/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 20:24:03 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[barcode]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[zxing]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1321</guid>
		<description><![CDATA[This article demonstrates how to read and write bar codes from a Java program. We use the open source library "zxing" which supports many different types of bar code including the 2D QRCode, used by mobile apps. It can even read a barcode embedded somewhere in the page in a busy text document.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/' rel='bookmark' title='How to copy bean properties with a single line of code'>How to copy bean properties with a single line of code</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/calling-static-methods-from-el/' rel='bookmark' title='Calling a static method from EL'>Calling a static method from EL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/09/java-barcode-api/';
var dzone_title = 'Java Barcode API';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<div id="attachment_1328" class="wp-caption alignright" style="width: 225px"><img class="size-full wp-image-1328" title="QR Code &quot;9780201750799&quot;" src="http://www.vineetmanohar.com/wp-content/uploads/2010/09/qrcode_97802017507991.png" alt="QR Code &quot;9780201750799&quot;" width="215" height="215" /><p class="wp-caption-text">QR Code for &quot;9780201750799&quot;</p></div>
<h3>Overview</h3>
<p>Originally Barcodes were 1D representation of data using width and spacing of bars. Common bar code types are UPC barcodes which are seen on product packages. There are 2D barcodes as well (they are still called Barcodes even though they don&#8217;t use bars). A common example of 2D bar code is QR code (shown on right) which is commonly used by mobile phone apps. You can read history and more info about <a href="http://en.wikipedia.org/wiki/Barcode" target="_blank">Barcodes on Wikipedia</a>.</p>
<p>There is an open source Java library called &#8216;zxing&#8217; (Zebra Crossing) which can read and write many differently types of bar codes formats. I tested zxing and it was able to read a barcode embedded in the middle of a 100 dpi grayscale busy text document!</p>
<p>This article demonstrates how to use zxing to read and write bar codes from a Java program.</p>
<h3>Getting the library</h3>
<p>It would be nice if the jars where hosted in a maven repo somewhere, but there is no plan to do that (see <a href="http://code.google.com/p/zxing/issues/detail?id=88" target="_blank">Issue 88</a>). Since I could not find the binaries available for download, I decided to download the source code and build the binaries, which was actually quite easy.</p>
<p>The source code of the library is available on <a href="http://code.google.com/p/zxing/" target="_blank">Google Code</a>. At the time of writing, 1.6 is the latest version of zxing.</p>
<p>1. Download the release file <a href="http://code.google.com/p/zxing/downloads/detail?name=ZXing-1.6.zip&amp;can=2&amp;q=">ZXing-1.6.zip </a>(which contains of mostly source files) from <a href="http://code.google.com/p/zxing/downloads/list" target="_blank">here</a>.<br />
2. Unzip the file in a local directory<br />
3. You will need to build 2 jar files from the downloaded source: core.jar, javase.jar</p>
<p><strong>Building core.jar</strong></p>
<pre name="code" class="xml">cd zxing-1.6/core
mvn install
</pre>
<p>This will install the jar in your local maven repo. Though not required, you can also deploy it to your company&#8217;s private repo by using mvn:deploy or by manually uploading it to your maven repository.</p>
<p>There is an ant script to build the jar as well.</p>
<p><strong>Building javase.jar</strong></p>
<p>Repeat the same procedure to get javase.jar</p>
<pre name="code" class="xml">cd zxing-1.6/javase
mvn install
</pre>
<h3>Including the libraries in your project</h3>
<p>If you are using ant, add the core.jar and javase.jar to your project&#8217;s classpath.</p>
<p>If you are using maven, add the following to your pom.xml.</p>
<pre name="code" class="xml">
&lt;dependencies&gt;
 &lt;dependency&gt;
  &lt;groupId&gt;com.google.zxing&lt;/groupId&gt;
  &lt;artifactId&gt;core&lt;/artifactId&gt;
  &lt;version&gt;1.6-SNAPSHOT&lt;/version&gt;
 &lt;/dependency&gt;

 &lt;dependency&gt;
  &lt;groupId&gt;com.google.zxing&lt;/groupId&gt;
  &lt;artifactId&gt;javase&lt;/artifactId&gt;
  &lt;version&gt;1.6-SNAPSHOT&lt;/version&gt;
 &lt;/dependency&gt;
&lt;dependencies&gt;
</pre>
<p>Once you have the jars included in your project&#8217;s classpath, you are now ready to read and write barcodes from java!</p>
<h3>Reading a Bar Code from Java</h3>
<p>You can read the bar code by first loading the image as an input stream and then calling this utility method.</p>
<pre name="code" class="java">InputStream barCodeInputStream = new FileInputStream("file.jpg");
BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);

LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap);

System.out.println("Barcode text is " + result.getText());
</pre>
<h3>Writing a Bar Code from Java</h3>
<p>You can encode a small text string as follows:</p>
<pre name="code" class="java">String text = "98376373783"; // this is the text that we want to encode

int width = 400;
int height = 300; // change the height and width as per your requirement

// (ImageIO.getWriterFormatNames() returns a list of supported formats)
String imageFormat = "png"; // could be "gif", "tiff", "jpeg" 

BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, new FileOutputStream(new File("qrcode_97802017507991.png")));
</pre>
<p>In the above example, the bar code for &#8220;97802017507991&#8243; is written to the file &#8220;<a href="http://www.vineetmanohar.com/wp-content/uploads/2010/09/qrcode_97802017507991.png" target="_blank">qrcode_97802017507991.png</a>&#8221; (click to see the output).</p>
<h3>JavaDocs and Documentation</h3>
<p>The Javadocs are part of the downloaded zip file. You can find a list of supported bar code formats in the Javadocs. Open the following file to see the javadocs.</p>
<pre name="code" class="xml">zxing-1.6/docs/javadoc/index.html</pre>
<h3>Reference</h3>
<ul>
<li><a href="http://code.google.com/p/zxing/" target="_blank">ZXing Google Code project</a></li>
<li><a href="http://en.wikipedia.org/wiki/Barcode" target="_blank">Barcode on Wikipedia</a></li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2010/05/2-ways-to-convert-java-map-to-string/' rel='bookmark' title='2 ways to convert Java Map to String'>2 ways to convert Java Map to String</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/' rel='bookmark' title='How to copy bean properties with a single line of code'>How to copy bean properties with a single line of code</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/calling-static-methods-from-el/' rel='bookmark' title='Calling a static method from EL'>Calling a static method from EL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/09/java-barcode-api/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>How to display maven project version in your webapp</title>
		<link>http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-display-maven-project-version-in-your-webapp</link>
		<comments>http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 02:43:20 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[maven plugin]]></category>
		<category><![CDATA[maven replacer plugin]]></category>
		<category><![CDATA[pom.xml]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1260</guid>
		<description><![CDATA[This article describes how to display the version of your maven project in your web application.
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li>
<li><a href='http://www.vineetmanohar.com/2009/06/the-plugin-orgcodehausmojoselenium-maven-plugin-does-not-exist-or-no-valid-version-could-be-found/' rel='bookmark' title='The plugin &#8216;org.codehaus.mojo:selenium-maven-plugin&#8217; does not exist or no valid version could be found'>The plugin &#8216;org.codehaus.mojo:selenium-maven-plugin&#8217; does not exist or no valid version could be found</a></li>
<li><a href='http://www.vineetmanohar.com/2009/11/tweet-your-builds-with-maven-twitter-plugin/' rel='bookmark' title='Tweet your builds with Maven Twitter Plugin'>Tweet your builds with Maven Twitter Plugin</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/';
var dzone_title = 'How to display maven project version in your webapp';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<h3>Overview</h3>
<p>Sometimes it is useful to display the version of your web application, typically in the footer area of  the web page. By displaying the version information, one can quickly determine which version of the app is running or users can use it for error reporting purposes. Displaying the version is also useful when there are frequent <a href="http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/" target="_blank">automated releases using the maven release plugin</a> and it is hard to track which version is actually deployed on a server. Here&#8217;s an illustration of how version can be displayed in the footer.</p>
<p><img style="border-top: 1px solid #cccccc; margin: 10px 0pt; background-color: #eeeeee; padding: 2px;" title="footer-version" src="http://www.vineetmanohar.com/wp-content/uploads/2010/09/footer-version.png" alt="Project Version shown in footer" width="252" height="20" /></p>
<p>This article describes how to display the version of your maven project in your web application.</p>
<h3>Step 1: Create a View file to display the version</h3>
<p>First we will create a view file which will display the version. The view file could be a JSP, HTML, XHTML, a Facelet or any format depending on your stack. In this example, we will create a JSP file which will print the version somewhere in the page. However, instead of the hardcoding an actual version, we put a special token &#8216;PROJECT_VERSION&#8217;. We don&#8217;t want to hard code the version information as it will change from release to release. The special token will be replaced with actual maven project version when the app is packaged.</p>
<p>Create the following  jsp.</p>
<pre name="code" class="xml">src/main/webapp/version.jsp</pre>
<p>Here&#8217;s a simple file which displays the version information.</p>
<pre name="code" class="html">&lt;html&gt;
  &lt;body&gt;Project version is &lt;i&gt;PROJECT_VERSION&lt;/i&gt;&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>Step 2: Add snippet to pom.xml</h3>
<p>The maven replacer plugin is a simple and useful plugin which can replaces tokens in file of your choice. Add the following snippet of code to your pom.xml. (Note: you can also use the maven resources plugin&#8217;s filter feature to accomplish this).</p>
<pre name="code" class="xml">&lt;project&gt;
 &lt;build&gt;
  &lt;plugins&gt;
   &lt;!-- replace version in file --&gt;
   &lt;plugin&gt;
    &lt;groupId&gt;com.google.code.maven-replacer-plugin&lt;/groupId&gt;
    &lt;artifactId&gt;maven-replacer-plugin&lt;/artifactId&gt;
    &lt;version&gt;1.3.2&lt;/version&gt;
    &lt;executions&gt;
     &lt;execution&gt;
      &lt;!-- the replace should happen before the app is packaged --&gt;
      &lt;phase&gt;prepare-package&lt;/phase&gt;
      &lt;goals&gt;
       &lt;goal&gt;replace&lt;/goal&gt;
      &lt;/goals&gt;
     &lt;/execution&gt;
    &lt;/executions&gt;

    &lt;configuration&gt;
     &lt;includes&gt;
      &lt;!-- replace the token in this file --&gt;
      &lt;include&gt;target/myproject/version.jsp&lt;/include&gt;
     &lt;/includes&gt;
     &lt;regex&gt;false&lt;/regex&gt;
     &lt;!-- the name of the token to replace --&gt;
     &lt;token&gt;PROJECT_VERSION&lt;/token&gt;
     &lt;!-- replace it with the maven project version --&gt;
     &lt;value&gt;${project.version}&lt;/value&gt;
    &lt;/configuration&gt;
   &lt;/plugin&gt;
  &lt;/plugins&gt;
 &lt;/build&gt;
&lt;/project&gt;
</pre>
<p>To test the above setup, you can run the following command:</p>
<pre name="code" class="xml">mvn prepare-package</pre>
<p>Navigate to the following file.</p>
<pre name="code" class="xml">target/myproject/version.jsp
</pre>
<p>The contents of this file will look something like this (assuming that your project version is 1.0-SNAPSHOT):</p>
<pre name="code" class="xml">&lt;html&gt;
  &lt;body&gt;Project version is &lt;i&gt;<strong>1.0-SNAPSHOT</strong>&lt;/i&gt;&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>When your application ships, the version.jsp file will always have the correct version. You can see the version by invoking the version.jsp page.</p>
<pre name="code" class="xml">http://localhost:8080/myproject/version.jsp
</pre>
<p><strong>Note:</strong></p>
<ul>
<li>Your view file does not have to be a JSP, it can be any a view file suitable to your stack. It could be part of your footer which could be included at the bottom in each page.</li>
<li>The special token can be changed from PROJECT_VERSION to another value of your choice, just change it in the view file as well as the pom.xml</li>
<li>Instead of having the version contained in a view file, you could have the version in a properties file or a message bundle and then display a message from the message bundle on the view</li>
<li><span style="color: red;"><strong>Update</strong></span> &#8211; you can also accomplish the replacement using the filtering feature of <a href="http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html">maven resource plugin</a></li>
</ul>
<h3>References</h3>
<ul>
<li><a href="http://code.google.com/p/maven-replacer-plugin/wiki/UsageGuide" target="_blank">Maven Replace Plugin on Google Code</a></li>
<li>Filtering feature documentation of <a href="http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html">Maven Resource Plugin</a></li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/10/how-to-automate-project-versioning-and-release-with-maven/' rel='bookmark' title='How to automate project versioning and release with Maven'>How to automate project versioning and release with Maven</a></li>
<li><a href='http://www.vineetmanohar.com/2009/06/the-plugin-orgcodehausmojoselenium-maven-plugin-does-not-exist-or-no-valid-version-could-be-found/' rel='bookmark' title='The plugin &#8216;org.codehaus.mojo:selenium-maven-plugin&#8217; does not exist or no valid version could be found'>The plugin &#8216;org.codehaus.mojo:selenium-maven-plugin&#8217; does not exist or no valid version could be found</a></li>
<li><a href='http://www.vineetmanohar.com/2009/11/tweet-your-builds-with-maven-twitter-plugin/' rel='bookmark' title='Tweet your builds with Maven Twitter Plugin'>Tweet your builds with Maven Twitter Plugin</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to copy bean properties with a single line of code</title>
		<link>http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=copy-map-bean-properties</link>
		<comments>http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 05:10:31 +0000</pubDate>
		<dc:creator>vineet</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[jaxb]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=1152</guid>
		<description><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/';
var dzone_title = 'How to copy bean properties with a single line of code';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
This article shows how to copy multiple properties from one bean to another with a single line of code, even if the property names in the source and target beans are different. Copying properties from one bean is quite common especially if you are working with a lot of POJOs, for example working with JAXB [...]
Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/' rel='bookmark' title='Spring Quartz code snippets for beginners'>Spring Quartz code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/calling-static-methods-from-el/' rel='bookmark' title='Calling a static method from EL'>Calling a static method from EL</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;"><script type="text/javascript">
<!--
var dzone_url = 'http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/';
var dzone_title = 'How to copy bean properties with a single line of code';
var dzone_blurb = '';
var dzone_style = '1';
//-->
</script>
<script language="javascript" src="http://widgets.dzone.com/widgets/zoneit.js"></script> 
</div>
<p>This article shows how to copy multiple properties from one bean to another with a single line of code, even if the property names in the source and target beans are different.</p>
<p>Copying properties from one bean is quite common especially if you are working with a lot of POJOs, for example working with <a target="_blank" href="http://www.vineetmanohar.com/tag/jaxb/">JAXB</a> objects. Lets walk through the following example where we want to copy all properties from the User object -&gt; SystemUser object</p>
<h3>Example: source and target objects</h3>
<pre name="code" class="java">// source object that we want to copy the properties from
public class User {
    private String first;
    private String last;
    private String address1;
    private String city;
    private String state;
    private String zip;
    private String phone;

    // getters and setters
    // ...
}

// target object that we want to copy the properties to
public class SystemUser {
    private String firstName;
    private String lastName;
    private String phone;
    private String addressLine1;
    private String addressLine2;
    private String city;
    private String state;
    private String zip;

    // getters and setters
    // ...
}
</pre>
<h3>Example continued: Preparing the objects</h3>
<pre name="code" class="java">// initializing the source object with example values
User user = new User();
user.setFirst("John");
user.setLast("Smith");
user.setAddress1("555 Lincoln St");
user.setCity("Washington");
user.setState("DC");
user.setZip("00000");
user.setPhone("555-555-5555");

// creating an empty target object
SystemUser systemUser = new SystemUser();
</pre>
<h3>Approach 1: Traditional code for copying properties</h3>
<pre name="code" class="java">systemUser.setFirstName(user.getFirst());
systemUser.setLastName(user.getLast());
systemUser.setPhone(user.getPhone());
systemUser.setAddressLine1(user.getAddress1());
systemUser.setAddressLine2(user.getAddress2());
systemUser.setCity(user.getCity());
systemUser.setState(user.getState());
systemUser.setZipcode(user.getZip());
</pre>
<h3>Approach 2: Single line code for copying properties</h3>
<pre name="code" class="java">
copyProperties(user, systemUser, "first firstName", "last lastName", "phone",
               "address1 addressLine1", "address2 addressLine2", "city", "state", "zip zipcode");
</pre>
<p><strong>Parameters</strong></p>
<ol>
<li><strong>user</strong> &#8211; the source object</li>
<li><strong>systemUser</strong> &#8211; the target object</li>
<li><strong>first firstName</strong> &#8211; indicates that the &#8220;first&#8221; property of the source object should be copied to the &#8220;firstName&#8221; property of the target object</li>
<li><strong>last lastName</strong> &#8211; indicates that the &#8220;last&#8221;  property of the source object should be copied to the &#8220;lastName&#8221;  property of the target object</li>
<li><strong>phone</strong> &#8211; indicates that the &#8220;phone&#8221;  property of the source object should be copied to the &#8220;phone&#8221;  property of the target object</li>
<li> &#8230;. and so on</li>
</ol>
<p>The underlying code uses Apache Commons BeanUtils code to copy the property value from the source to the destination.</p>
<p>You can download the copyProperties code from <a href="http://code.google.com/p/vineetmanohar/source/browse/trunk/src/main/java/com/vineetmanohar/util/BeanPropertyCopyUtil.java" target="_blank">Google Code</a>. Simply copy the code to your project. The code requires apache BeanUtils. If you are using maven, you can get BeanUtils by adding the following to your pom.xml</p>
<pre name="code" class="xml"> &lt;!-- for maven only, add this to your pom to get BeanUtils, needed by the copyProperties code --&gt;
 &lt;dependency&gt;
   &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
   &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
   &lt;version&gt;1.8.3&lt;/version&gt;
 &lt;/dependency&gt;</pre>
<h2>References</h2>
<ul>
<li><a href="http://code.google.com/p/vineetmanohar/source/browse/trunk/src/main/java/com/vineetmanohar/util/BeanPropertyCopyUtil.java" target="_blank">copyProperties Java code from Google Code</a></li>
<li><a target="_blank" href="http://commons.apache.org/beanutils/">Apache Commons BeanUtils</li>
</ul>
<p>Related posts:<ol>
<li><a href='http://www.vineetmanohar.com/2009/09/jaxb-code-snippets-for-beginners/' rel='bookmark' title='JAXB code snippets for beginners'>JAXB code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/10/spring-quartz-code-snippets-for-beginners/' rel='bookmark' title='Spring Quartz code snippets for beginners'>Spring Quartz code snippets for beginners</a></li>
<li><a href='http://www.vineetmanohar.com/2010/08/calling-static-methods-from-el/' rel='bookmark' title='Calling a static method from EL'>Calling a static method from EL</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vineetmanohar.com/2010/08/copy-map-bean-properties/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

