How Ant echo environment variables

19Dec2012 In: Ant

Ant has a build-in task Property that can access OS-specific environment variables, Property's parameter environment is the prefix to use when retrieving environment variables, plus the prefix and environment variables’name, we can directly echo or use its value. Read the rest of this entry »

Junit 3 vs Junit 4 Comparison

14Dec2012 In: Junit

Junit 3 vs Junit 4 Overview

Junit 4 is the next series of Junit 3 and introduced lot of features. It has been compatible with most tools for a while. We will compare junit 3 and junit 4 to give the difference from 11 aspects.

1. JDK Required?

JUnit 4 requires Java 5 or higher, it uses a lot from Java 5 annotations, generics, and static import features. The JUnit 3.x version can work with JDK 1.2+ and any higher versions.

2. JPackage Structure

JUnit 4 is built on the idea of backward compatibility, it leaves the old package org.junit. For all JUnit 4.x new features, they were added to a new package junit.framework. Read the rest of this entry »

If we execute the Junit test cases in Ant (most of the time we do) and some cases fail, we may expect to debug Java code in Ant to analyze the failures. This tutorial will demonstrate how to remote debug Java code in ant and Eclipse. Read the rest of this entry »

How to Check Java version in Ant

5Dec2012 In: Ant

Ant has built-in property ${}, you can directly use it to get Java or JVM version, the following example prints out Java version.

<target name="print-version"> 
   <echo>Java/JVM version: ${}</echo> 
   <echo>Java/JVM detail version: ${java.version}</echo> 

Read the rest of this entry »

How do I sign Jar files in Ant

4Dec2012 In: Ant

When JAR files are published, it has by default no signature included so nobody would likely trust this source, it is best to digitally sign the JAR files, this like you might sign a paper document with pen and ink – to let readers know who wrote or approved. The typical use of signed jars is in Java applet or Webstart deployment, you must sign all jars with same signature to avoid security issue.

To sign a JAR file, you must have a private key, Java is able to create self-signed certificate, in previous tutorial, we guide How Do I Create Keystore with Ant, you may take a reading if you don’t understand where we get the keystore that we use to sign Jar files. we are now not going to use Java JAR Signing and Verification Tool to sign JAR files, instead, Ant provides task SignJar do same thing, It will take a named file in the jar attribute, and an optional destDir or signedJar attribute. Read the rest of this entry »

How Do I Create Keystore with Ant

3Dec2012 In: Ant

A Java KeyStore (JKS) is a repository of security certificates, either authorization certificates, self-authentication certificates(where the user authenticates himself/herself to other users/services) or public key certificates. In this tutorial, we guide you how to create keystore in Ant and in next tutorial soon about how to sign Java jars using the keystore we just created. Read the rest of this entry »

SAX (Simple API for XML) is an event-based sequential access parser API, a widely-used specification that describes how XML parser can read and pass XML content efficiently from XML document to applications. SAX XML Reader is one famous and most popularity selection of current XML parser, unlike else XML-related specifications, it does not come from a formal committee or world-class company, it was developed by the XML-DEV mailing list, all discussions, documents and implementations around SAX were done by Dev mail lists. But now it has being received industry-wide acceptance. In this how-to tutorial/example, it provides a quick-start tutorial for java programmers to read XML via SAX parser/reader. Read the rest of this entry »

How Do I Create Temporary File with Ant

1Dec2012 In: Ant

Ant provides task ‘Tempfile’ to create temporary file, unlike, this task does not actually create a real temporary file in disk system(unless you ask it to), it just sets a property to the name of a temporary file which you can later create a file or dir. Read the rest of this entry »

How Do I Create File with Ant

29Nov2012 In: Ant

Ant provides task ‘Touch’ to create file and extensively set modification time of either newly created or any existing resources, it is even able to copy the modification time from old file to new created one, this task creates an empty file without content included, it can have any file name and suffix name as you specified.

Example to create File with Ant

<touch file="newfile.txt"/>

Creates ‘newfile.txt’ in current user work directory if it doesn’t exist, the datetime did not set so by default change the modification time of newly created file to the current time.

<touch file="newfile.txt" datetime="11/20/2012 2:00 pm"/>

Creates “newfile.txt” if it doesn’t exist and changes the modification time to 11/20/2012 2:00 pm. For the datetime, you have to follow the date format as Ant documents suggested.

<touch datetime="11/20/2012 2:00 pm">
  <fileset dir="c:\asjava"/>

Change the modification time to 11/20/2012 2:00 pm of files and directories found in c:\asjava, so it does not create any new files or folders, it just modifies the metadata of these pre-existing files, it sets modification time for the first children so doesn’t recursively set deep ones.


How Do I Create Directory with Ant

28Nov2012 In: Ant

1. Create directory with Ant

To creates a directory, you can simply use ant task Mkdir to create the full tree of directories, when have non-existent parent directories they will be created directly, does nothing if the directory already exist.

<mkdir dir="c:/asjava"/>

Creates a directory asjava in disk C.

<mkdir dir="C:/asjava/lib"/>

Read the rest of this entry »