我正在使用带有jOOQ codegen工具3.11.7的Spring Boot 2.1.1。我有一个Java类配置为稍微修改从pom.xml中的MySQL表名派生的类名:
<generator>
<target>
<packageName>com.example.foglight.db</packageName>
<directory>src/main/java</directory>
</target>
<database>
<excludes>
flyway_schema_history
| information_schema.*
</excludes>
<inputSchema>${dbName}</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>
<forcedTypes>
<forcedType>
<userType>java.util.UUID</userType>
<binding>com.example.foglight.config.db.MysqlUuidBinding</binding>
<types>BINARY\(16\)</types>
</forcedType>
</forcedTypes>
</database>
<generate>
<deprecationOnUnknownTypes>false</deprecationOnUnknownTypes>
<pojos>true</pojos>
</generate>
<!-- The default code generator. You can override this one, to generate your own code style
Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>
<!-- The naming strategy used for class and field names.
You may override this with your custom naming strategy. Some examples follow
Defaults to org.jooq.codegen.DefaultGeneratorStrategy -->
<strategy>
<name>com.example.foglight.config.db.DatabaseModelNamingStrategy</name>
</strategy>
</generator>
当我从IntelliJ构建/运行应用程序时,一切正常,但是当我在同一环境中从命令行运行mvn generate-sources
或mvn install
时,我收到以下错误:
[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.11.7:generate (default) on project foglight: Error running jOOQ code generation tool: com.example.foglight.config.db.DatabaseModelNamingStrategy -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jooq:jooq-codegen-maven:3.11.7:generate (default) on project foglight: Error running jOOQ code generation tool
详细解释如下:
Caused by: java.lang.ClassNotFoundException: com.example.foglight.config.db.DatabaseModelNamingStrategy
at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.jooq.codegen.GenerationTool.loadClass (GenerationTool.java:819)
at org.jooq.codegen.GenerationTool.run (GenerationTool.java:352)
at org.jooq.codegen.GenerationTool.generate (GenerationTool.java:220)
at org.jooq.codegen.maven.Plugin.execute (Plugin.java:197)
这个类在那里(否则IntelliJ也会抛出错误)。 IDE是否还有其他更多工作要做?
jOOQ代码生成器必须通过类路径访问您的生成器策略,这意味着必须在运行代码生成器之前编译它。由于代码生成器通常在包含它的Maven模块的编译阶段之前运行,因此您必须将生成器策略提取到另一个模块中以确保它之前被编译。