Differences between revisions 1 and 2
Revision 1 as of 2005-06-20 15:32:50
Size: 7837
Editor: bdc34
Comment:
Revision 2 as of 2009-09-20 23:04:11
Size: 7837
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Using Ant to build Torque v3.1.1

Justification and Goals

bdc34: I am unfamiliar with Maven but I wanted to use Torque to build java objects for an existing MySQL db schema. After attempting to use maven, and failing, I used ant and configuration files from torque 3.1 to build torque 3.1.1. This is not a suggested procedure and you should us maven if you can.

The first step was configuring Torque 3.1.1 to use ant. Next the schema.xml needed to be generated using the ant target jdbc. Then the java objects could be built.

This was done an an winxp box with cygwin.

java and ant

  • I had nothing in jre/lib/ext. When I started there was something in that dir tha confused ant. I used jdk1.4.2 and ant 1.6.1.

downloading torque

  • download torque-gen.3.1.1.zip and unzip to dir $TORQ3_1_1 download torque-gen.3.1.zip and unzip to dir $TORQ3_1

Copy 3.1 config files to 3.1.1

  • We need the v3.1 config files from $TORQ3_1 in the $TORQ3_1_1 directory.
    • These include:

                $TORQ3_1/build-torque.xml
                $TORQ3_1/build.properties
                $TORQ3_1/commons-logging.properties
                $TORQ3_1/default.properties
                $TORQ3_1/simplelog.propertes

Edit build-torque.xml

The class path of the $TORQ3_1/build-torque.xml, which was just copied to $TORQ3_1_1/build-torque.xml needs to be corrected to use jars in $TORQ3_1_1/

*** diff of torque-gen-3.1/build-torque.xml and torque-gen-3.1.1/build-torque.xml
*** c:/DOCUME~1/bdc34/LOCALS~1/Temp/build-torque.xml  <<<< this is the original $TORQ3_1/build-torque.xml
--- c:/DOCUME~1/bdc34/LOCALS~1/Temp/build-torque.xml119324dP <<<< this is what you want to edit it to look like
***************
*** 22,28 ****
    <property file="${torque.contextProperties}"/>
    <property name="lib.dir" value="lib"/>
    <property name="torque.lib.dir" value="${lib.dir}"/>
!   <property name="torque.jar" value="torque-gen-3.1-rc.jar"/>
  
    <!--
      Build the classpath. Specifically point to each file we're including to avoid
--- 22,28 ----
    <property file="${torque.contextProperties}"/>
    <property name="lib.dir" value="lib"/>
    <property name="torque.lib.dir" value="${lib.dir}"/>
!   <property name="torque.jar" value="torque-gen-3.1.1.jar"/>
  
    <!--
      Build the classpath. Specifically point to each file we're including to avoid
***************
*** 33,46 ****
    -->
    <path id="torque-classpath">
      <fileset dir="${torque.lib.dir}">
!       <include name="**/commons-collections-2.1.jar"/>
!       <include name="**/commons-lang-1.0.1.jar"/>
        <include name="**/log4j-1.2.8.jar"/>
        <include name="**/${torque.jar}"/>
        <include name="**/velocity-1.3.1.jar"/>
!       <include name="**/village-2.0-dev-20030625.jar"/>
!       <include name="**/xercesImpl-2.0.2.jar"/>
!       <include name="**/xmlParserAPIs-2.0.2.jar"/>
        <include name="**/*.jar"/>
      </fileset>
    </path>
--- 33,48 ----
    -->
    <path id="torque-classpath">
      <fileset dir="${torque.lib.dir}">
!       <include name="**/commons-collections-3.0.jar"/>
!       <include name="**/commons-lang-2.0.jar"/>
        <include name="**/log4j-1.2.8.jar"/>
+       <include name="**/ant.jar"/>
        <include name="**/${torque.jar}"/>
        <include name="**/velocity-1.3.1.jar"/>
!       <include name="**/village-2.0-dev-20030825.jar"/>
!       <include name="**/xerces-2.4.0.jar"/>
!       <include name="**/xercesImpl-2.4.0.jar"/>
!       <include name="**/xml-apis-1.0.b2.jar"/>
        <include name="**/*.jar"/>
      </fileset>
    </path>

Set build.properties

  • I used this:

      # The name of the project Torque will generate code for.
      torque.project = vitro
    
      # The target database platform.
      torque.database = mysql
    
      # The target package to put the generated classes in.
      torque.targetPackage = edu.cornell.mannlib.vitro
    
      # The JDBC URL that Torque can use to create db's
      torque.database.createUrl = jdbc:mysql://localhost/junkCreateURL
      # The JDBC URL that will be used to create tables in your database.
      torque.database.buildUrl = jdbc:mysql://localhost/junkBuildURL
    
      # The JDBC URL that will be used to access your database.
      torque.database.url = jdbc:mysql://localhost/vivo3
    
      # The JDBC database driver to use when connecting to your database.
      torque.database.driver = org.gjt.mm.mysql.Driver
    
      # The administrative username that has sufficient privileges to create 
      # and drop databases and tables that Torque executes at generation time.
      torque.database.user =XXXyourUserXXX
    
      # The administrative password for the supplied username.
      torque.database.password =XXXyoupasswdXXX
    
      # The hostname or IP address of your database server.
      torque.database.host =localhost
    
      # The location of the your *-schema.xml files (see below).
      #torque.schema.dir = ./schema

Preparing the build dir

unpack the velocity templates from v3.1.1

The Maven based v3.1.1 build pulls the velocity templates out of the torque-gen.3.1.1.jar but the v3.1 build-torque.xml looks for them in directories. We need to unpack the v3.1.1 jar and copy the velocity template directories to $TORQ3_1_1/templates

unzip torque-gen.3.1.1.jar and move ./bla/bla/*.vm dir tree to ./templates/bla/bla/*.vm

There may be a way to set build.properties so that the jar's templates get used but I didn't look too hard for it.

get the jar files for $TORQ3_1_1/

The v3.1.1 zip comes with many jars that you need but here is the list I ended up using. I had to add the ant.jar (ant v1.6.1). Also you need to add a jdbc driver such as mysql-connector-java-3.0.16-ga-bin.jar.

This is what I had in my $TORQ3_1_1/lib:

  c:/usr/local/oldsrc/Vitro/dream/torque-gen-3.1.1/lib:
  -rw-rw-rw-   1 bdc34    root   999966 Jun 17 15:56 ant.jar
  -rw-rw-rw-   1 bdc34    root   518641 Nov  1  2004 commons-collections-3.0.jar
  -rw-rw-rw-   1 bdc34    root   169763 Nov  1  2004 commons-lang-2.0.jar
  -rw-rw-rw-   1 bdc34    root    35857 Nov  1  2004 commons-logging-1.0.4.jar
  -rw-rw-rw-   1 bdc34    root   352668 Mar 15 08:53 log4j-1.2.8.jar
  -rw-rw-rw-   1 bdc34    root   236079 Jun 17 16:43 mysql-connector-java-3.0.16-ga-bin.jar
  -rw-rw-rw-   1 bdc34    root   194203 Nov  1  2004 torque-gen-3.1.1.jar
  -rw-rw-rw-   1 bdc34    root   351405 Nov  1  2004 velocity-1.3.1.jar
  -rw-rw-rw-   1 bdc34    root    26081 Nov  1  2004 village-2.0-dev-20030825.jar
  -rw-rw-rw-   1 bdc34    root   895924 Mar 14 14:47 xerces-2.4.0.jar
  -rw-rw-rw-   1 bdc34    root   895924 Mar 14 14:48 xercesImpl-2.4.0.jar
  -rw-rw-rw-   1 bdc34    root   109318 Mar 14 14:46 xml-apis-1.0.b2.jar

Running torque

I was interested in generating a schema.xml from an existing database and then generating java object to access that.

These ant commands should be run from the $TORQ3_1_1 directory

Run the ant target to build the schema.xml form an existing db.

Run the command: ant -f build-torque.xml jdbc This will generate $TORQ3_1_1/schema/schema.xml

Making the java objects

Torque expects to find your schema file at $TORQ3_1_1/schema/${torque.project}-schema.xml but it puts the schema that it generates at $TORQ3_1_1/schema/schema.xml

Move $TORQ3_1_1/schema/schema.xml to $TORQ3_1_1/schema/vitro-schema.xml

Build the java db access objects

Run the command: ant -f build-torque.xml torque See the results: find . -name "*.java"

Final Notes

These instructions have not been tested. I just took notes as I foolishly stumbled around and finally got this to work. Please add comments and corrections.

UsingAntForV311 (last edited 2009-09-20 23:04:11 by localhost)