I'm trying to use JOOQ to generate code files from an existing database in a Spring Boot application. However, when I run the maven plugin, I'm getting the following error:
[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.13.3:generate (default-cli) on project english-learners: Error running jOOQ code generation tool: Your configured database type was not found. This can have several reasons:
[ERROR] - You want to use a commercial jOOQ Edition, but you pulled the Open Source Edition from Maven Central.
[ERROR] - You have mis-typed your class name. org.jooq.meta.sqlserver.SQLServerDatabase
I'm unclear what this error means - I copied the name from the documentation. I've tested, and can connect to the database. I assume there's something wrong with my configuration.
Here's my plugin configuration:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<dependencies>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbc>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>${datasource.url}</url>
<user>${datasource.username}</user>
<password>${datasource.password}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.sqlserver.SQLServerDatabase</name>
<includes>.*</includes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>my.project</packageName>
</target>
</generator>
</configuration>
</plugin>
Versions:
Java 14
Spring Boot 2.3.2.RELEASE
JOOQ 3.13.3
mssql-jdbc 8.4.0.jre14
MS SQL 2012
Can anyone help me with my configuration or point out what I'm doing wrong?
jOOQ is not free for commercial databases.
Please check out: https://www.jooq.org/download/
Related
I am trying to use the jooq code generation plugin to point to my liquibase change set. I am using the following plugin configuration
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.15.5</version>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions-liquibase</artifactId>
<version>3.15.5</version>
</dependency>
</dependencies>
<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<id>jooq-generate</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generator>
<database>
<name>org.jooq.meta.extensions.liquibase.LiquibaseDatabase</name>
<properties>
<property>
<key>scripts</key>
<value>src/main/resources/schemas/sql/changelog-root.xml</value>
</property>
</properties>
</database>
<generate>
<daos>true</daos>
<fluentSetters>true</fluentSetters>
</generate>
</generator>
</configuration>
</plugin>
However I get this error
[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.15.5:generate (jooq-generate) on project cas: Error running jOOQ code generation tool: Error while exporting schema: src/main/resources/schemas/sql/changelog-root.xml does not exist -> [Help 1]
The file does exist at the location specified but the plugin can't seem to find it.
Does anyone know why this happens?
Thanks
Hopefully this will be useful to others.
This was a bug in jooq which is now fixed
https://github.com/jOOQ/jOOQ/issues/12872
I'm using the swagger-codegen-maven-plugin within my pom to generate a client. Here is my plugin info:
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.9</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.json</inputSpec>
<language>java</language>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Using:
java version "1.8.0_221"
Apache Maven 3.6.1
I had many errors when running mvn compile, as the package names could not be found in my repo e.g.
[ERROR]
//target/generated-sources/swagger/src/main/java/io/swagger/client/model/.java:[18,23]
package com.google.gson does not exist
To overcome the errors and enable a successful mvn compile, I have had to name the missing packages within my pom's dependencies e.g.
<dependencies>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
I don't believe this is best practice, as I have to specify the version myself without knowing the actual version that the source has used.
My question is, what is the best practice for generating a client using maven when there are packages which can't be resolved by the swagger-codegen-plugin? Alternatively, please advise if the resolution I have found to overcome the issue is actually the best practice in this scenario?
Thanks.
To generate java classes from XSD (for reading XML files), we used jaxb2-maven-plugin and Java8.
For java 11, we get many issues...
What libraries and plugins do work (today), allowing to generate java code from XSD using java 11 and maven? If possible point out different solutions, such as with cxf-xjc-plugin, jaxb2-Maven-Plugin and others.
I've just investigated the same topic. The best way for Java 11 is to use cxf-xjc-plugin. It's a Maven plugin. No other Maven plugin is able to work under Java 11 without annoying workarounds.
I've published a complete example with cxf-xjc-plugin here: https://artofcode.wordpress.com/2019/02/28/generating-classes-from-xsd-under-java-11-the-right-way/
I was able to get Jaxb2-maven-plugin to work with Java 11. By default the generated classes will be created in the generated classes package. My only gripe is that it doesn't implement toString methods. If I ever figure that out i'll update this.
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
</dependency>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>xjc-foo</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<!-- if you put path only, it will read any wsdl or xsd file -->
<!-- if you have xsd that is imported in wsdl, then make sure you point it wsdl file -->
<source>${project.basedir}/src/main/resources/schemas/foo.wsdl</source>
</sources>
<clearOutputDir>false</clearOutputDir>
<packageName>foo</packageName>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation.api</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
</plugin>
I am trying to use OpenDaylight to generate Pojos from Yang files according to this guide.
I cloned Yangtools from OpenDaylight github and built the project with mvn clean install
i've added the following to my pom:
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
<version>2.0.8-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
<configuration>
<!-- directory containing yang files to parse and generate code -->
<yangFilesRootDir>src/main/yang</yangFilesRootDir>
<codeGenerators>
<generator>
<codeGeneratorClass>
org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl
</codeGeneratorClass>
<!-- directory into which generated files will be placed -->
<outputBaseDir>
target/generated-sources
</outputBaseDir>
</generator>
</codeGenerators>
<!-- if true, plugin will search for yang files also in dependent projects -->
<inspectDependencies>true</inspectDependencies>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<version>0.7.4-Lithium-SR4</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
however i am unable to generate the sources. I am getting the following error:
[ERROR] Failed to execute goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources (default) on project odl-poc: Execution default of goal org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources failed: An API incompatibility was encountered while executing org.opendaylight.yangtools:yang-maven-plugin:2.0.8-SNAPSHOT:generate-sources: java.lang.AbstractMethodError: Method org/opendaylight/yangtools/maven/sal/api/gen/plugin/CodeGeneratorImpl.generateSources(Lorg/opendaylight/yangtools/yang/model/api/SchemaContext;Ljava/io/File;Ljava/util/Set;Ljava/util/function/Function;)Ljava/util/Collection; is abstract
what am i doing wrong?
Looks like a version incompatibility - you're referencing yang-maven-plugin version 2.0.8-SNAPSHOT, which is the current unreleased master branch, and dependency maven-sal-api-gen-plugin version 0.7.4-Lithium-SR4, which was like 5 major releases ago and long obsolete.
I'm in the process of converting our db management to Liquibase. This is running along nicely.
As a subsequent step I want to assure that all future modifications gets tested before deploy to common environments, continuous integration style. I try to do this using the following setup:
Build our ear containing EJB webservices
Using maven-embedded-glassfish-plugin to start an embedded instance of Glassfish 3 during pre-integration-test maven ohase
Create my datasource as part of start goal
Deploy ear during deploy goal
Still in pre-integration-test, I run liquibase:update on the same database URL. In this case a H2 file database
I then want to run our SoapUI tests on the deployed application
But when i get this far the application can't find any data in the database. So the question is if I've missed something in my setup or if there's a better way to organize my intended goal?
pom.xml, embedded Glassfish
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>4.0</version>
<configuration>
<ports>
<http-listener>9090</http-listener>
<https-listener>9191</https-listener>
</ports>
<goalPrefix>embedded-glassfish</goalPrefix>
<app>${project.build.directory}/school-application-${project.version}.ear</app>
<name>school-application</name>
<commands>
<command>create-jdbc-connection-pool --datasourceclassname=org.h2.jdbcx.JdbcDataSource --restype=javax.sql.DataSource --property URL=jdbc\:h2\:~/tmpLB\;AUTO_SERVER\=TRUE schoolDSPool</command>
<command>create-jdbc-resource --connectionpoolid schoolDSPool jdbc/schoolDS</command>
</commands>
</configuration>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>start</goal>
<goal>admin</goal>
<goal>deploy</goal>
<goal>undeploy</goal>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
pom.xml, Liquibase
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<groupId>company.school</groupId>
<artifactId>school-db</artifactId>
<version>${project.version}</version>
<systemPath>../school-db/target</systemPath>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>integration-test</phase>
<configuration>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>db.changelog-master.xml</changeLogFile>
<driver>org.h2.Driver</driver>
<url>jdbc:h2:~/tmpLB;AUTO_SERVER=TRUE</url>
<logging>info</logging>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
I have one changeset in the changelog inserting data in targeted tables.
Do I have the right users set up?
Is there a way to run Liquibase in the same process as Glassfish and use a mem: database instead?
Thx and regards,
Christian
Ok, so there was an "easy" solution to the problem.
There was no data in the database since that changeset in liquibase changelog couldn't complete. I had the insert statements in a separate sql file that I called using the <sqlFile> liquibase tag. But the insert was violating some foreign key constraints and didn't get executed.
So what put me off was the fact that Liquibase seems to hide any errors from included sql files. Will try try reproduce that and Jira it if I succeed.
/Christian