New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3 | 2.6

Configuration and setup of the generator

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

There are three binaries available with jOOQ, to be downloaded from or from Maven central:

  • jooq-2.6.4.jar
    The main library that you will include in your application to run jOOQ
  • jooq-meta-2.6.4.jar
    The utility that you will include in your build to navigate your database schema for code generation. This can be used as a schema crawler as well.
  • jooq-codegen-2.6.4.jar
    The utility that you will include in your build to generate your database schema

Configure jOOQ's code generator

You need to tell jOOQ some things about your database connection. Here's an example of how to do it for an Oracle database

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <!-- Configure the database connection here -->
    <url>jdbc:oracle:thin:@[your jdbc connection parameters]</url>
    <user>[your database user]</user>
    <password>[your database password]</password>
    <!-- You can also pass user/password and other JDBC properties in the optional properties tag: -->

      <!-- The database dialect from jooq-meta. Available dialects are
           named org.jooq.util.[database].[database]Database. Known values are:

           org.jooq.util.ase.ASEDatabase (to be used with Sybase ASE)
           org.jooq.util.sybase.SybaseDatabase (to be used with Sybase SQL Anywhere)

           You can also provide your own org.jooq.util.Database implementation
           here, if your database is currently not supported or if you wish to
           read the database schema from a file, such as a Hibernate .hbm.xml file 
           Note the classes have been moved to org.jooq.meta in jOOQ 3.11 -->

      <!-- All elements that are generated from your schema (several Java
           regular expressions, separated by comma) Watch out for
           case-sensitivity. Depending on your database, this might be
           important! You can create case-insensitive regular expressions
           using this syntax: (?i:expr)A comma-separated list of regular
           expressions -->

      <!-- All elements that are excluded from your schema (several Java
           regular expressions, separated by comma). Excludes match before
           includes -->

      <!-- The schema that is used locally as a source for meta information.
           This could be your development schema or the production schema, etc
           This cannot be combined with the schemata element.

           If left empty, jOOQ will generate all available schemata. See the
           manual's next section to learn how to generate several schemata -->
      <inputSchema>[your database schema / owner / name]</inputSchema>

    <!-- Generation flags: See advanced configuration properties -->

      <!-- The destination package of your generated classes (within the
           destination directory) -->

      <!-- The destination directory of your generated classes -->

There are also lots of advanced configuration parameters, which will be treated in the manual's section about advanced code generation features Note, you can find the official XSD file for a formal specification at:

Run jOOQ code generation

Code generation works by calling this class with the above property file as argument.

org.jooq.util.GenerationTool /jooq-config.xml

Note: The GenerationTool class has been moved to org.jooq.codegen in jOOQ 3.11

Be sure that these elements are located on the classpath:

  • The XML configuration file
  • jooq-2.6.4.jar, jooq-meta-2.6.4.jar, jooq-codegen-2.6.4.jar
  • The JDBC driver you configured

A command-line example (For Windows, unix/linux/etc will be similar)

  • Put the property file, jooq*.jar and the JDBC driver into a directory, e.g. C:\temp\jooq
  • Go to C:\temp\jooq
  • Run java -cp jooq-2.6.4.jar;jooq-meta-2.6.4.jar;jooq-codegen-2.6.4.jar;[JDBC-driver].jar;. org.jooq.util.GenerationTool /[XML file]

Note that the property file must be passed as a classpath resource

Run code generation from Eclipse

Of course, you can also run code generation from your IDE. In Eclipse, set up a project like this. Note that this example uses jOOQ's log4j support by adding log4j.xml and log4j.jar to the project classpath:

Eclipse configuration

Once the project is set up correctly with all required artefacts on the classpath, you can configure an Eclipse Run Configuration for org.jooq.util.GenerationTool.

Eclipse configuration

With the XML file as an argument

Eclipse configuration

And the classpath set up correctly

Eclipse configuration

Finally, run the code generation and see your generated artefacts

Eclipse configuration

Run generation with ant

You can also use an ant task to generate your classes. As a rule of thumb, remove the dots "." and dashes "-" from the .properties file's property names to get the ant task's arguments:

<!-- Task definition -->
<taskdef name="generate-classes" classname="org.jooq.util.GenerationTask">
    <fileset dir="${}">
      <include name="jooq-2.6.4.jar"/>
      <include name="jooq-meta-2.6.4.jar"/>
      <include name="jooq-codegen-2.6.4.jar"/>
    <fileset dir="${}">
      <include name="${mysql.driver}.jar"/>

<!-- Run the code generation task -->
<target name="generate-test-classes">

Note that when running code generation with ant's <java/> task, you may have to set fork="true":

<!-- Run the code generation task -->
<target name="generate-test-classes">
  <java fork="true" classname="org.jooq.util.GenerationTool">

Integrate generation with Maven

Using the official jOOQ-codegen-maven plugin, you can integrate source code generation in your Maven build process:


  <!-- Specify the maven code generator plugin -->

  <!-- The plugin should hook into the generate goal -->

  <!-- Manage the plugin's dependency. In this example, we'll use a PostgreSQL database -->

  <!-- Specify the plugin configuration.
       The configuration format is the same as for the standalone code generator -->

    <!-- JDBC connection parameters -->

    <!-- Generator parameters -->

Migrate properties files from jOOQ 1.7, early versions of jOOQ 2.0.x:

Before jOOQ 2.0.4, the code generator was configured using properties files. These files are still supported for source code generation, but their syntax won't be maintained any longer. If you wish to migrate to XML, you can migrate the file using this command on the command line

org.jooq.util.GenerationTool / migrate

Using the migrate flag, jOOQ will read the properties file and output a corresponding XML file on system out

Use jOOQ generated classes in your application

Be sure, both jooq-2.6.4.jar and your generated package (see configuration) are located on your classpath. Once this is done, you can execute SQL statements with your generated classes.


Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo