
Question:
I have an issue using jooq codegen with JPADatabase. I have gone through this <a href="https://stackoverflow.com/questions/42968155/unable-to-generate-jooq-classes-from-h2-using-jpadatabase" rel="nofollow">post</a> and made the changes accordingly. My project contains sub modules and the entity classes are in domain module. I have biz module on which depends on domain. So I have this build configuration in biz module's pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
<configuration>
<!-- Generator parameters -->
<generator>
<database>
<name>org.jooq.util.jpa.JPADatabase</name>
<properties>
<!-- A comma separated list of Java packages, that contain your entities -->
<property>
<key>packages</key>
<value>com.yaswanth.domain.entity</value>
</property>
</properties>
</database>
<target>
<packageName>com.yaswanth.domain.entity.jooq</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</plugin>
</plugins>
</build>
The plugin fails with ClassNotFoundException on the entities. This is the stack trace.
Caused by: org.jooq.exception.DataAccessException: Error while exporting schema
at org.jooq.util.jpa.JPADatabase.create0(JPADatabase.java:147)
at org.jooq.util.AbstractDatabase.create(AbstractDatabase.java:221)
at org.jooq.util.AbstractDatabase.create(AbstractDatabase.java:213)
at org.jooq.util.AbstractDatabase.getDialect(AbstractDatabase.java:195)
at org.jooq.util.AbstractGenerator.logDatabaseParameters(AbstractGenerator.java:129)
at org.jooq.util.JavaGenerator.generate(JavaGenerator.java:243)
at org.jooq.util.GenerationTool.run(GenerationTool.java:610)
at org.jooq.util.GenerationTool.generate(GenerationTool.java:199)
at org.jooq.util.maven.Plugin.execute(Plugin.java:188)
... 22 more
Caused by: java.lang.ClassNotFoundException: com.walmartlabs.sc.domain.entity.ItemNames
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.jooq.util.jpa.JPADatabase.create0(JPADatabase.java:135)
... 30 more
The domain module classes have already been generated but still the plugin says ClassNotFoundException. I am using jooq version 3.9.1. Can anyone tell me what am I doing wrong here?
Update: Lukas Eder's answer is correct answer and accepted one. My own answer for this question worked for me because I had that specific version cached in the maven repo. My answer is wrong.
Answer1:You seem to have run into issue <a href="https://github.com/jOOQ/jOOQ/issues/5845" rel="nofollow">#5845</a>, which is fixed for jOOQ 3.10 and is scheduled for 3.9.3 and 3.8.8.
The best workaround right now might be to use the GitHub version (3.10-SNAPSHOT) of the jooq-meta-extensions dependency: <a href="https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions" rel="nofollow">https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions</a>, or patch your version accordingly.
Answer2:Following @Lukas Eder's answer, I have tried on the suggestions from <a href="https://github.com/jOOQ/jOOQ/issues/5845" rel="nofollow">#5845</a>. The following build configuration works.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>3.9.1</version>
</dependency>
<!--
This needs to be the dependency where the entity classes reside.
In my case, it is in the same module as the build profile is present.
Hence the version is ${project.version}
-->
<dependency>
<groupId>com.yaswanth</groupId>
<artifactId>domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<!-- Generator parameters -->
<generator>
<database>
<name>org.jooq.util.jpa.JPADatabase</name>
<properties>
<!-- A comma separated list of Java packages, that contain your entities -->
<property>
<key>packages</key>
<value>com.yaswanth.domain.entity</value>
</property>
</properties>
</database>
<target>
<packageName>com.yaswanth.domain.entity.jooq</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</plugin>
</plugins>
The weird thing about this configuration is that I am including the module as a dependency in a plugin in build profile of it's own POM!!