Step 1: Installing Maven 1 and the Torque Maven Plugin

First of all, note that Torque is divided into four parts.

  • The generator generates your persistence classes from an xml description of the database. It also generates and executes sql scripts to create all the necessary tables, constraints etc. in your database. The generator comes packaged in two jars: The templates in torque-gen-templates.jar, and the rest in torque-gen.jar. In this tutorial, you will not use the generator directly, but you will invoke it using the Maven 1 plugin. This also means that you do not have to download the generator separately from the maven 1 plugin.
  • The Maven 1 plugin integrates the generator into Maven 1, a software project management tool. In other words, the maven plugin is a frontend for the generator.
  • The runtime has to be included in your projects for the generated classes to work properly.
  • There is also a Maven 2 plugin available, but this is not covered in this tutorial.
For this tutorial, we will be using the maven 1 plugin for Torque 3.3 (which will silently invoke the generator) to generate our object model classes and sql scripts. For working with the generated classes, we will use the Torque 3.3 runtime for our sample application.

If you have not already done so, download and install Maven 1. It is highly recommended to use version 1.0.2 of Maven. You can not use the Torque Maven 1 plugin with Maven 2.

Maven uses an online repository to download any libraries and resources it need. The default for this has been the ibiblio maven repository. However, this has been moved and now Maven 1.0.x is unable to find required dependencies without a minor configuration change. (For more information see the Maven 1.1 Site.)

In order to find the files that Torque needs, you will need to create a file named project.properties in your user's home directory. e.g. C:\Documents and Settings\userid on Windows or ~userid on *nix. This file only needs the following line in it:

    maven.repo.remote=http://repo1.maven.org/maven

Once you have done this, obtain the Torque maven plugin by typing:

maven plugin:download -DartifactId=maven-torque-plugin -DgroupId=torque -Dversion=3.3

You do not need to download the generator or the runtime separately. Maven will download them from the ibiblio distribution site automatically when they are needed.

Where to next

Next we will look at Configuring the Torque generator.

User Comments

User comments for this step