<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Java/JEE</title>
	<atom:link href="http://numberformat.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://numberformat.wordpress.com</link>
	<description>Information that Helps!</description>
	<lastBuildDate>Thu, 23 May 2013 03:39:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='numberformat.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Java/JEE</title>
		<link>http://numberformat.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://numberformat.wordpress.com/osd.xml" title="Java/JEE" />
	<atom:link rel='hub' href='http://numberformat.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Log4j2 Configuration with Multiple Web Apps</title>
		<link>http://numberformat.wordpress.com/2013/02/16/log4j2-configuration-with-multiple-web-applications/</link>
		<comments>http://numberformat.wordpress.com/2013/02/16/log4j2-configuration-with-multiple-web-applications/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 04:58:42 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[log4j]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5723</guid>
		<description><![CDATA[This page describes how to use the new Log4j 2 Framework within multiple web applications deployed to a single web container with a shared log4j jar. Full downloadable source for this page is available here. Corrections and enhancements are welcome, fork, change and push back to GitHub. Background Historically Java Web Application WAR files have [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5723&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to use the new Log4j 2 Framework within multiple web applications deployed to a single web container with a shared log4j jar.</p>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130216">available here</a>. Corrections and enhancements are welcome, fork, change and push back to GitHub.</div>
<h3>Background</h3>
<p>Historically Java Web Application WAR files have included their own copy of the log4j jar files. This allowed multiple applications to co exist and use their own log4j configuration. However as web applications get smaller and focused smaller tasks (possibly RESTful applications) you will find yourself deploying multiple WAR files to the same web container. It doesnt make too much sense to have each WAR contain its own copy of log4j.jar.</p>
<p>Ideally it would be nice to have one log4j.jar file at the container level that each application can share. However, its not as simple as moving it out of the WAR file because of the way log4j configures itself.</p>
<p>This page covers a method described in the log4j 2 homepage.</p>
<blockquote><p>
Place the logging jars in the container&#8217;s classpath and use the default ClassLoaderContextSelector. Include the Log4jContextListener in each web application. Each ContextListener can be configured to share the same configuration used at the container or they can be individually configured. If status logging is set to debug in the configuration there will be output from when logging is initialized in the container and then again in each web application.
</p></blockquote>
<h3>Requirements</h3>
<ul>
<li>Java 5 or later</li>
<li>Maven 2 or later</li>
<li>Log4j 2</li>
<li>Apache Tomcat 6</li>
</ul>
<h3>Procedure</h3>
<p>We will create 2 apps and deploy them on Tomcat and verify that they are both logging to the console as well as individual files specified in their configs.</p>
<p>Any one who worked with log4j 1.x knows that this was a pain to setup with multiple web applications. Log4j 2 makes it a lot easier.</p>
<ul>
<li>web-log-test &#8211; outputs to SYSOUT and ${user.home}/APPBASE/logs/web-log-test.log</li>
<li>web-log-test2 &#8211; outputs to SYSOUT and ${user.home}/APPBASE/logs/web-log-test2.log</li>
</ul>
<h3>Project Configuration</h3>
<p>pom.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;web-log-test&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
	&lt;pluginRepositories&gt;
	  &lt;pluginRepository&gt;
	    &lt;id&gt;numberformat-releases&lt;/id&gt;
	    &lt;url&gt;https://raw.github.com/numberformat/20130213/master/repo&lt;/url&gt;
	  &lt;/pluginRepository&gt;
	&lt;/pluginRepositories&gt;
	  
  &lt;dependencies&gt;
  	&lt;dependency&gt;
  		&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
  		&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
  		&lt;version&gt;2.5&lt;/version&gt;
  		&lt;scope&gt;provided&lt;/scope&gt;
  	&lt;/dependency&gt;
  	&lt;dependency&gt;
  		&lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
  		&lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
  		&lt;version&gt;2.0-beta4&lt;/version&gt;
  		&lt;scope&gt;provided&lt;/scope&gt;
  	&lt;/dependency&gt;
  	&lt;dependency&gt;
  		&lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
  		&lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
  		&lt;version&gt;2.0-beta4&lt;/version&gt;
  		&lt;scope&gt;provided&lt;/scope&gt;
  	&lt;/dependency&gt;
  	&lt;dependency&gt;
  		&lt;groupId&gt;org.apache.logging.log4j.adapters&lt;/groupId&gt;
  		&lt;artifactId&gt;log4j-web&lt;/artifactId&gt;
  		&lt;version&gt;2.0-beta4&lt;/version&gt;
  		&lt;scope&gt;provided&lt;/scope&gt;
  	&lt;/dependency&gt;
  	&lt;dependency&gt;
  		&lt;groupId&gt;org.apache.logging.log4j.adapters&lt;/groupId&gt;
  		&lt;artifactId&gt;log4j-1.2-api&lt;/artifactId&gt;
  		&lt;version&gt;2.0-beta4&lt;/version&gt;
  		&lt;scope&gt;provided&lt;/scope&gt;
  	&lt;/dependency&gt;
  &lt;/dependencies&gt;
  
	&lt;build&gt;
		&lt;finalName&gt;web-log-test&lt;/finalName&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0.2&lt;/version&gt;
				&lt;configuration&gt;
					&lt;source&gt;1.6&lt;/source&gt;
					&lt;target&gt;1.6&lt;/target&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
	 		&lt;plugin&gt; 			
	 			&lt;groupId&gt;github.numberformat&lt;/groupId&gt;
	 			&lt;artifactId&gt;blog-plugin&lt;/artifactId&gt;
	 			&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
	 			&lt;configuration&gt;
				&lt;gitUrl&gt;https://github.com/numberformat/20130216&lt;/gitUrl&gt;
	 			&lt;/configuration&gt;
	        &lt;executions&gt;
	          &lt;execution&gt;
	            &lt;id&gt;1&lt;/id&gt;
	            &lt;phase&gt;site&lt;/phase&gt;
	            &lt;goals&gt;
	              &lt;goal&gt;generate&lt;/goal&gt;
	            &lt;/goals&gt;	            
	          &lt;/execution&gt;
	        &lt;/executions&gt;
	 		&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;  
&lt;/project&gt;</pre>
<h3>Web Configuration</h3>
<p>The following sets up the log4jContextListener by specifying the log4jConfiguration parameter pointing it to the location of your config.</p>
<p>You may specify a file in the classpath or an absolute location on your system. If you want to keep this file in your WEB-INF folder then you can extend the class and customize it to suit your requirement.</p>
<p>vi src/main/webapp/WEB-INF/web.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
	id=&quot;WebApp_ID&quot; version=&quot;2.5&quot;&gt;
	&lt;display-name&gt;Sample Web Application&lt;/display-name&gt;

	&lt;context-param&gt;   
	   &lt;param-name&gt;log4jConfiguration&lt;/param-name&gt;
	   &lt;param-value&gt;log4j2.xml&lt;/param-value&gt;
	&lt;/context-param&gt;
	
	&lt;listener&gt;
		&lt;listener-class&gt;org.apache.logging.log4j.core.web.Log4jContextListener&lt;/listener-class&gt;
	&lt;/listener&gt;

&lt;/web-app&gt;
</pre>
<h3>Log4j Configuration</h3>
<p>In log4j 2 the name of the config file should be log4j2.xml. For this page our configuration file is very simple. See the log4j 2 site for further details about other configuration options.</p>
<p>vi src/main/resources/log4j2.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;configuration strict=&quot;true&quot;&gt;
&lt;!-- include this to enable log4j internal debug messages: status=&quot;debug&quot; --&gt;
&lt;appenders&gt;
	&lt;appender type=&quot;Console&quot; name=&quot;STDOUT&quot;&gt;
		&lt;layout type=&quot;PatternLayout&quot; pattern=&quot;%d %-5p %c - %m%n&quot;/&gt;
	&lt;/appender&gt;
	&lt;appender type=&quot;File&quot; name=&quot;File&quot; fileName=&quot;${sys:user.home}/APPBASE/logs/web-log-test.log&quot;&gt;
		&lt;layout type=&quot;PatternLayout&quot;&gt;
			&lt;pattern&gt;%d %-5p %c - %m%n&lt;/pattern&gt;
		&lt;/layout&gt;
	&lt;/appender&gt;
&lt;/appenders&gt;
 
&lt;loggers&gt;
	&lt;logger name=&quot;org.apache.jsp&quot; level=&quot;debug&quot;&gt;
		&lt;appender-ref ref=&quot;File&quot;/&gt;
	&lt;/logger&gt;
	&lt;root level=&quot;trace&quot;&gt;
		&lt;appender-ref ref=&quot;STDOUT&quot;/&gt;
	&lt;/root&gt;
&lt;/loggers&gt;
 
&lt;/configuration&gt;</pre>
<h3>Test Page</h3>
<p>We can test the application by using a simple jsp.</p>
<p>vi src/main/webapp/snoop.jsp</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;HTML&gt;
&lt;HEAD&gt;
	&lt;TITLE&gt;JSP snoop page&lt;/TITLE&gt;
	&lt;%@ page import=&quot;org.apache.log4j.*&quot; %&gt; 
&lt;/HEAD&gt;
&lt;BODY&gt;

&lt;H1&gt;WebApp JSP Log4j Test&lt;/H1&gt;

&lt;h3&gt;Apache Log4j Logging&lt;/h3&gt;

&lt;%
Logger logger = Logger.getLogger(getClass());
if(&quot;submit&quot;.equals((String)request.getParameter(&quot;log&quot;))) {
	String text = (String)request.getParameter(&quot;text&quot;);
	String level = (String)request.getParameter(&quot;level&quot;);
	logger.log(Level.toLevel(level), text);
}
%&gt;

&lt;form action=&quot;&quot; method=&quot;GET&quot;&gt;
&lt;TABLE border=&quot;1&quot;&gt;
&lt;TR valign=top&gt;
	&lt;TH align=left&gt;Level&lt;/TH&gt;
	&lt;TH align=left&gt;Test Message&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR valign=top&gt;
	&lt;TD&gt;
		&lt;select name=&quot;level&quot;&gt;		
			&lt;option value=&quot;ERROR&quot;&gt;ERROR&lt;/option&gt;
			&lt;option value=&quot;WARN&quot;&gt;WARN&lt;/option&gt;
			&lt;option value=&quot;INFO&quot; selected=&quot;selected&quot;&gt;INFO&lt;/option&gt;
			&lt;option value=&quot;DEBUG&quot;&gt;DEBUG&lt;/option&gt;
			&lt;option value=&quot;TRACE&quot;&gt;TRACE&lt;/option&gt;
		&lt;/select&gt;
	&lt;/TD&gt;
	&lt;TD&gt;
		&lt;input name=&quot;text&quot; type=&quot;text&quot; size=&quot;35&quot; value=&quot;&lt;%=new java.util.Date()%&gt;&quot;&gt;
		&lt;input name=&quot;log&quot; type=&quot;submit&quot; value=&quot;submit&quot;&gt;	
	&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/form&gt;

&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
<p>Finally copy the following files to the &#8220;tomcat6/lib&#8221; folder. You may obtain these files from the .m2 folder after the project is built. Or you can get them from the apache download site. (at the time of this writing only beta4 was the latest available)</p>
<ul>
<li>log4j-core-2.0.jar &#8211; core libarary.</li>
<li>log4j-api-2.0.jar &#8211; API Shell Classes to be used by your code</li>
<li>log4j-web-2.0.jar &#8211; Servlet Listener to initialize Logging</li>
<li>log4j-1.2-api-2.0.jar &#8211; log4j 1.x support for legacy code that still uses it.</li>
</ul>
<h3>Build and Run the Application</h3>
<p>perform the build by typing:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
mvn clean compile package
</pre>
<p>You will notice that the WAR file does not contain any log4j jars. </p>
<p>Copy the war file into your tomcat6/webapps folder.</p>
<p>navigate to: <a href="http://localhost:8080/web-log-test/snoop.jsp">http://localhost:8080/web-log-test/snoop.jsp</a></p>
<h3>Modify and Deploy the Second Application</h3>
<p>For the second application we want to modify the log4j2.xml to write the log to ${user.home}/APPBASE/logs/web-log-test2.log</p>
<p>Rename the WAR file to web-log-test2.war deploy to the same server.</p>
<p>Restart and test.</p>
<p>Using a new TAB, navigate to: <a href="http://localhost:8080/web-log-test2/snoop.jsp">http://localhost:8080/web-log-test2/snoop.jsp</a></p>
<p>Verify that the logs are being written the console and to each file independently.</p>
<h3>Appendix</h3>
<p><a href="http://numberformat.wordpress.com/2012/01/14/log4j-property-file-default/">log4j 1.x configuration available here</a></p>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130216">available here</a>. </div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5723/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5723/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5723&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2013/02/16/log4j2-configuration-with-multiple-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Create Custom Maven Plugin</title>
		<link>http://numberformat.wordpress.com/2013/02/13/create-custom-maven-plugin/</link>
		<comments>http://numberformat.wordpress.com/2013/02/13/create-custom-maven-plugin/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 06:07:20 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[velocity]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5692</guid>
		<description><![CDATA[This page describes how to create a custom maven plugin. Full downloadable source for this page is available here. Corrections and enhancements are welcome, fork, change and push back to GitHub. Problem Statement This site contains hundreds pages with small demo java projects embedded in its pages. While working on this site I came across [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5692&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to create a custom maven plugin. </p>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130213">available here</a>. Corrections and enhancements are welcome, fork, change and push back to GitHub.</div>
<h3>Problem Statement</h3>
<p>This site contains hundreds pages with small demo java projects embedded in its pages.</p>
<p>While working on this site I came across a few problems.</p>
<ol>
<li>How to reduce typo errors on the pages source code.</li>
<li>How to keep the blog page up to date after code fixes.</li>
</ol>
<p><strong>The solution</strong>: Have a custom maven plugin generate the blog page with source code automatically.  The plugin uses velocity template that contain the text of the blog page along with &#8220;#include&#8221; velocity directives that bring in the source code from the project.</p>
<h3>Implementation</h3>
<p>Follow these steps to create a custom plugin to generate HTML content from velocity templates.</p>
<p>Start by editing the pom.xml file to look like this.</p>
<p>vi pom.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

	&lt;groupId&gt;github.numberformat&lt;/groupId&gt;
	&lt;artifactId&gt;blog-plugin&lt;/artifactId&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
	&lt;packaging&gt;maven-plugin&lt;/packaging&gt;

	&lt;properties&gt;
		&lt;mavenVersion&gt;2.0.6&lt;/mavenVersion&gt;
	&lt;/properties&gt;

	&lt;pluginRepositories&gt;
	  &lt;pluginRepository&gt;
	    &lt;id&gt;numberformat-releases&lt;/id&gt;
	    &lt;url&gt;https://raw.github.com/numberformat/20130213/master/repo&lt;/url&gt;
	  &lt;/pluginRepository&gt;
	&lt;/pluginRepositories&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
			&lt;artifactId&gt;maven-plugin-api&lt;/artifactId&gt;
			&lt;version&gt;2.0&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.velocity&lt;/groupId&gt;
			&lt;artifactId&gt;velocity&lt;/artifactId&gt;
			&lt;version&gt;1.7&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
			&lt;artifactId&gt;maven-model&lt;/artifactId&gt;
			&lt;version&gt;${mavenVersion}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
			&lt;artifactId&gt;maven-artifact&lt;/artifactId&gt;
			&lt;version&gt;${mavenVersion}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
			&lt;artifactId&gt;maven-project&lt;/artifactId&gt;
			&lt;version&gt;${mavenVersion}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
			&lt;artifactId&gt;maven-core&lt;/artifactId&gt;
			&lt;version&gt;${mavenVersion}&lt;/version&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
	&lt;name&gt;Wordpress Page Generation Plugin&lt;/name&gt;
	&lt;description&gt;Generates a wordpress page for the project.&lt;/description&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0.2&lt;/version&gt;
				&lt;configuration&gt;
					&lt;source&gt;1.6&lt;/source&gt;
					&lt;target&gt;1.6&lt;/target&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
	 		&lt;plugin&gt; 			
	 			&lt;groupId&gt;github.numberformat&lt;/groupId&gt;
	 			&lt;artifactId&gt;blog-plugin&lt;/artifactId&gt;
	 			&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
	 			&lt;configuration&gt;
				&lt;gitUrl&gt;https://github.com/numberformat/20130213&lt;/gitUrl&gt;
	 			&lt;/configuration&gt;
	        &lt;executions&gt;
	          &lt;execution&gt;
	            &lt;id&gt;1&lt;/id&gt;
	            &lt;phase&gt;site&lt;/phase&gt;
	            &lt;goals&gt;
	              &lt;goal&gt;generate&lt;/goal&gt;
	            &lt;/goals&gt;	            
	          &lt;/execution&gt;
	        &lt;/executions&gt;
	 		&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;
&lt;/project&gt;</pre>
<p>The following file is the plugin implementation class.</p>
<p>BlogMojo.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package github.numberformat.plugin;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

/**
 * This is a simple plug-in that generates a blog page from a velocity
 * template. This allows developers to create very simple project documentation
 * pages for their projects. Developers would typically create a blog entry by
 * copying and pasting the HTML directly into the blog site.
 * 
 * @goal generate
 */
public class BlogMojo extends AbstractMojo {
	/**
	 * @parameter default-value=&quot;${basedir}&quot;
	 * @required
	 * @readonly
	 */
	private File basedir;

	/**
	 * Represents the date first published.
	 * 
	 * @parameter default-value=&quot;https://github.com/numberformat&quot;
	 * @required
	 * @readonly
	 */
	private String gitUrl;
	
	
	public void execute() throws MojoExecutionException {
		
		final File templateDir = basedir;
		final File targetBlog = new File(basedir, &quot;target/blog&quot;);

		if(new File(templateDir, &quot;src/blog/wordpress.vm&quot;).canRead()) {
			if(!targetBlog.exists()) {
				targetBlog.mkdirs();
			} else if(!targetBlog.isDirectory()) {
				throw new MojoExecutionException(&quot;Must be a directory: &quot; + targetBlog.getAbsolutePath());
			}
	
	        VelocityEngine ve = new VelocityEngine();
	        ve.setProperty(&quot;file.resource.loader.path&quot;, templateDir.getAbsolutePath());
	        ve.init();
        
	        Template t = ve.getTemplate( &quot;src/blog/wordpress.vm&quot; );
	        VelocityContext context = new VelocityContext();
	        context.put(&quot;blog_header&quot;, getHeader());
	        context.put(&quot;blog_footer&quot;, getFooter());
	        context.put(&quot;blog_git_url&quot;, gitUrl);
	        
	        FileWriter writer = null;
			try {
				writer = new FileWriter(new File(targetBlog, &quot;wordpress.html&quot;));
		        t.merge( context, writer );				
			} catch (IOException e) {
				throw new MojoExecutionException(e.getMessage());
			} finally {
				try{writer.close();}catch(Exception e){}				
			}
		}
	}


	private Object getFooter() {
		return &quot;&lt;div style=\&quot;font-size:13px;border:1px solid gray; &quot; +
				&quot;padding:5px;line-height:120%\&quot;&gt;Full downloadable source for &quot; +
				&quot;this page is &lt;a href=\&quot;&quot;+gitUrl+&quot;\&quot;&gt;available here&lt;/a&gt;. &quot; +
				&quot;&lt;/div&gt;&quot;;
	}

	private Object getHeader() {
		return &quot;&lt;div style=\&quot;font-size:13px;border:1px solid gray; &quot; +
				&quot;padding:5px;line-height:120%\&quot;&gt;Full downloadable source for &quot; +
				&quot;this page is &lt;a href=\&quot;&quot;+gitUrl+&quot;\&quot;&gt;available here&lt;/a&gt;. &quot; +
				&quot;Corrections and enhancements are welcome, fork, change and push &quot; +
				&quot;back to GitHub.&lt;/div&gt;&quot;;
	}
}
</pre>
<h3>Publish to Nexus or Website</h3>
<p>You may <a href="http://numberformat.wordpress.com/2011/05/18/nexus-repository/">deploy the plugin into a nexus repository a simple website</a>.</p>
<h3>Example Usage</h3>
<p>For demonstration purposes I have published the plugin to the following URL, you may use it in your project by including it in your pom.xml.</p>
<p>vi pom.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;testProject&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  &lt;pluginRepositories&gt;
    &lt;pluginRepository&gt;
      &lt;id&gt;numberformat-releases&lt;/id&gt;
      &lt;url&gt;https://raw.github.com/numberformat/20130213/master/repo&lt;/url&gt;
    &lt;/pluginRepository&gt;
  &lt;/pluginRepositories&gt;
  
  &lt;build&gt;
  	&lt;plugins&gt;
  		&lt;plugin&gt; 			
  			&lt;groupId&gt;github.numberformat&lt;/groupId&gt;
  			&lt;artifactId&gt;blog-plugin&lt;/artifactId&gt;
  			&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
	        &lt;executions&gt;
	          &lt;execution&gt;
	            &lt;id&gt;1&lt;/id&gt;
	            &lt;phase&gt;site&lt;/phase&gt;
	            &lt;goals&gt;
	              &lt;goal&gt;generate&lt;/goal&gt;
	            &lt;/goals&gt;	            
	          &lt;/execution&gt;
	        &lt;/executions&gt;
  		&lt;/plugin&gt;
  	&lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre>
<p>As you can see from the above the plugin to generate the wordpress page is hooked into the &#8220;site&#8221; phase of the build lifecycle.</p>
<h3>Velocity Template</h3>
<p>Save the file into: </p>
<p>src/blog/wordpress.vm </p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
#set( $foo = &quot;Velocity&quot; )
Hello $foo World!

(include sourcecode tag in square brackets around the include line below)
#include(&quot;src/main/java/App.java&quot;)
(include /sourcecode tag in square brackets around the include line above)
</pre>
<h3>Run the Plugin</h3>
<p>To run the plugin and you have specified the executions tag above just type </p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
mvn site
</pre>
<p>As an alternative if you don&#8217;t want to hook it into the maven lifecycle then just delete the &#8220;executions&#8221; tag above and run the plugin by typing:</p>
<p>To run the plugin just type </p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
mvn blog:generate
</pre>
<p>If you get a WARNING about plexus ignore it.</p>
<p>Upon successful build you can view the generated wordpress page in the target/blog folder of the project.</p>
<h3>Next Steps</h3>
<p>blog-plugin improvements:</p>
<ol>
<li>Enhance the plugin to generate pages in formats other than wordpress.</li>
<li>Have plugin insert headers or footers on the generated pages. (done)</li>
<li>Enhance the plugin to have blog pages contain a link to GitHub where visitors can simply checkout the project instead of copying and pasting source from the page. (done)</li>
</ol>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130213">available here</a>. </div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5692/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5692/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5692&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2013/02/13/create-custom-maven-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Convert UTF-8 Unicode to ASCII Latin 1</title>
		<link>http://numberformat.wordpress.com/2013/02/09/convert-utf-8-unicode-to-ascii-latin-1/</link>
		<comments>http://numberformat.wordpress.com/2013/02/09/convert-utf-8-unicode-to-ascii-latin-1/#comments</comments>
		<pubDate>Sat, 09 Feb 2013 23:19:01 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[utf-8]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5683</guid>
		<description><![CDATA[This page describes how to convert utf-8 or Unicode strings with diacritical characters or Unicode punctuation marks into Latin 1 encoding with minimal loss of information. Full downloadable source for this page is available here. Corrections and enhancements are welcome, fork, change and push back to GitHub. There is a 2 step process to get [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5683&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to convert utf-8 or Unicode strings with diacritical characters or Unicode punctuation marks into Latin 1 encoding with minimal loss of information. </p>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130209">available here</a>. Corrections and enhancements are welcome, fork, change and push back to GitHub.</div>
<p>There is a 2 step process to get this done.</p>
<h3>Step 1</h3>
<p>Use java.text.Normalizer to convert <a href="http://en.wikipedia.org/wiki/Diacritic">diacritical characters</a> with accents into ASCII characters.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
str = Normalizer.normalize(str, Form.NFD).replaceAll(&quot;\\p{InCombiningDiacriticalMarks}+&quot;, &quot;&quot;);
</pre>
<h3>Step 2</h3>
<p>Convert Symbols and punctuation marks into latin-1 equivalents.</p>
<p>Currently the best way to get this done is to search and replace as seen below.</p>
<h3>Sample Swing App</h3>
<p>The following app demonstrates how to convert Unicode to ASCII latin-1.</p>
<p>vi src/main/java/github/numberformat/utf/Norm.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package github.numberformat.utf;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.Normalizer;
import java.util.HashMap;
import java.util.Iterator;

import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Norm extends JFrame {
	private static final long serialVersionUID = 1L;

	private JComboBox normalizationTemplate;
	private JComboBox formComboBox;
	private JComponent paintingComponent;
	private HashMap&lt;String, Normalizer.Form&gt; formValues = new HashMap&lt;String, Normalizer.Form&gt;();
	private HashMap&lt;String, String&gt; templateValues = new HashMap&lt;String, String&gt;();

	public Norm() {
		init();
	}
	
	public void init() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle(&quot;UTF-8 to ASCII&quot;);
		
		formValues.put(&quot;NFC&quot;, Normalizer.Form.NFC);
		formValues.put(&quot;NFD&quot;, Normalizer.Form.NFD);
		formValues.put(&quot;NFKC&quot;, Normalizer.Form.NFKC);
		formValues.put(&quot;NFKD&quot;, Normalizer.Form.NFKD);
		
		formComboBox = new JComboBox();
		for (Iterator it = formValues.keySet().iterator(); it.hasNext();) {
			formComboBox.addItem((String) it.next());
		}
		templateValues.put(&quot;acute accent&quot;, &quot;\u2039touch&quot; + &quot;\u00e9\u2035&quot;);

		// text with ligature
		templateValues.put(&quot;ligature&quot;, &quot;a&quot; + &quot;\ufb03&quot; + &quot;ance&quot;);

		// text with the cedilla
		templateValues.put(&quot;cedilla&quot;, &quot;fa&quot; + &quot;\u00e7&quot; + &quot;ade&quot;);

		
		templateValues.put(&quot;half-width katakana&quot;,
				&quot;\uff81\uff6e\uff7a\uff9a\uff70\uff84&quot;);

		normalizationTemplate = new JComboBox();

		for (Iterator it = templateValues.keySet().iterator(); it.hasNext();) {
			normalizationTemplate.addItem((String) it.next());
		}
		
		JPanel controls = new JPanel();

		controls.setLayout(new BoxLayout(controls, BoxLayout.X_AXIS));
		controls.add(new Label(&quot;Normalization Form: &quot;));
		controls.add(formComboBox);
		controls.add(new Label(&quot;Normalization Template:&quot;));
		controls.add(normalizationTemplate);
		formComboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				paintingComponent.repaint();
			}
		});

		normalizationTemplate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				paintingComponent.repaint();
			}
		});

		
		getContentPane().add(getCenter(), BorderLayout.CENTER);
		getContentPane().add(controls, BorderLayout.SOUTH);
		pack();
		setVisible(true);

	}

	private JComponent getCenter() {
		if(paintingComponent != null) return paintingComponent;
		
		paintingComponent = new JComponent() {
			static final long serialVersionUID = -3725620407788489160L;

			public Dimension getSize() {
				return new Dimension(550, 200);
			}

			public Dimension getPreferredSize() {
				return new Dimension(550, 200);
			}

			public Dimension getMinimumSize() {
				return new Dimension(550, 200);
			}

			public void paint(Graphics g) {
				Graphics2D g2 = (Graphics2D) g;

				g2.setFont(new Font(&quot;Serif&quot;, Font.PLAIN, 20));
				g2.setColor(Color.BLACK);
				g2.drawString(&quot;Original string:&quot;, 100, 80);
				g2.drawString(&quot;Normalized string:&quot;, 100, 120);
				g2.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 24));

				// output of the original sample selected from the ComboBox

				String original_string = templateValues
						.get(normalizationTemplate.getSelectedItem());
				g2.drawString(original_string, 320, 80);

				// normalization and output of the normalized string

				String normalized_string = utf8ToLatin1(original_string);

				g2.drawString(normalized_string, 320, 120);
			}

			private String utf8ToLatin1(String original_string) {
				String normalized_string;
				java.text.Normalizer.Form currentForm = formValues
						.get(formComboBox.getSelectedItem());
				normalized_string = Normalizer.normalize(original_string,
						currentForm);

				normalized_string = normalized_string.replaceAll(
						&quot;\\p{InCombiningDiacriticalMarks}+&quot;, &quot;&quot;);

				String str = normalized_string;
				str = str
						.replaceAll(
								&quot;[\u00AB\u2034\u2037\u00BB\u02BA\u030B\u030E\u201C\u201D\u201E\u201F\u2033\u2036\u3003\u301D\u301E]&quot;,
								&quot;\&quot;&quot;);
				str = str.replaceAll(&quot;[\u02CB\u0300\u2035]&quot;, &quot;`&quot;);
				str = str.replaceAll(&quot;[\u02C4\u02C6\u0302\u2038\u2303]&quot;, &quot;^&quot;);
				str = str.replaceAll(&quot;[\u02CD\u0331\u0332\u2017]&quot;, &quot;_&quot;);
				str = str.replaceAll(
						&quot;[\u00AD\u2010\u2011\u2012\u2013\u2014\u2212\u2015]&quot;,
						&quot;-&quot;);
				str = str.replaceAll(&quot;[\u201A]&quot;, &quot;,&quot;);
				str = str.replaceAll(&quot;[\u0589\u05C3\u2236]&quot;, &quot;:&quot;);
				str = str.replaceAll(&quot;[\u01C3\u2762]&quot;, &quot;!&quot;);
				str = str.replaceAll(&quot;[\u203D]&quot;, &quot;?&quot;);
				str = str
						.replaceAll(
								&quot;[\u00B4\u02B9\u02BC\u02C8\u0301\u200B\u2018\u2019\u201B\u2032]&quot;,
								&quot;'&quot;);
				str = str.replaceAll(&quot;[\u27E6]&quot;, &quot;[&quot;);
				str = str.replaceAll(&quot;[\u301B]&quot;, &quot;]&quot;);
				str = str.replaceAll(&quot;[\u2983]&quot;, &quot;{&quot;);
				str = str.replaceAll(&quot;[\u2984]&quot;, &quot;}&quot;);
				str = str.replaceAll(&quot;[\u066D\u204E\u2217\u2731]&quot;, &quot;*&quot;);
				str = str.replaceAll(&quot;[\u00F7\u0338\u2044\u2060\u2215]&quot;, &quot;/&quot;);
				str = str.replaceAll(&quot;[\u20E5\u2216]&quot;, &quot;\\&quot;);
				str = str.replaceAll(&quot;[\u266F]&quot;, &quot;#&quot;);
				str = str.replaceAll(&quot;[\u066A\u2052]&quot;, &quot;%&quot;);
				str = str.replaceAll(&quot;[\u2039\u2329\u27E8\u3008]&quot;, &quot;&lt;&quot;);
				str = str.replaceAll(&quot;[\u203A\u232A\u27E9\u3009]&quot;, &quot;&gt;&quot;);
				str = str.replaceAll(&quot;[\u01C0\u05C0\u2223\u2758]&quot;, &quot;|&quot;);
				str = str.replaceAll(&quot;[\u02DC\u0303\u2053\u223C\u301C]&quot;, &quot;~&quot;);
				normalized_string = str;
				return normalized_string;
			}
		}; 
				
				
		return paintingComponent;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Norm();
	}

}
</pre>
<p>To run the app just type the following:</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn exec:java -Dexec.mainClass=github.numberformat.utf.Norm
</pre>
<div style="font-size:13px;border:1px solid gray;padding:5px;line-height:120%;">Full downloadable source for this page is <a href="https://github.com/numberformat/20130209">available here</a>. </div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5683/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5683&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2013/02/09/convert-utf-8-unicode-to-ascii-latin-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>JAX-WS Hello World Standalone / Tomcat / JBoss</title>
		<link>http://numberformat.wordpress.com/2012/11/07/jax-ws-hello-world/</link>
		<comments>http://numberformat.wordpress.com/2012/11/07/jax-ws-hello-world/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 04:07:39 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5450</guid>
		<description><![CDATA[The following page describes how to create a simple JAX-WS web service and run it under JBoss and Tomcat and as a standalone App. Background JAX-WS supports both traditional SOAP-RPC as well as the newer RESTful/JSON type services. Its a plug and play framework where the developer annotate their classes and the application server takes [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5450&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The following page describes how to create a simple JAX-WS web service and run it under JBoss and Tomcat and as a standalone App.</p>
<h3>Background</h3>
<p>JAX-WS supports both traditional SOAP-RPC as well as the newer RESTful/JSON type services. Its a plug and play framework where the developer annotate their classes and the application server takes care of the rest.</p>
<h3>Requirements</h3>
<ol>
<li>Java 6 or above</li>
<li>Tomcat 6 or JBoss 5</li>
<li>Maven 3</li>
</ol>
<h3>Interface</h3>
<p>vi src/main/java/server/HelloWorld.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package server;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld {
@WebMethod String getHelloWorldAsString(String name);
}
</pre>
<h3>Implementation</h3>
<p>vi src/main/java/server/HelloWorldImpl.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package server;

import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService(endpointInterface = &quot;server.HelloWorld&quot;)
public class HelloWorldImpl implements HelloWorld {
	@Override
	public String getHelloWorldAsString(String name) {
		return &quot;Hello World JAX-WS &quot; + name;
	}
	public static void main(String args[]) { // for test purposes only
		Endpoint.publish(&quot;http://localhost:9999/ws/hello&quot;, new HelloWorldImpl());		
	}	
}
</pre>
<h3>Client Application</h3>
<p>If you would like to test without generating the client application you can do the following.</p>
<p>vi HelloWorldApp.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import server.HelloWorld;

public class HelloWorldApp {
	
	public static void main(String args[]) throws Exception {
		URL url = new URL(&quot;http://localhost:9999/ws/hello?wsdl&quot;);
		QName qname = new QName(&quot;http://server/&quot;, &quot;HelloWorldImplService&quot;);	
		Service service = Service.create(url, qname);
                addDebugSupport(service); // optional (see method below)
		HelloWorld hello = service.getPort(HelloWorld.class);
		System.out.println(hello.getHelloWorldAsString(&quot;name&quot;));
	}
}
</pre>
<p>The following method allows for the incoming and outgoing SOAP messages to be logged. It requires HTMLTidy dependency</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
    &lt;dependency&gt;
        &lt;groupId&gt;jtidy&lt;/groupId&gt;
        &lt;artifactId&gt;jtidy&lt;/artifactId&gt;
        &lt;version&gt;4aug2000r7-dev&lt;/version&gt;
    &lt;/dependency&gt;
</pre>
<pre class="brush: java; gutter: false; title: ; notranslate">
private static void addDebugSupport(Service service) {
	service.setHandlerResolver(new HandlerResolver() {
		public List&lt;Handler&gt; getHandlerChain(PortInfo portInfo) {
			List&lt;Handler&gt; handlerChain = new ArrayList&lt;Handler&gt;();
			handlerChain.add(new SOAPHandler&lt;SOAPMessageContext&gt;() {
				public boolean handleFault(SOAPMessageContext context) {
					log(context);
					return true;
				}
				public boolean handleMessage(SOAPMessageContext context) {
					log(context);
					return true;
				}
				public void close(MessageContext context) {}
				public Set&lt;QName&gt; getHeaders() {return null;}
			});
			return handlerChain;
		}
		private void log(SOAPMessageContext smc) {
			Boolean outboundProperty = (Boolean) smc
					.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
			if(outboundProperty.booleanValue()) {
				logger.info(&quot;Outbound message:&quot;);					
			} else {
				logger.info(&quot;Inbound message:&quot;);
			}
			SOAPMessage message = smc.getMessage();
			try {
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				message.writeTo(baos);
				ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
				Tidy tidy = new Tidy();
				tidy.setXmlOut(true);
				tidy.setXmlTags(true);
				baos = new ByteArrayOutputStream();
				tidy.parse(bais, baos);
				logger.info(&quot;\n&quot; + new String(baos.toByteArray()));
			} catch (Exception e) {
				logger.error(&quot;Exception in handler: &quot; + e);
			}
		}
    });
}
</pre>
<h3>Package and Deploy the JAX-WS Web Service</h3>
<p>Create a sun-jaxws.xml file if you are planning to use the Reference Implementation. Otherwise skip it.</p>
<p>src/main/webapp/WEB-INF/sun-jaxws.xml</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;endpoints
  xmlns=&quot;http://java.sun.com/xml/ns/jax-ws/ri/runtime&quot;
  version=&quot;2.0&quot;&gt;
  &lt;endpoint
      name=&quot;HelloWorld&quot;
      implementation=&quot;server.HelloWorldImpl&quot;
      url-pattern=&quot;/hello&quot;/&gt;
&lt;/endpoints&gt;
</pre>
<p>The following is the way the web.xml file should look if you are using the Reference Implementation. Otherwise just skip to the JBoss section.</p>
<p>src/main/webapp/WEB-INF/web.xml</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, 
Inc.//DTD Web Application 2.3//EN&quot;
&quot;http://java.sun.com/j2ee/dtds/web-app_2_3.dtd&quot;&gt;
 
&lt;web-app&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;
                com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        &lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
        &lt;servlet-class&gt;
        	com.sun.xml.ws.transport.http.servlet.WSServlet
        &lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;hello&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;120&lt;/session-timeout&gt;
    &lt;/session-config&gt;
&lt;/web-app&gt;
</pre>
<h3>Run under Tomcat</h3>
<p>Tomcat 6 does not include the JAX-WS RI jars, instead download them from oracle and place them in the tomcat6/lib directory of your server or your WEB-INF/lib folder or the WAR file.</p>
<p>The following is a sample list: your version of JAX-WS can vary.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
gmbal-api-only.jar
management-api.jar
stax-ex.jar
streambuffer.jar
policy.jar
</pre>
<h3>Run under JBoss 5</h3>
<p>JBoss comes pre-installed with a JAX-WS implementation. No need to package the JAX-WS implementation in the war. Instead just put the following in the web.xml file and navigate to the following URL:</p>
<p><a href="http://127.0.0.1:8080/jaxwsTest/hello?wsdl">http://127.0.0.1:8080/jaxwsTest/hello?wsdl</a></p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
 &lt;servlet&gt;
  &lt;servlet-name&gt;HelloService&lt;/servlet-name&gt;
  &lt;servlet-class&gt;server.HelloWorldImpl&lt;/servlet-class&gt;
 &lt;/servlet&gt;
 &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;HelloService&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;
 &lt;/servlet-mapping&gt;
</pre>
<h3>JAX-WS Web Service Client</h3>
<p>To create a standalone client application use wsimport command provided by the JDK 6.</p>
<h3>Appendix: MockServer</h3>
<p>The following is an implementation of a mock server that could be used for testing.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package service;

import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.ws.Endpoint;

public class MockServer {

	private static final MockServer instance = new MockServer();
	
	private Map&lt;QName, String&gt; urlMap = new HashMap&lt;QName, String&gt;();
	
	private MockServer() {
		super();
		publish(&quot;DataManagerImplService&quot;, &quot;http://service/&quot;, getAvailablePort(), new DataManagerImpl());
	}

	private void publish(String serviceName, String uri, int port, Object implObject) {
		String url = &quot;http://localhost:&quot; + port + &quot;/ws/&quot; + serviceName + &quot;?wsdl&quot;;
		QName qname = new QName(uri, serviceName);
		Endpoint.publish(url, implObject);
		urlMap.put(qname, url);
	}
	
	public static MockServer getInstance() {
		return instance;
	}

	public URL getUrl(QName qname) {
		URL url = null;
		try {
			url = new URL(urlMap.get(qname));
		} catch (MalformedURLException e) {
		}
		return url;
	}
	
	private static int getAvailablePort() {
		int count = 0;
		int port = 0;
		while (true) {
			try {
				ServerSocket s = new ServerSocket(0);
				port = s.getLocalPort();
				s.close();				
				break;			
			} catch (Exception ex) {
				if (count++ &gt; 3) throw new RuntimeException(ex.getMessage());
			}
		}
		return port;
	}
	
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5450/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5450&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/11/07/jax-ws-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Compiler API</title>
		<link>http://numberformat.wordpress.com/2012/10/08/java-compiler-api/</link>
		<comments>http://numberformat.wordpress.com/2012/10/08/java-compiler-api/#comments</comments>
		<pubDate>Mon, 08 Oct 2012 14:51:14 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5440</guid>
		<description><![CDATA[This page describes a sample application to compile a class file from a String that is pasted in.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5440&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes a sample application to compile a class file from a String that is pasted in.</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package com.test;

import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

public class TestApp extends JFrame {

	private Container c;
	JTextArea txtSource;
	
	public TestApp() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        c = this.getContentPane();
        setLayout(new FlowLayout());
        this.setTitle(&quot;Class Loader Test App&quot;);
        txtSource = getTextArea();
        c.add(txtSource);
        c.add(compileButton());
        c.add(executeButton());
        this.pack();
        this.setVisible(true);        
	}
	
	private Component executeButton() {
		JButton executeButton = new JButton(&quot;execute&quot;);
		executeButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
	            try {
					new URLClassLoader(new URL[] { new File(&quot;&quot;).toURI()
							.toURL() }).loadClass(&quot;Test&quot;).newInstance();
	            } catch (Exception ex) {
	            	ex.printStackTrace();
	            }
			}
		});
		return executeButton;
	}

	private JButton compileButton() {
		JButton btnCompile = new JButton(&quot;Compile&quot;);
		
		btnCompile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println(&quot;Compiling...&quot;);
				
				compile(txtSource.getText());
			}
			SimpleJavaFileObject getJavaFileContentsAsString() {
				StringBuilder javaFileContents = new StringBuilder(txtSource.getText());
				JavaObjectFromString javaFileObject = null;
				try {
					javaFileObject = new TestApp.JavaObjectFromString(&quot;Test.java&quot;,
							javaFileContents.toString());
				} catch (Exception exception) {
					exception.printStackTrace();
				}
				return javaFileObject;
			}
			private void compile(String text) {
				JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
				DiagnosticCollector diagnosticsCollector = new DiagnosticCollector();
				StandardJavaFileManager fileManager  =
					compiler.getStandardFileManager(diagnosticsCollector, null, null);
				
				Iterable fileObjects = null;
				boolean fromFile = false;
				if(fromFile) {
					String fileToCompile = &quot;Test.java&quot;;
					fileObjects = fileManager.getJavaFileObjectsFromStrings(Arrays.asList(fileToCompile)); // Line 5
				} else {
					JavaFileObject javaObjectFromString = getJavaFileContentsAsString();
					fileObjects = Arrays.asList(javaObjectFromString);
				}
				
				CompilationTask task = compiler.getTask(null, fileManager, diagnosticsCollector, null, null, fileObjects);
				
		        Boolean result = task.call(); // Line 7
		        
		        List&lt;Diagnostic&gt; diagnostics = diagnosticsCollector.getDiagnostics();
		        
		        for(Diagnostic d : diagnostics){
		            // Print all the information here.
		        	System.out.println(d.getMessage(null));
		        }
		        
		        if(result == true){
		            System.out.println(&quot;Compilation is successful&quot;);
		        }else{
		            System.out.println(&quot;Compilation Failed&quot;);
		        }
			}
		});
		return btnCompile;
	}

	static class JavaObjectFromString extends SimpleJavaFileObject {
		private String contents = null;

		public JavaObjectFromString(String className, String contents)
				throws Exception {
			super(new URI(className), Kind.SOURCE);
			this.contents = contents;
		}

		public CharSequence getCharContent(boolean ignoreEncodingErrors)
				throws IOException {
			return contents;
		}
	}

	
	private JTextArea getTextArea() {
		JTextArea txtSource = new JTextArea(25, 80);
		return txtSource;
	}

	public static void main(String args[]) {
		new TestApp();
	}
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5440/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5440/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5440&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/10/08/java-compiler-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Internationalizing a GWT Application</title>
		<link>http://numberformat.wordpress.com/2012/06/19/internationalizing-a-gwt-application/</link>
		<comments>http://numberformat.wordpress.com/2012/06/19/internationalizing-a-gwt-application/#comments</comments>
		<pubDate>Tue, 19 Jun 2012 23:30:52 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5282</guid>
		<description><![CDATA[This page describes how to setup internationalisation in your GWT application. The example on this page builds from the page listed in the requirements section. Requirements Successful completion of my previous post Project Configuration In order to enable internationalisation support you need to add the following &#8220;goal&#8221; and &#8220;i18nMessagesBundle&#8221; elements inside &#8220;gwt-maven-plugin&#8221;: vi pom.xml insert [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5282&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to setup internationalisation in your GWT application. The example on this page builds from the page listed in the requirements section.</p>
<h3>Requirements</h3>
<ul>
<li><a href="http://numberformat.wordpress.com/2012/06/18/blank-gwt-template/">Successful completion of my previous post</a></li>
</ul>
<h3>Project Configuration</h3>
<p>In order to enable internationalisation support you need to add the following &#8220;goal&#8221; and &#8220;i18nMessagesBundle&#8221; elements inside &#8220;gwt-maven-plugin&#8221;:</p>
<p>vi pom.xml</p>
<pre class="brush: xml; gutter: false; highlight: [9]; title: ; notranslate">
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.4.0&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
            ...
            &lt;goal&gt;i18n&lt;/goal&gt;
            ...
            &lt;/goals&gt;
...
</pre>
<p>insert the &#8220;i18nMessagesBundle&#8221; element here:</p>
<pre class="brush: xml; gutter: false; highlight: [3]; title: ; notranslate">
        &lt;configuration&gt;
          ...
          &lt;i18nMessagesBundles&gt;
                    &lt;i18nMessagesBundle&gt;com.test.client.Messages&lt;/i18nMessagesBundle&gt;
          &lt;/i18nMessagesBundles&gt;
          ...
        &lt;configuration&gt;
</pre>
<p>Externalize the language strings to a property file. </p>
<p>The following message bundle is converted to a Java Class by Maven. In order to specify additional bundles just insert an additional &#8220;i18nMessagesBundle&#8221; tag in the pom.xml file.</p>
<h3>Properties File</h3>
<p>Create the directory that will hold the property file if not done so already: </p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mkdir -p src/main/resources/com/test/client
</pre>
<p>vi src/main/resources/com/test/client/Messages.properties</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
sendButton = Send
hello = Hello {0}!
</pre>
<h3>Java code Change</h3>
<p>Modify the java code to reference the property values instead of hard-coded strings.</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
--- matrix-blank/src/main/java/com/test/client/Matrix.java	
+++ matrix/src/main/java/com/test/client/Matrix.java	
@@ -10,10 +10,11 @@
 
 public class Matrix implements EntryPoint {
 
+	private final Messages messages = GWT.create(Messages.class);
 	public void onModuleLoad() {
-		Button button = new Button(&quot;Send&quot;, new ClickHandler() {
+		Button button = new Button(messages.sendButton(), new ClickHandler() {
 			public void onClick(ClickEvent event) {
-				Window.alert(&quot;Hello World!&quot;);
+				Window.alert(messages.hello(&quot;World&quot;));
 			}
 		});
 		button.setStyleName(&quot;sendButton&quot;);
</pre>
<h3>Test the Change</h3>
<p>At this time you would want to verify that the Message.java class has been generated by the GWT framework. If this class is not found then try to mvn compile and refresh the eclipse project. You may also want to right click, update Maven project configuration if that does not work.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn compile gwt:run
</pre>
<h3>The French Version</h3>
<p>vi src/main/resources/com/test/client/Messages_fr.properties</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
sendButton = Envoyer
hello = bonjour {0}!
</pre>
<h3>Configure</h3>
<p>You can add the following line into the module element of your &#8220;gwt.xml&#8221; file for each locale you want to support:<br />
vi src/main/java/com/test/Matrix.gwt.xml</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
&lt;extend-property name=&quot;locale&quot; values=&quot;fr&quot;/&gt;
</pre>
<h3>Start the application</h3>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn compile gwt:run
</pre>
<h3>Test the Change</h3>
<p>At this point you have 2 options to see the French version of the site:</p>
<ol>
<li>You can put the following line in the host HTML page
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;meta name=&quot;gwt:property&quot; content=&quot;locale=fr&quot;&gt;
</pre>
</li>
<li>Append the client property value to the query string of the URL: <a href="http://127.0.0.1:8888/Matrix.html?gwt.codesvr=127.0.0.1:9997?locale=fr" rel="nofollow">http://127.0.0.1:8888/Matrix.html?gwt.codesvr=127.0.0.1:9997?locale=fr</a></li>
</ol>
<p>Either way you will see the French version of the site.</p>
<h3>Reference</h3>
<p><a href="http://code.google.com/webtoolkit/doc/latest/tutorial/i18n.html">http://code.google.com/webtoolkit/doc/latest/tutorial/i18n.html</a></p>
<h3>Appendix</h3>
<p>Creating Keys for place holder parameters, the lines of the property file should look like this:</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
myString = First parm is {0}, second parm is {1}, third parm is {2}.
</pre>
<p>The key &#8220;myString&#8221; can be used in static HTML by wrapping the content with a html tag with an assigned id.</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
    &lt;h1 id=&quot;myString&quot;&gt;&lt;/h1&gt;
</pre>
<p>The id attribute can be used as a handle to replace the text in Java code like this:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
    RootPanel.get(&quot;appTitle&quot;).add(new Label(constants.myString(&quot;one&quot;,&quot;two&quot;,&quot;three&quot;)));
</pre>
<p>To get the list of locale&#8217;s supported by your JVM just run the following code:</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
	public static void main(String args[]) {
		Locale locales[] = SimpleDateFormat.getAvailableLocales();
		List arrayList = Arrays.asList(locales);
		Collections.sort(arrayList, new Comparator() {
			public int compare(Locale o1, Locale o2) {
				return o1.getDisplayName().compareTo(o2.getDisplayName());
			}
		});
		for (Locale locale : arrayList) {
			System.out.println(locale.toString() + &quot;\t&quot; + locale.getDisplayName());
		}
	}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5282&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/06/19/internationalizing-a-gwt-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Blank GWT Template Starter Application</title>
		<link>http://numberformat.wordpress.com/2012/06/18/blank-gwt-template/</link>
		<comments>http://numberformat.wordpress.com/2012/06/18/blank-gwt-template/#comments</comments>
		<pubDate>Tue, 19 Jun 2012 03:12:29 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5273</guid>
		<description><![CDATA[This page describes the complete end-to-end process of creating and testing a blank &#8220;Hello World&#8221; type Google Web Tool kit (GWT) starter application using Maven. The page takes about 10-15 minutes to complete and have a working GWT application. The application described on this page displays a Send Button on the page. It displays a [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5273&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes the complete end-to-end process of creating and testing a blank &#8220;Hello World&#8221; type Google Web Tool kit (GWT) starter application using Maven. The page takes about 10-15 minutes to complete and have a working GWT application.</p>
<p>The application described on this page displays a Send Button on the page. It displays a JavaScript alert() message when the button is clicked.</p>
<h3>Background</h3>
<p>The GWT SDK allows you to generate an application using their generation tool. However I never liked using this tool because the application it generated is useless to me unless I understand how the application is working. The following page breaks down a simple Hello World GWT application step by step and allows the reader to follow along. Once the application is complete the user can import it into eclipse and use the GWT tool to modify the application using the Screen Design Tools.</p>
<h3>Requirements</h3>
<ul>
<li>Maven</li>
<li>M2 Eclipse plugin</li>
<li>Eclipse GWT plugin</li>
</ul>
<p>This page covers GWT version 2.4.0.</p>
<p>The first step is to create directory that will hold your project. The example below uses &#8220;matrix&#8221; as the project name. You can replace each instance of &#8220;matrix&#8221; with whatever you want to call your project.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mkdir matrix
cd matrix
# create some additional directories
mkdir -p src/main/java/com/test/client
mkdir -p src/main/webapp/WEB-INF
</pre>
<p>vi pom.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project
  xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;

  &lt;!-- POM file generated with GWT webAppCreator --&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;matrix&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;GWT Maven Archetype&lt;/name&gt;

  &lt;properties&gt;
    &lt;!-- Convenience property to set the GWT version --&gt;
    &lt;gwtVersion&gt;2.4.0&lt;/gwtVersion&gt;
    &lt;!-- GWT needs at least java 1.5 --&gt;
    &lt;webappDirectory&gt;${project.build.directory}/${project.build.finalName}&lt;/webappDirectory&gt;
    &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;

  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-servlet&lt;/artifactId&gt;
      &lt;version&gt;${gwtVersion}&lt;/version&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;com.google.gwt&lt;/groupId&gt;
      &lt;artifactId&gt;gwt-user&lt;/artifactId&gt;
      &lt;version&gt;${gwtVersion}&lt;/version&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
    &lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;javax.validation&lt;/groupId&gt;
&lt;artifactId&gt;validation-api&lt;/artifactId&gt;
&lt;version&gt;1.0.0.GA&lt;/version&gt;
&lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;4.7&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

  &lt;build&gt;
    &lt;!-- Generate compiled stuff in the folder used for developing mode --&gt;
    &lt;outputDirectory&gt;${webappDirectory}/WEB-INF/classes&lt;/outputDirectory&gt;
    &lt;plugins&gt;
      &lt;!-- GWT Maven Plugin --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
        &lt;artifactId&gt;gwt-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.4.0&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;compile&lt;/goal&gt;
              &lt;goal&gt;test&lt;/goal&gt;
              &lt;goal&gt;generateAsync&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;!-- Plugin configuration. There are many available options, see
          gwt-maven-plugin documentation at codehaus.org --&gt;
        &lt;configuration&gt;
          &lt;runTarget&gt;Matrix.html&lt;/runTarget&gt;
          &lt;hostedWebapp&gt;${webappDirectory}&lt;/hostedWebapp&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;

      &lt;!-- Copy static web files before executing gwt:run --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.1.1&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;phase&gt;compile&lt;/phase&gt;
            &lt;goals&gt;
              &lt;goal&gt;exploded&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;webappDirectory&gt;${webappDirectory}&lt;/webappDirectory&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.3.2&lt;/version&gt;
        &lt;configuration&gt;
          &lt;source&gt;1.6&lt;/source&gt;
          &lt;target&gt;1.6&lt;/target&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;
</pre>
<h3>Host HTML Page</h3>
<p>The following is the Host HTML Page. The page imports the generated Javascript and starts the Javascript application. Similar to the &#8220;Entry Point&#8221; main() method of many other programming languages.</p>
<p>vi src/main/webapp/Matrix.html</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;!doctype html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
    &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;Matrix.css&quot;&gt;
&lt;script language=&quot;javascript&quot; src=&quot;com.test.Matrix/com.test.Matrix.nocache.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;noscript&gt;
      &lt;div style=&quot;width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif&quot;&gt;
        Your web browser must have JavaScript enabled
        in order for this application to display correctly.
      &lt;/div&gt;
    &lt;/noscript&gt;
    &lt;div id=&quot;sendButtonContainer&quot;&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<h3>CSS Styles</h3>
<p>GWT components are highly customizable. It makes sense to define sizes, colors, alighment, images, and other visual aspects of the component in CSS.</p>
<p>vi src/main/webapp/Matrix.css</p>
<pre class="brush: css; gutter: false; title: ; notranslate">
.sendButton {
  display: block;
  font-size: 12pt;
}
</pre>
<h3>Web Application Descriptor</h3>
<p>The following is a basic web.xml file for the application.</p>
<p>vi src/main/webapp/WEB-INF/web.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app
    PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
    &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;

&lt;web-app&gt;

  &lt;!-- Servlets --&gt;
  &lt;!-- Servlet-Mapping --&gt;

  &lt;!-- Default page to serve --&gt;
  &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;Matrix.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre>
<p>vi src/main/java/com/test/Matrix.gwt.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;module&gt;
  &lt;inherits name='com.google.gwt.user.User' /&gt;
  &lt;inherits name='com.google.gwt.user.theme.standard.Standard' /&gt;
  &lt;entry-point class='com.test.client.Matrix' /&gt;
&lt;/module&gt;
</pre>
<p>vi src/main/java/com/test/client/Matrix.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package com.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

public class Matrix implements EntryPoint {

	public void onModuleLoad() {
		Button button = new Button(&quot;Send&quot;, new ClickHandler() {
			public void onClick(ClickEvent event) {
				Window.alert(&quot;Hello World!&quot;);
			}
		});
		button.setStyleName(&quot;sendButton&quot;);
		RootPanel.get(&quot;sendButtonContainer&quot;).add(button);
	}
}

</pre>
<h3>Run the project</h3>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn clean compile gwt:run
</pre>
<p>Click on Launch Default Browser button. You should see a page with a button on the top left.</p>
<h3>Import into Eclipse and Edit in Design View</h3>
<p>The following procedure allows you to open the screen above in the &#8220;GWT Design View&#8221;.</p>
<ol>
<li>Right click and import &#8220;Existing Maven Projects&#8221; into eclipse.</li>
<li>Select the directory where the project is contained.</li>
<li>Once the project is imported right click -&gt; Properties -&gt; Google -&gt; Web Toolkit.</li>
<li>Add the Entry point Module Matrix to the list if not already there by clicking on the &#8220;Add&#8221; button.</li>
<li>Right click on the Matrix.java File and choose Open With -&gt; WindowBuilder Editor.</li>
<li>The source file will open and allow you to click on the Design Tab.</li>
<li>Change the button name to Send2.</li>
</ol>
<p>Test the change by typing:</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn clean compile gwt:run
</pre>
<p>Might need to click on Launch Default Browser button twice. You should see a page with a button titled &#8220;Send2&#8243; on the top left.</p>
<h3>What&#8217;s Next?</h3>
<ul>
<li><a href="http://numberformat.wordpress.com/2012/01/16/internationalizing-a-gwt-application/">Internationalize your application</a></li>
<li><a href="http://numberformat.wordpress.com/2012/01/16/invoke-server-side-code-using-gwt/">Invoke Server Side Code Using GWT</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5273/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5273/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5273&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/06/18/blank-gwt-template/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Shutting Down Spring Batch Jobs Gracefully</title>
		<link>http://numberformat.wordpress.com/2012/04/24/shutting-down-spring-batch-jobs-gracefully/</link>
		<comments>http://numberformat.wordpress.com/2012/04/24/shutting-down-spring-batch-jobs-gracefully/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 02:48:25 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[batch]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5356</guid>
		<description><![CDATA[This page describes how to exit batch jobs gracefully when the system sends the SIGINT to the JVM. If we ignore these signals the jobs will be left hanging. The solution is to request the Spring Job-operator to gracefully stop the job and in the process save any intermediate data to the spring batch status [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5356&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to exit batch jobs gracefully when the system sends the SIGINT to the JVM. If we ignore these signals the jobs will be left hanging. The solution is to request the Spring Job-operator to gracefully stop the job and in the process save any intermediate data to the spring batch status tables.</p>
<h3>Requirements</h3>
<ul>
<li>Fully working Spring Batch application</li>
<li>Configured Spring batch Job Repository</li>
</ul>
<p>Start by adding the following to the spring configuration file:</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;beans:bean id=&quot;jobRegistry&quot; 
	class=&quot;org.springframework.batch.core.configuration.support.MapJobRegistry&quot; /&gt;
&lt;beans:bean id=&quot;jobRegistryBeanPostProcessor&quot;
	class=&quot;org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor&quot;&gt;
    &lt;beans:property name=&quot;jobRegistry&quot; ref=&quot;jobRegistry&quot;/&gt;
&lt;/beans:bean&gt;	
&lt;beans:bean id=&quot;jobOperator&quot; 
	class=&quot;org.springframework.batch.core.launch.support.SimpleJobOperator&quot;&gt;
		&lt;beans:property name=&quot;jobExplorer&quot; ref=&quot;jobExplorer&quot;/&gt;
		&lt;beans:property name=&quot;jobRepository&quot; ref=&quot;jobRepository&quot; /&gt;
		&lt;beans:property name=&quot;jobRegistry&quot; ref=&quot;jobRegistry&quot; /&gt;
		&lt;beans:property name=&quot;jobLauncher&quot; ref=&quot;jobLauncher&quot; /&gt;
&lt;/beans:bean&gt;
&lt;beans:bean id=&quot;jobExplorer&quot; 
	class=&quot;org.springframework.batch.core.explore.support.JobExplorerFactoryBean&quot;&gt;
	&lt;beans:property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;/&gt;
&lt;/beans:bean&gt;
&lt;beans:bean name=&quot;processShutdownListener&quot; 
	class=&quot;com.test.batch.listeners.ProcessShutdownListener&quot;&gt;
	&lt;beans:property name=&quot;jobOperator&quot; ref=&quot;jobOperator&quot;/&gt;
&lt;/beans:bean&gt;
</pre>
<p>Inside the job.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
	&lt;listeners&gt;
		&lt;listener ref=&quot;processShutdownListener&quot;/&gt;
	&lt;/listeners&gt;
</pre>
<p>And finally the listener</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package com.test.batch.listeners;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.launch.JobExecutionNotRunningException;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.launch.NoSuchJobExecutionException;

/**
 * This class listens to events from the Operating System requesting the Batch
 * to shutdown. For example when the user hits CTRL-C or the system is shutting
 * down. If we ignore these signals the jobs will be left hanging. This class
 * attempts to remedy this situation by requesting the JobOperator to gracefully
 * stop a job when the JVM calls the shutdown hook.
 */
public class ProcessShutdownListener implements JobExecutionListener {
	private static final Log logger = 
		LogFactory.getLog(ProcessShutdownListener.class);
	
	private JobOperator jobOperator;
	
	@Override
	public void afterJob(JobExecution jobExecution) { /* do nothing. */ }

	@Override
	public void beforeJob(final JobExecution jobExecution) {
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					jobOperator.stop(jobExecution.getId());
					while(jobExecution.isRunning()) {
						logger.info(&quot;waiting for job to stop...&quot;);
						try {Thread.sleep(100);} catch (InterruptedException e) {}
					}
				} catch (NoSuchJobExecutionException e) { // ignore
				} catch (JobExecutionNotRunningException e) { // ignore
				}
			}
		});
	}

	public void setJobOperator(JobOperator jobOperator) {
		this.jobOperator = jobOperator;
	}

}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5356&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/04/24/shutting-down-spring-batch-jobs-gracefully/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>ALTERing Database Schema Using DDLUtils</title>
		<link>http://numberformat.wordpress.com/2012/02/09/altering-database-schema-using-ddlutils/</link>
		<comments>http://numberformat.wordpress.com/2012/02/09/altering-database-schema-using-ddlutils/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 04:23:41 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[ddlutils]]></category>
		<category><![CDATA[hsqldb]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5325</guid>
		<description><![CDATA[This page describes how to use DDLUtils to only prints out alter statements instead of making the changes automatically. Requirements Java 5 or above Maven 2 or above In Memory database. Background My previous article described how to use DDLUtils to automatically make changes to a database. Since we were using an in-memory/temporary database, it [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5325&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to use DDLUtils to only prints out alter statements instead of making the changes automatically.</p>
<h3>Requirements</h3>
<ul>
<li>Java 5 or above</li>
<li>Maven 2 or above</li>
<li><a href="http://numberformat.wordpress.com/2011/03/31/schema-maintenance-using-ddlutils/">In Memory database.</a></li>
</ul>
<h3>Background</h3>
<p>My previous article described how to use DDLUtils to automatically make changes to a database. Since we were using an in-memory/temporary database, it wouldn&#8217;t be a big deal if DDLUtils made a mistake. </p>
<p><strong>Shortcut: If you have not implemented the &#8220;In memory database&#8221; in the requirements section and you have your own database. Then you can skip to the short cut section below. the return here.</strong></p>
<p>DDLUtils has functionality to fetch the current DDL and dump it into an XML file. Once we modify the xml we can have DDLUtils compare the xml against the current database and only print &#8220;ALTER&#8221; statements to the screen. We can take those alter statements and manually run them against the database.</p>
<h3>Create the Java Code</h3>
<p>The following class is designed to be run from the command line. You can wrap it into a shell script. Take some time to review the java source below. It is pretty much self explanatory. Please be sure to name your xml file different from the prior project. In the example below its called &#8220;ddl-draft.xml&#8221;.</p>
<p>vi src/main/java/com/test/DDLUtils.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package com.test;

import java.io.InputStreamReader;
import java.io.StringWriter;

import javax.sql.DataSource;

import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * &lt;p&gt;
 * Dumps or generates schema information for the batch project. This class is
 * only designed to output information. Although the framework is capabile, It
 * should not make any alterations to the database since automated alterations
 * could be risky.
 * &lt;/p&gt;
 * 
 * &lt;p&gt;
 * The Dump command takes the existing database schema and creates an xml file.
 * You can choose to redirect this output to a file so you can modify the
 * schema.
 * &lt;/p&gt;
 * 
 * &lt;p&gt;
 * The alter command takes the xml located in the /ddl.xml file and generates
 * alter statements to standard output. You can redirect this to a file and use
 * it to alter the database manually.
 * &lt;/p&gt;
 * 
 * &lt;p&gt;
 * mvn -q exec:java -Dexec.mainClass=com.test.DDLUtils -Dexec.args=&quot;dump&quot;
 * &lt;/p&gt; language
 * &lt;p&gt;
 * mvn -q exec:java -Dexec.mainClass=com.test.DDLUtils -Dexec.args=&quot;alter&quot;
 * &lt;/p&gt;
 * 
 */
public class DDLUtils {
	private DataSource dataSource;

	public DDLUtils() {
		super();
		ApplicationContext context = new 
		ClassPathXmlApplicationContext(&quot;com/test/app-config.xml&quot;);
		dataSource = (DataSource) context.getBean(&quot;dataSource&quot;);		
	}
	
	public static void main(String args[]) {
		(new DDLUtils()).contextInitialized(args);
	}
	
    public void contextInitialized(String args[]) {
        Platform platform = PlatformFactory
                .createNewPlatformInstance(dataSource);
 
        Database database = new DatabaseIO().read(new InputStreamReader(
                getClass().getResourceAsStream(&quot;/ddl-draft.xml&quot;)));
        if(args.length &lt; 1) {
        	usage();
        	return;
        }
        if(&quot;dump&quot;.equals(args[0])) {
    		StringWriter writer = new StringWriter();
    		new DatabaseIO().write(platform.readModelFromDatabase(&quot;batch&quot;), writer);
    		System.out.println(writer.toString());        	
        } else if(&quot;alter&quot;.equals(args[0])) {
        	System.out.println(platform.getAlterTablesSql(database));
        } else {
        	usage();
        	return;
        }
    }

	private void usage() {
    	System.out.println(&quot;usage: &quot;);
    	System.out.println(&quot;\t\t&quot;+getClass().getName()+&quot; (dump|alter)\n\n&quot;);    
	}
    
}
</pre>
<h3>Testing the Application</h3>
<p>The following command takes the current schema and creates an xml file to standard output.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn -q exec:java -Dexec.mainClass=com.test.DDLUtils -Dexec.args=&quot;dump&quot;
</pre>
<p>The following prints to standard out the DDL that will get the current database to resemble what is documented in the xml file.</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn -q exec:java -Dexec.mainClass=com.test.DDLUtils -Dexec.args=&quot;alter&quot;
</pre>
<h3>Shortcut</h3>
<p>Read this section if you already have a database and simply want to use DDL utils to query the schema or help modify it.</p>
<p><strong>Step 1:</strong> Create a Maven Project with all the necessary dependencies listed below + the JDBC driver specific to your database.<br />
mkdir ddlutil<br />
cd ddlutil<br />
vi pom.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.test&lt;/groupId&gt;
  &lt;artifactId&gt;ddlutil&lt;/artifactId&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;name&gt;ddlutil Maven Webapp&lt;/name&gt;
  &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;junit&lt;/groupId&gt;
      &lt;artifactId&gt;junit&lt;/artifactId&gt;
      &lt;version&gt;3.8.1&lt;/version&gt;
      &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
		&lt;groupId&gt;org.apache.ddlutils&lt;/groupId&gt;
		&lt;artifactId&gt;ddlutils&lt;/artifactId&gt;
		&lt;version&gt;1.0&lt;/version&gt;    
    &lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring&lt;/artifactId&gt;
			&lt;version&gt;2.5.6&lt;/version&gt;
		&lt;/dependency&gt;                
  &lt;/dependencies&gt;
  &lt;build&gt;
    &lt;finalName&gt;ddlutil&lt;/finalName&gt;
    
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.0.2&lt;/version&gt;
				&lt;configuration&gt;
					&lt;source&gt;1.5&lt;/source&gt;
					&lt;target&gt;1.5&lt;/target&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;    
  &lt;/build&gt;
&lt;/project&gt;
</pre>
<p><strong>Step 2:</strong> Create the spring configuration file with the information necessary to connect to your datasource.</p>
<p>src/main/resources/applicationContext.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
        xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
        xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans

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


http://www.springframework.org/schema/context


http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;&gt;

&lt;context:annotation-config/&gt;
&lt;context:component-scan base-package=&quot;com.test&quot;/&gt;
&lt;bean name=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;xxxreplace with your database driverxxx&quot;/&gt;
        &lt;property name=&quot;url&quot; value=&quot;xxxreplace with your database urlxxx&quot;/&gt;
        &lt;property name=&quot;username&quot; value=&quot;xxx_username_xxx&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;xxx&quot;/&gt;
&lt;/bean&gt;
&lt;/beans&gt;
</pre>
<p>See the following URL to <a href="http://numberformat.wordpress.com/2009/12/19/spring-enabled-application-with-mysql/">setup data connectivity using spring</a> and help fill in the values above. </p>
<p><strong>Step 3:</strong> Create sample DDL and return the the Background section on this page.</p>
<p>src/main/resources/ddl.xml</p>
<pre class="brush: xml; gutter: false; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE database SYSTEM &quot;http://db.apache.org/torque/dtd/database.dtd&quot;&gt;
&lt;database name=&quot;testdb&quot;&gt;
  &lt;table name=&quot;author&quot;&gt;
    &lt;column name=&quot;author_id&quot;
            type=&quot;INTEGER&quot;
            primaryKey=&quot;true&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;name&quot;
            type=&quot;VARCHAR&quot;
            size=&quot;50&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;organization&quot;
            type=&quot;VARCHAR&quot;
            size=&quot;50&quot;
            required=&quot;false&quot;/&gt;
  &lt;/table&gt;

  &lt;table name=&quot;book&quot;&gt;
    &lt;column name=&quot;book_id&quot;
            type=&quot;INTEGER&quot;
            required=&quot;true&quot;
            primaryKey=&quot;true&quot;
            autoIncrement=&quot;true&quot;/&gt;
    &lt;column name=&quot;isbn&quot;
            type=&quot;VARCHAR&quot;
            size=&quot;15&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;author_id&quot;
            type=&quot;INTEGER&quot;
            required=&quot;true&quot;/&gt;
    &lt;column name=&quot;title&quot;
            type=&quot;VARCHAR&quot;
            size=&quot;255&quot;
            required=&quot;true&quot;/&gt;

    &lt;foreign-key foreignTable=&quot;author&quot;&gt;
      &lt;reference local=&quot;author_id&quot; foreign=&quot;author_id&quot;/&gt;
    &lt;/foreign-key&gt;  

    &lt;index name=&quot;book_isbn&quot;&gt;
      &lt;index-column name=&quot;isbn&quot;/&gt;
    &lt;/index&gt;
  &lt;/table&gt;
&lt;/database&gt;
</pre>
<h3>References</h3>
<ul>
<li><a href="http://db.apache.org/ddlutils/">DDLUtils Homepage</a></li>
<li><a href="http://hsqldb.org/">HSQLDB</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5325&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/02/09/altering-database-schema-using-ddlutils/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
		<item>
		<title>Application Version.java Maven</title>
		<link>http://numberformat.wordpress.com/2012/02/05/application-version-java-maven/</link>
		<comments>http://numberformat.wordpress.com/2012/02/05/application-version-java-maven/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 04:33:15 +0000</pubDate>
		<dc:creator>numberformat</dc:creator>
				<category><![CDATA[Technical]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[properties]]></category>

		<guid isPermaLink="false">http://numberformat.wordpress.com/?p=5318</guid>
		<description><![CDATA[This page describes how to have Maven configure your application so that it can report the current application build version to the user. This comes in handy when displaying help information for your application as well as allowing production support staff to know what version is actually running on the server. Requirements Maven 2 or [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5318&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>This page describes how to have Maven configure your application so that it can report the current application build version to the user. </p>
<p>This comes in handy when displaying help information for your application as well as allowing production support staff to know what version is actually running on the server.</p>
<h3>Requirements</h3>
<ol>
<li>Maven 2 or above</li>
<li>Maven Java 5 or above</li>
</ol>
<h3>Create the project using Maven Archetype</h3>
<p>First step is to create the job using a Maven archetype. Open up the command prompt and navigate to an empty directory.</p>
<p>mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart<br />
groupId: com.test<br />
artifactId: appVersion</p>
<p>Answer the rest of the questions with defaults “Just hit the enter key”</p>
<p>Change to the project’s base directory.</p>
<p>cd appVersion</p>
<p>Create the resources folder</p>
<p>Edit the pom.xml file and add the following section towards the bottom of the page right before the closing project tag.</p>
<p>vi pom.xml</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
        &lt;build&gt;
                &lt;resources&gt;
                    &lt;resource&gt;
                        &lt;directory&gt;src/main/resources&lt;/directory&gt;
                        &lt;filtering&gt;true&lt;/filtering&gt;
                    &lt;/resource&gt;
                &lt;/resources&gt;
        &lt;/build&gt;
</pre>
<p>mkdir -p src/main/resources/com/test</p>
<p>vi src/main/resources/com/test/default.properties</p>
<pre class="brush: plain; gutter: false; title: ; notranslate">
app.version=${pom.version}
</pre>
<p>vi src/main/java/com/test/Version.java</p>
<pre class="brush: java; gutter: false; title: ; notranslate">
package com.test;

import java.util.ResourceBundle;

/**
 * Prints the application version. 
 */
public class Version {

	public static void main(String[] args) {
		String version = ResourceBundle.getBundle (&quot;com.test.default&quot;).getString(&quot;app.version&quot;);
		System.out.println(&quot;Application Version: &quot; + version);
	}

}
</pre>
<h3>Compile and Test</h3>
<pre class="brush: bash; gutter: false; title: ; notranslate">
mvn -q clean compile exec:java -Dexec.mainClass=com.test.Version 
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/numberformat.wordpress.com/5318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/numberformat.wordpress.com/5318/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=numberformat.wordpress.com&#038;blog=7605784&#038;post=5318&#038;subd=numberformat&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://numberformat.wordpress.com/2012/02/05/application-version-java-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6c22d6d1f6cd226c2501f8658e726e81?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">numberformat</media:title>
		</media:content>
	</item>
	</channel>
</rss>
