Ant / Jooq Generator - 使用maven导入的jooq库的路径

时间:2018-01-30 20:32:13

标签: java maven ant jooq

我有一个多模块maven项目,我正在实施ant任务,直接从jooq个实体生成jpa个类。

这些是我所指的教程:

我的蚂蚁任务给了我错误就是这个(我相信因为没有设置类路径):

<target name="02-gen-jooq">
    <java   classname="org.jooq.util.GenerationTool"
            fork="true"
            failonerror="true"
            logerror="true">

        <arg value="/jooq-config.xml"/> <!-- my jooq config file in project root folder -->
        <classpath>
            <!--
            <pathelement location="?"/> // what to put here??
            <pathelement location="?"/>
            <pathelement location="?"/>
            -->
        </classpath>
    </java>
</target>

给出的错误是:

  

错误:无法找到或加载主类org.jooq.util.GenerationTool

在本教程中,类路径设置如下:

<pathelement location="/path/to/jooq-3.5.4.jar"/>

但似乎手动导入了库。如果使用maven导入库,我应该放置什么?

1 个答案:

答案 0 :(得分:1)

使用Ant standalone

如果要在Maven之外触发代码生成,则必须将所有这些jar文件放在ant类路径中:

  • JDBC驱动程序
  • jooq- {版本}的.jar
  • jooq - 间{版本}的.jar
  • jooq-codegen- {版本}的.jar

另见: https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration

使用Maven中的Ant

您链接的手册部分显示了如何使用maven-antrun-plugin:

<!-- Run the code generation task -->
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <configuration>
        <tasks>
          <java fork="true" 
                classname="org.jooq.util.GenerationTool"
                classpathref="maven.compile.classpath">
              <arg value="/path/to/configuration.xml"/>
          </java>
       </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>

  <dependencies>
    <dependency>
      <!-- JDBC driver -->
    </dependency>
    <dependency>
      <groupId>org.jooq</groupId>
      <artifactId>jooq-codegen</artifactId>
      <version>${jooq.version}</version>
    </dependency>
  </dependencies>
</plugin>

重要的一点是:

classpathref="maven.compile.classpath"

这样,Maven类路径被传递给运行jOOQ代码生成器的ant进程。如果将此插件放在Maven配置文件中,则可以从命令行显式运行它,否则不会影响Maven构建生命周期。

当然,你可能最好使用这里记录的jooq-codegen-maven插件:

https://www.jooq.org/doc/latest/manual/code-generation/codegen-maven