调试“jOOQ代码生成工具配置错误”
Posted
技术标签:
【中文标题】调试“jOOQ代码生成工具配置错误”【英文标题】:Debugging "Incorrect configuration of jOOQ code generation tool" 【发布时间】:2018-12-15 23:49:07 【问题描述】:我正在尝试跟随 jOOQ 教程。我在Step 3(代码生成),但想使用 Maven 执行代码生成步骤。
这是我pom.xml
的内容:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.hiew</groupId>
<artifactId>jooq-tutorial</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.11.2</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.11.2</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.11.2</version>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.1.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Specify the maven code generator plugin -->
<!-- Use org.jooq for the Open Source Edition
org.jooq.pro for commercial editions,
org.jooq.pro-java-6 for commercial editions with Java 6 support,
org.jooq.trial for the free trial edition
Note: Only the Open Source Edition is hosted on Maven Central.
Import the others manually from your distribution -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.2</version>
<executions>
<execution>
<id>jooq-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- Configure the database connection here -->
<jdbc>
<driver>org.mariadb.jdbc.Driver</driver>
<url>jdbc:mariadb://localhost:3306/library</url>
<user>root</user>
<password>mysql</password>
</jdbc>
<generator>
<!-- The default code generator. You can override this one, to generate your own code style.
Supported generators:
- org.jooq.codegen.JavaGenerator
- org.jooq.codegen.ScalaGenerator
Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<!-- The database type. The format here is:
org.util.[database].[database]Database -->
<name>org.jooq.meta.mariadb.MariaDBDatabase</name>
<!-- The database schema (or in the absence of schema support, in your RDBMS this
can be the owner, user, database name) to be generated -->
<inputSchema>library</inputSchema>
<!-- All elements that are generated from your schema
(A Java regular expression. Use the pipe to separate several expressions)
Watch out for case-sensitivity. Depending on your database, this might be important! -->
<includes>.*</includes>
<!-- All elements that are excluded from your schema
(A Java regular expression. Use the pipe to separate several expressions).
Excludes match before includes, i.e. excludes have a higher priority -->
<excludes></excludes>
</database>
<target>
<!-- The destination package of your generated classes (within the destination directory) -->
<packageName>net.hiew.jooqtutorial.generated</packageName>
<!-- The destination directory of your generated classes. Using Maven directory layout here -->
<directory>/home/james/src/local/jooqtutorial/src/main/java/</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的项目目录:
我在运行mvn -e jooq-codegen:generate
时遇到的错误:
[INFO] --- jooq-codegen-maven:3.11.2:generate (default-cli) @ jooq-tutorial ---
[ERROR] Incorrect configuration of jOOQ code generation tool
[ERROR]
The jOOQ-codegen-maven module's generator configuration is not set up correctly.
This can have a variety of reasons, among which:
- Your pom.xml's <configuration> contains invalid XML according to jooq-codegen-3.11.0.xsd
- There is a version or artifact mismatch between your pom.xml and your commandline
错误消息没有多大帮助,所以我不确定进一步调试问题的最佳方法。 pom.xml
验证并且数据库存在并且可以按照<configuration>
元素中的描述进行访问。
【问题讨论】:
【参考方案1】:配置标签必须直接在插件标签下,而不是在执行内部:
<plugin>
...
<executions>
...
</executions>
<configuration>
...
</configuration>
...
</plugin>
完整的插件标签:
<plugin>
<!-- Specify the maven code generator plugin -->
<!-- Use org.jooq for the Open Source Edition org.jooq.pro for commercial editions, org.jooq.pro-java-6 for commercial editions with Java 6 support, org.jooq.trial for the free trial edition Note: Only the Open Source Edition is hosted on Maven Central. Import the others manually from your distribution -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.2</version>
<executions>
<execution>
<id>jooq-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>$mariadb.version</version>
</dependency>
</dependencies>
<configuration>
<!-- Configure the database connection here -->
<jdbc>
<driver>org.mariadb.jdbc.Driver</driver>
<url>jdbc:mariadb://localhost:3306/library</url>
<user>root</user>
<password>mysql</password>
</jdbc>
<generator>
<!-- The default code generator. You can override this one, to generate your own code style. Supported generators: - org.jooq.codegen.JavaGenerator - org.jooq.codegen.ScalaGenerator Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<!-- The database type. The format here is: org.util.[database].[database]Database -->
<name>org.jooq.meta.mariadb.MariaDBDatabase</name>
<!-- The database schema (or in the absence of schema support, in your RDBMS this can be the owner, user, database name) to be generated -->
<inputSchema>library</inputSchema>
<!-- All elements that are generated from your schema (A Java regular expression. Use the pipe to separate several expressions) Watch out for case-sensitivity. Depending on your database, this might be important! -->
<includes>.*</includes>
<!-- All elements that are excluded from your schema (A Java regular expression. Use the pipe to separate several expressions). Excludes match before includes, i.e. excludes have a higher priority -->
<excludes>
</excludes>
</database>
<target>
<!-- The destination package of your generated classes (within the destination directory) -->
<packageName>net.hiew.jooqtutorial.generated</packageName>
<!-- The destination directory of your generated classes. Using Maven directory layout here -->
<directory>/home/james/src/local/jooqtutorial/src/main/java/</directory>
</target>
</generator>
</configuration>
</plugin>
请注意,您可能需要在依赖项中指定您的 mariadb 版本,我添加了默认变量名。
【讨论】:
谢谢!这更进一步。现在它吐出一个不同的错误:Error running jOOQ code generation tool: Error generating code for catalog: Error writing /home/james/src/local/jooqtutorial/src/main/java/net/hie w/jooqtutorial/generated/DefaultCatalog.java: /home/james/src/local/jooqtutorial/src/main/java/net/hiew/jooqtutorial/generated/DefaultCatalog.java (No such file or directory)
。我创建了应该生成 DefaultCatalog.java
的完整路径,但它仍然以同样的方式失败。
@JamesHiew 似乎只是与目标路径有关的错误,您确定路径正确吗?另外注意,目标<directory>src/main/java/</directory>
可以使用maven的相对路径,这样可能更方便。
@wallek876 这为我节省了很多工作。我的配置与 OP 相同,但奇怪的是 mvn clean package
工作正常但 mvn jooq-codegen:generate
没有。我更改了您的答案,现在一切正常。谢谢+1【参考方案2】:
除了wallek876's answer,您可以将您的executionId 重命名为default-cli
as documented here。所以,这应该工作:
<executions>
<execution>
<id>default-cli</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- Configure the database connection here -->
<jdbc>
...
另一个我一直喜欢的选择是使用配置文件:
<profiles>
<profile>
<id>jooq-codegen</id>
<build>
<plugins>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.2</version>
...
然后,运行它
mvn install -P jooq-codegen
【讨论】:
它提供与mvn -e jooq-codegen:generate
相同的输出
Maven 3.5.4 在 Oracle Java 9 上运行。没有骰子。
@JamesHiew:更新了答案以上是关于调试“jOOQ代码生成工具配置错误”的主要内容,如果未能解决你的问题,请参考以下文章
DjangoDjango Debug Toolbar调试工具配置