0

我使用 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>

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

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

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

4

2 回答 2

0

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

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

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

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

于 2018-04-24T09:03:20.723 回答
0

jOOQ 开源版 3.7+ 版需要 Java 8 才能运行。如果您需要 Java 7 支持,则由 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>
于 2018-04-25T12:59:10.670 回答