Hi Federico

This is a common issue when creating some custom implementation of a code
generator extension and expecting the jOOQ GenerationTool to pick it up
from the classpath. It has to be ... on the classpath. So, this is more of
a Maven question than a jOOQ related one. For your custom EnumGenerator to
end up on the GenerationTool's classpath (or rather, the generator plugin's
classpath), you have to add it as a dependency. This is similar to when you
want to use the JPADatabase and have it pick up JPA annotated dependencies
from the classpath:
https://www.jooq.org/doc/latest/manual/code-generation/codegen-jpa

Essentially, just:

1. Create a separate Maven project containing your EnumGenerator
2. Add that project as a dependency to either your "main" project that runs
the code generator, or to the Maven plugin configuration for the code
generator

Note: You cannot place the EnumGenerator in the same project that runs the
code generator plugin, because the code generation phase is
"generate-sources", which happens before the "compile" phase in Maven. So
your EnumGenerator is simply not yet compiled and installed, when you
expect the code generator to consume it.

Hope this helps,
Lukas

On Wed, Sep 5, 2018 at 7:49 PM <[email protected]> wrote:

> Hi guys,
>
> I'm very stuck trying to create a custom generator. Have been
> investigating a lot regarding this and found this post on SO that is a
> similar problem to mine:
>
> https://stackoverflow.com/questions/46429671/generate-enum-class-from-table-with-jooq
>
> This post answer by Lukas, give a good idea of what I should do, however
> I'd need better details of implementation since I have no clue how to
> continue. I've created this SO question describing what I need in details
> https://stackoverflow.com/questions/52171377/how-build-a-jooq-custom-generator.
> Basically, I have a postgres schema named "enums" where all the tables are
> like TYPES("name", "description"), and I have to create all groovy (or
> java) enums like below:
>
> enum Types {
>     OPEN("open status"), CLOSE("close status");
>
>     private final String id;
>     Types(String id) { this.id = id; }
>     public String getValue() { return id; }}
>
>
> According the post answer I have to create a class extending from
> JavaGenerator, however I was even unable to trigger my custom generator
> from the maven plugin. So, by using `*mvn -e jooq-codegen:generate*` I
> found this error:
> Caused by: java.lang.ClassNotFoundException:
> com.ctgengine.customer.jooq.EnumGenerator
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>         at
> org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:819)
>
> In the maven plugin I have this snippet:
>
> <generator>
>     <!--<name>org.jooq.codegen.JavaGenerator</name>-->
>     <name>com.ctgengine.customer.jooq.EnumGenerator</name>
> ...
>
>
> And in my class I have:
>
> class EnumGenerator extends JavaGenerator {
>     @Override
>     void generateTables(SchemaDefinition schema) {
>     ....
>
>
> Anyway, if I uncomment the JavaGenerator everything works fine.
>
> So, I have two big gaps of knowledge where I need your help:
> - Why my code isn't being picked by the maven plugin?
> - Once I could link the plugin to my code, how can I do to generate groovy
> (or java) enums?
>
> Thanks a lot in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to