gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:41:14 28 4
gpt4 key购买 nike

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

这些是我引用的教程:

给我带来错误的 ant 任务就是这个(我相信是因为未设置类路径):

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

给出的错误是:

Error: Could not find or load main class org.jooq.util.GenerationTool

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

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

但似乎库是手动导入的。如果使用 maven 导入库,我应该输入什么?

最佳答案

独立使用 Ant

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

  • JDBC 驱动程序
  • jooq-{版本}.jar
  • jooq-meta-{版本}.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

关于java - Ant/Jooq Generator - 使用 maven 导入的 jooq 库的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48530041/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com