##### General information

- Overview
- News and Status
- Downloads
- Addons
- Changes
- Old Changes
- Wiki
- Issue tracker
- Mailing lists
- Tools
- License
- Team
- Developer Information
- Sponsorship
- Security
- Thanks

##### Documentation

- Tutorial
  - OR-Mapping
    - step1-ant
    - step1-maven
    - step2
    - step3-ant
    - step3-maven
    - step4
    - step5
    - step6-ant
    - step6-maven
  - Code Generation
- OR Mapping Reference
- Code Generation Reference
- Module Documentation

##### Previous releases

- Torque 3.3

## Step 6: Compiling and Running the sample application

### Setting up the classpath

The libraries which the generated classes depend on are specified in the file pom.xml in the top level directory of the project. You already created this file in step 1 of the tutorial; and it already contains the dependencies to the Torque runtime, the mysql driver, and log4j, so nothing needs to be changed there.

Note: There is no need to include the torque-generator or torque-templates dependencies in your project.

### Building the sample application

Now that you've generated your object model with Torque, and created a sample application, you are now ready to compile and build everything. Again, Maven is used to control the build process. You can build your application by typing the following in the top-level directory of your project:

    mvn package

If you've done everything correctly, this should build without any errors. This means all of the source files will have been compiled to the target/classes folder and all libraries on which your application depends on will have been copied to the target/dependency folder. If the compiler misses any external libraries, review the <dependencies> section in your project.xml. Should you encounter other errors, go back and review your application code.

### Running the sample application

Before you run the sample application, you must first set your classpath (this was done automatically for you by Maven when you compiled). The classpath must include most of the jars in the target/dependency folder (There are some jars which are transitive dependencies to other jars which are not used, but there is no harm in including these). The classpath alsmo must include all of your application and object model classes located in target/classes. To run the application, change into the target directory of the application and type

    linux:
    java -cp classes:dependency/commons-beanutils-core-1.8.0.jar:dependency/commons-dbcp-1.3.jar:dependency/commons-collections-3.2.1.jar:dependency/commons-configuration-1.6.jar:dependency/commons-lang-2.6.jar:dependency/commons-logging-1.1.1.jar:dependency/commons-pool-1.5.6.jar:dependency/log4j-1.2.16.jar:dependency/mysql-connector-java-5.0.4.jar:dependency/torque-runtime-4.0.jar org.apache.torque.tutorial.om.Bookstore

    windows:
    java -cp classes;dependency/commons-beanutils-core-1.8.0.jar;dependency/commons-dbcp-1.3.jar;dependency/commons-collections-3.2.1.jar;dependency/commons-configuration-1.6.jar;dependency/commons-lang-2.6.jar;dependency/commons-logging-1.1.1.jar;dependency/commons-pool-1.5.6.jar;dependency/log4j-1.2.16.jar;dependency/mysql-connector-java-5.0.4.jar;dependency/torque-runtime-4.0.jar org.apache.torque.tutorial.om.Bookstore

If all goes well, you should see the following output:

      Full booklist:

      Title:     TCP/IP Illustrated, Volume 1
      ISBN:      0-201-63346-9
      Publisher: Addison Wesley Professional
      Author:    Stevens, W.

      Title:     Effective Java
      ISBN:      0-618-12902-2
      Publisher: Addison Wesley Professional
      Author:    Bloch, Joshua

      Booklist (specific ISBN):

      Title:     TCP/IP Illustrated, Volume 1
      ISBN:      0-201-63346-9
      Publisher: Addison Wesley Professional
      Author:    Stevens, W.

      Booklist (authors swapped):

      Title:     TCP/IP Illustrated, Volume 1
      ISBN:      0-201-63346-9
      Publisher: Addison Wesley Professional
      Author:    Bloch, Joshua

      Title:     Effective Java
      ISBN:      0-618-12902-2
      Publisher: Addison Wesley Professional
      Author:    Stevens, W.

      Booklist (should be empty):

If your application throws an exception, it could be for one of many reasons, most of which are not very descriptive unfortunately. Do not be discouraged if your application does not run the first time. Carefully retrace all of the steps outlined in this tutorial. If you are still not able to get your application to run, use the Torque user mailing list to your advantage.

## Where to Go From Here

Congratulations! You have completed the Torque ORM tutorial. Although this has only been an introduction to Torque, it should be sufficient to get you started with Torque in your applications. For those of you seeking additional information, there are several other documents on this site that can provide details on various subjects. Lastly, the source code is an invaluable resource when all else fails to provide answers!

## User Comments

User comments for this step