The jOOQ User Manual
2.1. 2.1。 Configuration and setup of the generator
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 24 / 76
- -
The property file
- -
jooq.jar, jooq-meta.jar, jooq-codegen.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, eg C:\temp\jooq
- -
Go to C:\temp\jooq
- -
Run java -cp jooq.jar;jooq-meta.jar;jooq-codegen.jar;[JDBC-driver].jar;.
org.jooq.util.GenerationTool /[property 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:
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.
Page 25 第25页
The jOOQ User Manual
2.1. 2.1。 Configuration and setup of the generator
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 25 / 76
With the properties file as an argument
And the classpath set up correctly
Page 26 第26页
The jOOQ User Manual
2.1. 2.1。 Configuration and setup of the generator
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 26 / 76
Finally, run the code generation and see your generated artefacts
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:
Page 27 第27页
The jOOQ User Manual
2.1. 2.1。 Configuration and setup of the generator
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 27 / 76
文件集>
文件集>
的taskdef>
Note that when running code generation with ant's
task, you may have to set fork="true":
[...] [...]
JAVA>
Integrate generation with Maven
Using the official jOOQ-codegen-maven plugin, you can integrate source code generation in your Maven
build process:
Page 28 第28页
The jOOQ User Manual
2.1. 2.1。 Configuration and setup of the generator
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 28 / 76
org.jooq
jooq-codegen-maven
1.6.7
generate
的
的
postgresql
postgresql
8.4-702.jdbc4
依赖>
的
org.postgresql.Driver
jdbc:postgresql:postgres
postgres
test
org.jooq.util.DefaultGenerator
org.jooq.util.postgres.PostgresDatabase
.*
public
true
false
org.jooq.util.maven.example
target/generated-sources/jooq
配置>
See the full example of a pom.xml including the jOOQ-codegen artefact here: https://github.com/
lukaseder/jOOQ/blob/master/jOOQ-codegen-maven-example/pom.xml
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 /jooq-config.properties 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.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.
Page 29 第29页
The jOOQ User Manual
2.2. 2.2。 Advanced generator configuration
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 29 / 76
2.2. 2.2。 Advanced generator configuration
Code generation
In the previous section we have seen how jOOQ's source code generator is configured and run within a
few steps. In this chapter we'll treat some advanced settings
org.jooq.util.DefaultGenerator
org.jooq.util.DefaultGeneratorStrategy
The following example shows how you can override the DefaultGeneratorStrategy to render table and
column names the way they are defined in the database, rather than switching them to camel case:
Page 30 第30页
The jOOQ User Manual
2.2. 2.2。 Advanced generator configuration
jOOQ is brought to you by Lukas Eder. Distributed under the Apache 2 licence
Page 30 / 76
/** / **
* It is recommended that you extend the DefaultGeneratorStrategy. Most of the 大部分
* GeneratorStrategy API is already declared final. You only need to override any
找好工作,来深圳英才网:http://0755.job1001.com