ÿþ<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=unicode" /> <meta http-equiv="Content-Language" content="en-us" /> <style> <!-- p.MsoNormal, li.MsoNormal {margin-top:0mm; margin-right:0mm; margin-bottom:10.0pt; margin-left:0mm; line-height:115%; font-size:12.0pt; font-family:"Times New Roman","serif";} h1 {margin-right:0mm; margin-left:0mm; font-size:24.0pt; font-family:"Times New Roman","serif"; font-weight:bold} a:link {color:blue; text-decoration:underline;} a:visited {color:purple; text-decoration:underline;} p {margin-right:0mm; margin-left:0mm; font-size:12.0pt; font-family:"Times New Roman","serif";} ol {margin-bottom:0mm;} --> </style> <title>Using external libraries of the Ant tools</title> <meta name="keywords" content="Ant, libraries, technology, application, Java, programs, programming, example, tools, utility" /> <meta name="description" content="The steps on how to use external libraries of the Java Ant tools" /> </head> <body lang="EN-US" link="#0000FF" vlink="#800080" topmargin="20" leftmargin="20" rightmargin="20" bottommargin="20"> <div class="WordSection1"> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0">&nbsp;</p> <h1 align="center" style="margin-bottom:0mm;margin-bottom:0; text-align:center;line-height:normal; margin-top:0"><font size="6" face="Arial"> Hands-on Tutorial: Hello World with Ant 4</font></h1> <h1 align="center" style="margin-bottom:0mm;margin-bottom:0; text-align:center;line-height:normal; margin-top:0"><i> <font size="3" face="Arial"><span style="font-style:italic">(On Windows system)</span></font></i></h1> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0" align="center">&nbsp;<script type="text/javascript"><!-- google_ad_client = "pub-8089415323104206"; /* 728x90, created 5/16/08 javaos */ google_ad_slot = "1917524460"; google_ad_width = 728; google_ad_height = 90; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Arial"> <span style="font-size:12.0pt; font-weight:bold">Using external libraries</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Somehow told us not to use syso-statements. For log-Statements we should use a Logging-API - customizable on a high degree (including switching off during usual life (= not development) execution). We use Log4J for that, because:</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <ol style="margin-top:0mm" start="1" type="1"> <li class="MsoNormal" style="margin-bottom:0mm;margin-bottom:.0001pt;line-height: normal"> <p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <font size="3" face="Arial"><span style="font-size:12.0pt">It is not part of the JDK (1.4+) and we want to show how to use external libs</span></font></p> </li> <li class="MsoNormal" style="margin-bottom:0mm;margin-bottom:.0001pt;line-height: normal"> <p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <font size="3" face="Arial"><span style="font-size:12.0pt">It can run under JDK 1.2 (as Ant)</span></font></p> </li> <li class="MsoNormal" style="margin-bottom:0mm;margin-bottom:.0001pt;line-height: normal"> <p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <font size="3" face="Arial"><span style="font-size:12.0pt">It's highly configurable</span></font></p> </li> <li class="MsoNormal" style="margin-bottom:0mm;margin-bottom:.0001pt;line-height: normal"> <p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> <font size="3" face="Arial"><span style="font-size:12.0pt">It s from Apache :-)</span></font></p> </li> </ol> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">We store our external libraries in a new directory </span></font> <font face="Courier New"><span style="font-family:&quot;Arial&quot;">lib</span></font><font face="Arial">. Log4J can be <a href="http://www.apache.org/dist/logging/log4j/1.2.13/logging-log4j-1.2.13.zip" target="_blank" title="The Log4J JAR download"> downloaded [1]</a> from Logging's Homepage. Create the </font> <font face="Courier New"><span style="font-family: &quot;Arial&quot;">lib</span></font><font face="Arial"> directory and extract the log4j-1.2.9.jar into that lib-directory. After that we have to modify our java source to use that library and our buildfile so that this library could be accessed during compilation and run.</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Working with Log4J is documented inside its manual. Here we use the <i> <span style="font-style:italic">MyApp</span></i>-example from the <a href="http://logging.apache.org/log4j/docs/manual.html" target="_blank" title="The MyApp example used for Ant tutorial"> Short Manual [2]</a>. First we have to modify the java source to use the logging framework:</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">package oata;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">import org.apache.log4j.Logger;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">import org.apache.log4j.BasicConfigurator;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">public class HelloWorld {</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; <b> <span style="font-weight:bold">static Logger logger = Logger.getLogger(HelloWorld.class);</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; public static void main(String[] args) {</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">BasicConfigurator.configure();</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><font color="blue"><span style="color:blue; font-weight:bold">logger.info(&quot;Hello World&quot;);</span></font></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the old SysO-statement</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; }</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">}</span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Most of the modifications are &quot;framework overhead&quot; which has to be done once. The blue line is our &quot;old System-out&quot; statement.</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Don't try to run </span></font><font face="Courier New"> <span style="font-family: &quot;Arial&quot;">ant</span></font><font face="Arial"> - you will only get lot of compiler errors. Log4J is not inside the classpath so we have to do a little work here. But do not change the <b>CLASSPATH</b> environment variable! This is only for this project and maybe you would break other environments (this is one of the most famous mistakes when working with Ant). We introduce Log4J (or to be more precise: all libraries (jar-files) which are somewhere under </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">.\lib</span></font><font face="Arial">) into our buildfile:</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&lt;project name=&quot;HelloWorld&quot; basedir=&quot;.&quot; default=&quot;main&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;property name=&quot;lib.dir&quot;&nbsp;&nbsp;&nbsp;&nbsp; value=&quot;lib&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;path id=&quot;classpath&quot;&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;fileset dir=&quot;${lib.dir}&quot; includes=&quot;**/*.jar&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;/path&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; &lt;target name=&quot;compile&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mkdir dir=&quot;${classes.dir}&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${classes.dir}&quot; <span style="font-weight:bold">classpathref=&quot;classpath&quot;</span>/&gt;</b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; &lt;target name=&quot;run&quot; depends=&quot;jar&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;java fork=&quot;true&quot; <span style="font-weight:bold">classname=&quot;${main-class}&quot;</span>&gt;</b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;classpath&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;path refid=&quot;classpath&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="red"><span style="color:red;font-weight:bold">&lt;path location=&quot;${jar.dir}/${ant.project.name}.jar&quot;/&gt;</span></font></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight:bold">&lt;/classpath&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/java&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&lt;/project&gt;</span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">In this example we start our application not via its Main-Class manifest-attribute, because we could not provide a jarname <i><span style="font-style:italic">and</span></i> a classpath. So add our class in the red line to the already defined path and start as usual. Running </span></font><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">ant</span></font><font face="Arial"> would give (after the usual compile stuff):</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">[java] 0 [main] INFO oata.HelloWorld - Hello World</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">What's that?</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <ol> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">[java]</span></i> Ant task running at the moment</font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">0</span></i> sorry don't know - some Log4J stuff</font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">[main]</span></i> the running thread from our application </font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">INFO</span></i> log level of that statement </font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">oata.HelloWorld</span></i> source of that statement </font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial">- separator</font></p> </li> <li> <p class="MsoNormal" style="margin-top:0;margin-right:0mm;margin-bottom:0mm; margin-left:54.0pt;margin-bottom:0;text-indent:-18.0pt;line-height:100%"> <font face="Arial"><i><span style="font-style:italic">Hello World</span></i> the message</font></p> </li> </ol> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">For another layout ... have a look inside Log4J's documentation about using other <a target="_blank" title="Log4J documentation about using other PatternLayout" href="http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html"> PatternLayout</a>'s.</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Arial"> <span style="font-size:12.0pt; font-weight:bold">Configuration files</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Why we have used Log4J? &quot;It's highly configurable&quot;? No - all is hard coded! But that is not the debt of Log4J - it's ours. We had coded </span></font> <font face="Courier New"><span style="font-family:&quot;Arial&quot;">BasicConfigurator.configure();</span></font><font face="Arial"> which implies a simple, but hard coded configuration. More comfortable would be using a <b><span style="font-weight:bold">property file</span></b>. In the java source delete the BasicConfiguration-line from the main() method (and the related import-statement). Log4J will search then for a configuration as described in its manual. Then create a new file </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">src/log4j.properties</span></font><font face="Arial">. That's the default name for Log4J's configuration and using that name would make life easier - not only the framework knows what is inside, you too!</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>log4j.rootLogger=DEBUG, <span style="font-weight: bold">stdout</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>log4j.appender.<span style="font-weight:bold">stdout</span>=org.apache.log4j.ConsoleAppender</b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>log4j.appender.<span style="font-weight:bold">stdout</span>.layout=org.apache.log4j.PatternLayout</b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;"><b>log4j.appender.<span style="font-weight:bold">stdout</span>.layout.ConversionPattern=<font color="blue"><span style="color:blue;font-weight:bold">%m%n</span></font></b></span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">This configuration creates an output channel (&quot;Appender&quot;) to console named as </span></font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">stdout</span></font><font face="Arial"> which prints the message (</font><font face="Courier New"><span style="font-family: &quot;Arial&quot;">%m</span></font><font face="Arial">) followed by a line feed (</font><font face="Courier New"><span style="font-family:&quot;Arial&quot;; font-weight:700">%n</span></font><font face="Arial">) - same as the earlier </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">System.out.println()</span></font><font face="Arial"> :-) Oooh kay - but we haven't finished yet. We should deliver the configuration file, too. So we change the buildfile:</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;target name=&quot;compile&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;mkdir dir=&quot;${classes.dir}&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${classes.dir}&quot; classpathref=&quot;classpath&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">&lt;copy todir=&quot;${classes.dir}&quot;&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">&lt;fileset dir=&quot;${src.dir}&quot; excludes=&quot;**/*.java&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">&lt;/copy&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">This copies all resources (as long as they haven't the suffix &quot;.java&quot;) to the build directory, so we could start the application from that directory and these files will be included into the jar.</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font face="Arial">Testing the class</font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">In this step we will introduce the usage of the <a title="Java JUnit tester" target="_blank" href="http://www.junit.org/">JUnit [3] testframework</a> in combination with Ant. Because Ant has a built-in JUnit 3.8.2 you could start directly using it. Write a test class in </span> </font><font face="Courier New"><span style="font-family:&quot;Arial&quot;"> src\HelloWorldTest.java</span></font><font face="Arial">:</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">public class HelloWorldTest extends junit.framework.TestCase {</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; public void testNothing() {</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; }</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; </span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; public void testWillAlwaysFail() {</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fail(&quot;An error message&quot;);</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; }</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; </span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">}</span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Because we don t have real business logic to test, this test class is very small: just show how to start. For further information see the JUnit documentation [3] and the manual of </span></font><font face="Arial"> <a target="_blank" title="The junit - Java unit tester" href="http://ant.apache.org/manual/OptionalTasks/junit.html"> junit</a> task. Now we add a junit instruction to our buildfile:</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;target name=&quot;run&quot; depends=&quot;jar&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;java fork=&quot;true&quot; classname=&quot;${main-class}&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;classpath&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path refid=&quot;classpath&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path <b><span style="font-weight: bold">id=&quot;application&quot;</span></b> location=&quot;${jar.dir}/${ant.project.name}.jar&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/classpath&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/java&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; </span> </font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; <b> <span style="font-weight:bold">&lt;target name=&quot;junit&quot; depends=&quot;jar&quot;&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;junit printsummary=&quot;yes&quot;&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;classpath&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path refid=&quot;classpath&quot;/&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path refid=&quot;application&quot;/&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/classpath&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;batchtest fork=&quot;yes&quot;&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir=&quot;${src.dir}&quot; includes=&quot;*Test.java&quot;/&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/batchtest&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/junit&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">We reuse the path to our own jar file as defined in run-target by giving it an ID. The </span></font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">printsummary=yes</span></font><font face="Arial"> lets us see more detailed information than just a &quot;FAILED&quot; or &quot;PASSED&quot; message. How much tests failed? Some errors? Printsummary lets us know. The classpath is set up to find our classes. To run tests the </font> <font face="Courier New"><span style="font-family:&quot;Arial&quot;">batchtest</span></font><font face="Arial"> here is used, so you could easily add more test classes in the future just by naming them </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">*Test.java</span></font><font face="Arial">. This is a common naming scheme. After a </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">ant junit</span></font><font face="Arial"> you'll get:</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">junit:</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; [junit] Running HelloWorldTest</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; [junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0,01 sec</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;&nbsp;&nbsp; [junit] Test HelloWorldTest FAILED</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">BUILD SUCCESSFUL</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">...</span></font></p> </blockquote> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">We can also produce a report. Something that you (and other) could read after closing the shell.... There are two steps: 1. let </span></font> <font face="Courier New"><span style="font-family:&quot;Arial&quot;">&lt;junit&gt;</span></font><font face="Arial"> log the information and 2. Convert these to something readable (browsable).</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; <b> <span style="font-weight:bold">&lt;property name=&quot;report.dir value=&quot;${build.dir}/junitreport&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; ...</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;target name=&quot;junit&quot; depends=&quot;jar&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">&lt;mkdir dir=&quot;${report.dir}&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;junit printsummary=&quot;yes&quot;&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;classpath&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path refid=&quot;classpath&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;path refid=&quot;application&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/classpath&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b><span style="font-weight:bold">&lt;formatter type=&quot;xml&quot;/&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;batchtest fork=&quot;yes&quot; <b><span style="font-weight:bold">todir=&quot;${report.dir}&quot;</span></b>&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir=&quot;${src.dir}&quot; includes=&quot;*Test.java&quot;/&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/batchtest&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/junit&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; </span> </font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; <b> <span style="font-weight:bold">&lt;target name=&quot;junitreport&quot;&gt;</span></b></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;junitreport todir=&quot;${report.dir}&quot;&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;fileset dir=&quot;${report.dir}&quot; includes=&quot;TEST-*.xml&quot;/&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;report todir=&quot;${report.dir}&quot;/&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/junitreport&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;;font-weight:bold">&nbsp;&nbsp;&nbsp; &lt;/target&gt;</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">Because we would produce a lot of files and these files would be written to the current directory by default, we define a report directory, create it before running the </span></font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">junit</span></font><font face="Arial"> and redirect the logging to it. The log format is XML so </font> <font face="Courier New"><span style="font-family:&quot;Arial&quot;">junitreport</span></font><font face="Arial"> could parse it. In a second target </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;">junitreport</span></font><font face="Arial"> should create a browsable HTML-report for all generated xml-log files in the report directory. Now you can open the </font><font face="Courier New"> <span style="font-family:&quot;Arial&quot;; font-weight:700">${report.dir}\index.html</span></font><font face="Arial"> and see the result (looks something like JavaDoc). Personally I use two different targets for junit and junitreport. Generating the HTML report needs some time and you don t need the HTML report just for testing, e.g. if you are fixing an error or an integration server is doing a job.</font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><b><font size="3" face="Arial"> <span style="font-size:12.0pt;font-weight:bold">Resources</span></font></b></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Arial"><span style="font-size:12.0pt">&nbsp;</span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; [1] <a href="http://www.apache.org/dist/logging/log4j/1.2.13/logging-log4j-1.2.13.zip"> http://www.apache.org/dist/logging/log4j/1.2.13/logging-log4j-1.2.13.zip</a></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; [2] <a href="http://logging.apache.org/log4j/docs/manual.html">http://logging.apache.org/log4j/docs/manual.html</a></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0;line-height: 100%; margin-top:0"><font size="3" face="Courier New"> <span style="font-family:&quot;Arial&quot;">&nbsp;&nbsp;&nbsp; [3] <a href="http://www.junit.org/index.htm">http://www.junit.org/index.htm</a></span></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0"> &nbsp;</p><hr color="#FF0000"> <p class="MsoNormal" style="line-height: 100%; margin-top: 0; margin-bottom: 0">&nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0" align="center"> <font face="Arial" size="5">&nbsp;<a title="Ant: tutorial on how to compile, build and run Java" target="_top" href="http://www.visualcplusdotnet.com/javaopensource/antworksheet2.html">Ant 3</a> | <a title="The Java and open source applications" target="_top" href="http://www.javaguicodexample.com/"> Back to Main</a></font></p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0" align="center"> &nbsp;</p> <p class="MsoNormal" style="margin-bottom:0mm;margin-bottom:0; line-height:100%; margin-top:0" align="center"> &nbsp;<div align="center"><script src="http://tag.contextweb.com/TagPublish/getjs.aspx?action=VIEWAD&cwrun=200&cwadformat=728X90&cwpid=527221&cwwidth=728&cwheight=90&cwpnet=1&cwtagid=85440"></script></div> </p> </div> </body> </html>