使用 jooq-codegen-maven 时如何将生成的源设置为目标字节码 1.7

How to set the generated sources as target bytecode 1.7 when using jooq-codegen-maven

我使用 JOOQ 来实现 MySQL DAO 层。而我的部分pom.xml如下,

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen-maven</artifactId>
            <version>3.9.1</version>

            <!-- The plugin should hook into the generate goal -->
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>

            <dependencies />

            <configuration>
                <jdbc>
                    <driver>${jdbc.driver}</driver>
                    <url>${jdbc.url}</url>
                    <user>${jdbc.user}</user>
                    <password>${jdbc.password}</password>
                </jdbc>

                <generator>
                    <database>

                    </database>
                    <target>

                    </target>
                </generator>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass />
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我通过 mvn package 获得了 jar 文件。但是当我运行jar文件时,出现错误:

java.lang.UnsupportedClassVersionError: org/jooq/Table : Unsupported major.minor version 52.0    

我了解到我可以将我的 运行ning JDK 版本更新到更高版本,或者用较低版本编译生成的 类 jooq。这里我不得不选择后一种方法。但是我将maven-compiler-plugin的目标设置为1.7后,结果并没有达到我的预期。我很困惑,因为我仍然收到此错误。那么我怎样才能实现我的目标呢?

版本 52.0 是 java 8,因此我认为您需要更改

中的值

< maven.compiler.source>1.8< /maven.compiler.source>

< maven.compiler.target>1.8< /maven.compiler.target>

或者您可以找到支持 java 1.8 的更新版本的 JOOQ?

jOOQ 开源版 3.7+ 版需要 Java 8 到 运行。如果你需要Java7支持,那就是jOOQ专业版和jOOQ企业版提供的。在此处查看版本支持: https://www.jooq.org/download/versions

特别是,您定义了指向 JDK 8:

的 Maven 属性
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

但是您没有在编译器插件配置中使用它们。你应该切换这个:

<source>1.7</source>
<target>1.7</target>

为此:

<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>