SourceForge Project Page

Instructions for the Apache Ant Task


This page describes how to generate barcodes inside Ant scripts.

Using the Ant task

Before you can use the Barcode4J task, you have to declare it in your Ant script:

  <path id="barcode4j.classpath">
    <pathelement location="${barcode4j-root}/build/barcode4j.jar"/>
    <pathelement location="${barcode4j-root}/lib/avalon-framework-4.2.0.jar"/>

  <taskdef name="barcode" classname="org.krysalis.barcode4j.ant.BarcodeTask"

Then you're set to produce barcodes. Here's an example:

  <barcode output="mybarcode.svg" symbol="upce" format="svg" message="1234567"/>

This creates an UPC-E symbol with the message "1234567" in SVG format and saves the generated image as "mybarcode.svg".

The Ant tasks supports the following attributes/parameters:

Attribute Description Required
message The barcode message. Yes
output The output file. Yes
symbol The symbology to use. Use one of the supported symbology identifiers such as "code128", "datamatrix" etc. These are the same as on the command-line interface. Yes, if you don't specify a configuration file.
configurationFile Allows you to specify an XML configuration file (Barcode XML format) in order to configure the barcode generator. Yes, if you don't specify a symbology.
format The requested output format. You can either use a MIME type (such as "image/png") or a format identifier (such as "png"). No; defaults to "image/svg+xml".
dpi The resolution (in dots per inch) for the generated images. Only applicable when generating bitmap formats. No; defaults to 300.
bw Indicates whether to generate monochrome (black and white, 1 bit) bitmap images. Only applicable when generating bitmap formats. No; defaults to "true".
The "symbol" and "configurationFile" attributes are mutually exclusive! If you specify both, "configuration" is ignored.