About This Demo

This is a quick demo that shows how to use attributes together with Maven. Don't worry about 90% here seemingly being pure unexplainable magic - the purpose of this part of the tutorial is to show you what steps you must do to make the Commons Attributes package work. In the reference we'll focus more on just what happens, and how the all features work.

The Demo Files

All files required for this demo can be found in maven_demo.zip.

Project Setup

In order to get attributes working in your project you need to do three things: (1) declare dependencies, (2) install the commons-attributes plugin and (3) set project properties that will enable the plugin for your project.

Declaring Dependencies

Dependencies are declared as you would expect in your project.xml:

<dependency>
    <groupId>commons-attributes</groupId>
    <artifactId>commons-attributes-api</artifactId>
    <version>2.2</version>
</dependency>

<dependency>
    <groupId>commons-attributes</groupId>
    <artifactId>commons-attributes-compiler</artifactId>
    <version>2.2</version>
</dependency>

Installing the Plugin

You can install the plugin by checking out the sources and doing:

$ maven install
$ maven install-plugin

Alternatively, you can download the plugin and put it in your Maven plugin directory.

Project Properties

Since Maven will unconditionally apply all plugins to every project being compiled it is neccessary to explicitly enable the attribute compiler and/or indexer. This is simply to keep them from being run on projects that do not want anything to do with Commons-Attributes. The compiler and/or indexer are enabled by two project properties that you can set in your project.properties file or in your maven.xml file:

######################################################################
# Commons-Attributes
######################################################################
org.apache.commons.attributes.enable=true
org.apache.commons.attributes.index.enable=true

The first property will enable the attribute precompilation step. The second will enable the attribute indexing step that takes place after the jar:jar target. Both properties can be set independently of each other, although it makes little sense to enable indexing if compilation isn't enables as well.

Running the Demo

You should be able to unzip the demo files, cd into the directory and execute "maven run", like this:

$ unzip maven_demo.zip
$ cd maven_demo
$ maven run