jOOQ利用maven插件生成代码出现异常

java.lang.ClassNotFoundException: org.jooq.util.mysql.MySQLDatabase。

See https://github.com/jOOQ/jOOQ/issues/7419。

出现这类问题,一般是由于使用了高版本jdk,引发的Java模块化(JPMS)异常提示。问题根源在于相关的依赖包命名不规范所致。比如:多个jar包都使用了相同的包名。

较早的jOOQ版本,jooq、jooq-meta/jooq-codegen都存在包名冲突问题(对于java9模块化而言是不规范),这些包中都包含了org.jooq.util包名。在java没有采用模块化之前这是没有问题的。但在Java 9/JPMS以后这是行不通的。所以在jOOQ的后来版本中,对包名作了重新规划,具体如下:

jooq-meta: org.jooq.meta
jooq-meta-extensions: org.jooq.meta.extensions
jooq-codegen: org.jooq.codegen
jooq-codegen-maven: org.jooq.codegen.maven

如MySQLDatabase在jOOQ早期版本中出现在org.jooq.util下,在按Java 9/JPMS规范做了重新规划后,被安排在org.jooq.meta包下。
所说在使用jOOQ时出现此类问题可以直接修改包名即可解决。

以下是jOOQ异常示例:

[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.11.9:generate (default) on project web: Error running jOOQ code generation tool: Your configured org.jooq.util type was not found.
[ERROR] Do note that in jOOQ 3.11, jOOQ-meta and jOOQ-codegen packages have been renamed. New package names are:
[ERROR] - org.jooq.meta
[ERROR] - org.jooq.meta.extensions
[ERROR] - org.jooq.codegen
[ERROR] - org.jooq.codegen.maven
[ERROR] See https://github.com/jOOQ/jOOQ/issues/7419 for details: org.jooq.util.mysql.MySQLDatabase
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jooq:jooq-codegen-maven:3.11.9:generate (default) on project web: Error running jOOQ code generation tool
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)

Caused by: org.apache.maven.plugin.MojoExecutionException: Error running jOOQ code generation tool
    at org.jooq.codegen.maven.Plugin.execute(Plugin.java:200)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
Caused by: java.lang.ClassNotFoundException: Your configured org.jooq.util type was not found.
Do note that in jOOQ 3.11, jOOQ-meta and jOOQ-codegen packages have been renamed. New package names are:
- org.jooq.meta
- org.jooq.meta.extensions
- org.jooq.codegen
- org.jooq.codegen.maven
See https://github.com/jOOQ/jOOQ/issues/7419 for details
    at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:857)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:364)
    ... 22 more
Caused by: java.lang.ClassNotFoundException: org.jooq.util.mysql.MySQLDatabase
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:821)
    ... 25 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException