[英]Ant / Jooq Generator - path to jooq libraries imported with maven
I have a multi-module maven
project and I'm implementing an ant
task to generate jooq
classes directly from jpa
entities. 我有一个多模块
maven
项目,并且正在实现一个ant
任务,以直接从jpa
实体生成jooq
类。
These are tutorials I am referring to: 这些是我指的教程:
My ant task that gives me errors is this one (I believe because the classpath is not set): 我给我带来错误的ant任务是这个(我相信是因为未设置classpath):
<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>
The error given is: 给出的错误是:
Error: Could not find or load main class org.jooq.util.GenerationTool
错误:找不到或加载主类org.jooq.util.GenerationTool
In the tutorial, the classpath is set as follows: 在本教程中,类路径的设置如下:
<pathelement location="/path/to/jooq-3.5.4.jar"/>
but it seems the libraries were manually imported. 但似乎库是手动导入的。 What should I put if the libraries are imported with
maven
? 如果使用
maven
导入库,我该怎么办?
You have to put all of these jar files on your ant classpath if you want to trigger the code generation outside of Maven: 如果要触发Maven外部的代码生成,则必须将所有这些jar文件放在ant类路径上:
See also: https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration 另请参阅: https : //www.jooq.org/doc/latest/manual/code-generation/codegen-configuration
The manual section you've linked shows how to use the maven-antrun-plugin: 您链接的手册部分显示了如何使用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>
The important line is: 重要的一行是:
classpathref="maven.compile.classpath"
This way, the Maven class path is passed to the ant process running the jOOQ code generator. 这样,Maven类路径将传递给运行jOOQ代码生成器的ant进程。 If you put this plugin in a Maven profile, you can run it explicitly from the command line, without it affecting the Maven build lifecycle otherwise.
如果将此插件放在Maven配置文件中,则可以从命令行显式运行它,而不会影响Maven构建生命周期。
Of course, you're probably better off using the jooq-codegen-maven plugin as documented here: 当然,您最好使用jooq-codegen-maven插件,如下所示:
https://www.jooq.org/doc/latest/manual/code-generation/codegen-maven https://www.jooq.org/doc/latest/manual/code-generation/codegen-maven
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.