简体   繁体   中英

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

I use JOOQ to implement MySQL DAO layer. And my part of pom.xml is as below,

<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>

I got the jar file by mvn package . But when I run the jar file, the error occurs:

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

I learned that I could update my running JDK version to a higher one, or compile the jooq generated classes with a lower version. Here I have to choose the latter method. But the result didn't meet my expectation after I set the target of maven-compiler-plugin to 1.7. I am confused since I still get this error. So how can I achieve my goal?

version 52.0 is java 8, therefore i think you need to change the value in

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

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

or perhaps you could find a newer version of JOOQ that supports java 1.8?

The jOOQ Open Source Edition version 3.7+ requires Java 8 to run. If you need Java 7 support, that is provided by the jOOQ Professional Edition and jOOQ Enterprise Edition. See version support here: https://www.jooq.org/download/versions

In particular, you have defined Maven properties that point to the JDK 8:

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

But you're not using them in your compiler plugin configuration. You should switch this:

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

To this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM