我正在将Spring Boot 2.1.1与jOOQ代码生成工具3.11.7结合使用。我将Java类配置为稍微修改从pom.xml中的MySQL表名称派生的类名称:
<div class="wrapper">
<aside class="left_panel">
<nav>
<ul>
<li>Home</li>
<li>Manu item 1</li>
<li>Manu item 2</li>
<li>Manu item 3</li>
</ul>
</nav>
</aside>
<div class="right_panel">
<header>
<h1>Name of the website</h1>
</header>
<main>
<img id="lantern" class="f-right" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/PlaceholderLC.png/600px-PlaceholderLC.png" alt="">
<h2>Subheading 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim tristique varius. Orci varius natoque penatibus et magnis dis parturient. </p>
<h2>Subheading 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim tristique varius. </p>
<h2>Subheading 3</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim tristique varius. Orci varius natoque penatibus et magnis dis parturient. </p>
<h2>Subheading 4</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus dignissim tristique varius.</p>
</main>
<footer>
<p>Copyright © 2019</p>
</footer>
</div>
</div>
当我从IntelliJ构建/运行应用程序时,一切正常,但是当我在同一环境中从命令行运行<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>
或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
那里是类(否则IntelliJ也会抛出错误)。 IDE在使它起作用的幕后还能做些什么?
答案 0 :(得分:2)
您可以按照Lukas Eder的建议编译该类并将其放在类路径中。为此,请使用maven-compiler-plugin引入另一个执行并将其绑定到generate-sources阶段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<includes>
<include>tb/database/jooq/custom/namingstrategies/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
答案 1 :(得分:0)
jOOQ代码生成器必须可以通过类路径访问生成器策略,这意味着必须在运行代码生成器之前 对其进行编译。由于代码生成器通常在 所在的Maven模块的编译阶段运行,因此您必须将生成器策略提取到另一个模块中,以确保之前已被编译。