2017-05-03 87 views
1

我有一个问题,使用jooq codegen与JPADatabase。我已经通过这个post并作出相应的更改。我的项目包含子模块,实体类位于域模块中。我有一个依赖域的商业模块。所以我在biz模块的pom.xml中有这个构建配置。jooq codegen与JPADatabase不工作

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

插件失败,实体上出现ClassNotFoundException。这是堆栈跟踪。

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 

域模块类已经生成,但仍然插件说ClassNotFoundException。我正在使用jooq 3.9.1版本。谁能告诉我我在这里做错了什么?

更新:卢卡斯埃德的答案是正确的答案,并接受一个。我自己对这个问题的回答对我来说很合适,因为我在maven回购中缓存了特定的版本。我的回答是错误的。

+0

你把你的实体放在使用jOOQ代码生成器的模块的依赖关系中吗?请参阅:http://stackoverflow.com/q/42968155/521799 –

+0

是的。域模块是发生代码生成的商业模块中的依赖项。 – yaswanth

回答

1

您似乎遇到了问题#5845,该问题已修复为3.00版,计划为3.9.3和3.8.8。

现在最好的解决方法是使用jooq-meta-extensions依赖关系的GitHub版本(3.10-SNAPSHOT):https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions,或者相应地修补您的版本。

+0

如果我降级到3.8.0会有帮助吗? – yaswanth

+0

@yaswanth:不,为什么?这不是回归。自从JPADatabase第一次实现以来,这个问题一直存在。 –

+0

我认为类加载器问题是一个在更高版本中开始出现的错误。 – yaswanth

1

正在关注@Lukas Eder的回答,我尝试了#5845的建议。以下构建配置有效。

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

有关此配置奇怪的是,我包括模块作为一个插件在它自己的POM的建造轮廓的依赖!