【问题标题】:jOOQ can't auto generate classesjOOQ 不能自动生成类
【发布时间】:2020-09-03 20:04:29
【问题描述】:

我正在尝试为我的 MySql 数据库自动生成 jOOQ java 代码,但它不起作用。我在 maven 的 JSP 项目中使用 jOOQ。

pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>MyHomeProject</groupId>
    <artifactId>MyHomeProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>13</release>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <executions>
                    <execution>
                        <id>generate-mysql</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <jdbc>
                                <driver>com.mysql.jdbc.Driver</driver>
                                <url>jdbc:mysql://localhost:3306/myprojectdb?useSSL=false&amp;serverTimezone=UTC</url>
                                <user>webuser</user>
                                <password>webuserP@$$*oR6</password>
                            </jdbc>
                            <generator>
                                <database>
                                    <name>org.jooq.meta.mysql.MySQLDatabase</name>
                                    <includes>.*</includes>
                                    <excludes></excludes>
                                    <inputSchema>public</inputSchema>
                                </database>
                                <target>
                                    <packageName>com.myproject.home.jooq</packageName>
                                    <directory>${basedir}\src</directory>
                                </target>
                            </generator>
                        </configuration>
                    </execution>
                </executions>

                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.13</version>
                    </dependency>
                </dependencies>

            </plugin>
        </plugins>
    </build>
    <dependencies>
        <!-- MySQL -->
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>8.0.13</version>
         </dependency>
        <!-- jOOQ -->
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.13.2</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.13.2</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.13.2</version>
        </dependency>
        <!-- Other dependencies here -->
        <!-- ... -->
        <!-- ... -->
        <!-- ... -->
    </dependencies>
</project>

我正在使用 Tomcat 在 Eclipse 上运行这个项目。当我想运行 Web 应用程序时,我清理项目,然后是 Project>properties>Deployment Assembly>Add>Java Build Path Entries>Maven Dependencies。

当我运行项目时,没有生成数据库的 java 代码。
正如documentation 中所说,由于我使用 maven 和 jOOQ,我可以自动生成 JAVA 代码而无需使用 cli。并且无需创建library.xml 文件。

我的问题是 jOOQ 不会使用这个 pom.xml 文件自动生成 JAVA 文件。我究竟做错了什么?我还需要进行其他配置吗?

【问题讨论】:

    标签: maven jsp jooq


    【解决方案1】:

    您指定:

    <inputSchema>public</inputSchema>
    

    默认情况下,MySQL 没有这样的架构。请改用您实际数据库的架构(区分大小写),或省略 inputSchema 以生成所有架构的代码。

    【讨论】:

    • 我省略了inputSchema。现在,当我清理和构建项目时,我可以看到在我的其他包旁边的src 目录下生成的com.myproject.home.jooq 包。但我无法将该包中的表导入到我的代码中:the import com.myproject.home.jooq.ANYTHING cannot be resolved
    • 我不得不刷新src 目录。现在它正在工作,谢谢。
    猜你喜欢
    • 2019-01-08
    • 2012-09-10
    • 2021-12-29
    • 2021-01-27
    • 2012-04-14
    • 2021-04-28
    • 2018-12-27
    • 2021-01-22
    • 1970-01-01
    相关资源
    最近更新 更多