I am using Jooq Trial for generating code from SQL Server database as a poc. I use the below congifuration. However, it is not generating the information schema during compilation.
<plugin>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>jooq-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>${skip.jooq.generation}</skip>
</configuration>
</execution>
</executions>
<configuration>
<jdbc>
<driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
<url>${database.url}</url>
<user></user>
<password></password>
</jdbc>
<generator>
<name>org.jooq.codegen.JavaGenerator</name>
<database>
<name>org.jooq.meta.sqlserver.SQLServerDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<!--<inputSchema></inputSchema> --> <!-- This will generate all schema of db, better to only generate the one
interested in -->
<inputCatalog>scm</inputCatalog>
<schemata>
<schema>
<inputSchema>dbo</inputSchema>
</schema>
<schema>
<inputSchema>INFORMATION_SCHEMA</inputSchema>
</schema>
</schemata>
</database>
<target>
<packageName>org.blackdread.sqltojava.jooq</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
<dependencies>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq-codegen</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq.trial</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>
</plugin>
Log:
[INFO] Generation finished: scm.dbo: Total: 1.493s, +0.333ms [INFO]
[INFO] Excluding empty schema : scm.INFORMATION_SCHEMA [INFO]
Removing excess files
But information_schema is available as views and it is returning me the necessary information too. I'm using windows authentication and not sa.
For historic reasons, jOOQ-meta's SQLServerDatabase only queries the sys.objects table, not the sys.all_objects table, to reverse engineer your database. This should be changed, of course. I have created a feature request for this:
https://github.com/jOOQ/jOOQ/issues/8827
It has been implemented for jOOQ 3.12
Workaround
In the meantime, you have these options:
Extend the SQLServerDatabase to adapt its queries to fetch rom all_objects, not from objects (this is a lot simpler with the professional edition than with the free trial, as you'll get the sources, and the right to patch the source code)
Use the JDBCDatabase, which queries JDBC's DatabaseMetaData, instead. This should return content from the sys and INFORMATION_SCHEMA schemas as well (but currently doesn't give access to e.g. stored procedures)
Use the generated INFORMATION_SCHEMA tables located in the jOOQ-meta module
Related
My goal is to export database schema from Jpaconfiguration entities loaded in the classpath when building the project (create-schema.sql).
I found that using Hibernate tools exporters is the convenient way to do it using the ant task and the JpaConfiguration to autoLoookup for the persistent elements from Classpath.
Here is the plugin implementation I have tried:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>process-classes</id>
<phase>process-classes</phase>
<configuration>
<target>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
<hibernatetool destdir="target">
<classpath refid="maven.compile.classpath"/>
<jpaconfiguration />
<!-- Write all CREATE statements to a file. -->
<hbm2ddl drop="false" create="true" export="false"
outputfilename="schema-create.sql"
delimiter=";" format="true"/>
</hibernatetool>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools</artifactId>
<version>3.2.0.beta9a</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.12.Final</version>
</dependency>
</dependencies>
</plugin>
The problem Is that I am getting ClassNotFoundException Ejb3Configuration
[ERROR] [hibernatetool] java.lang.ClassNotFoundException: org.hibernate.ejb.Ejb3Configuration
From documentation but it didn't work for me either way :
ejb3configuration was the name used in previous versions. It still works but will display a warning telling you to use jpaconfiguration instead.
Solution inspired by Hibernate Tools Reference documentation :
Hibernate JPA based configuration (jpaconfiguration)
Hibernate Database schema exporter (hbm2ddl)
Any proposition please!
We are using a setup with Spring Boot, Hibernate, Query DSL and Maven with Java 1.8
Recently, I've added Query DSL to the project with the configuration listed below. To make it work, I had to configure the Java Compiler in the eclipse project settings to allow Annotation Processing and also add the Query DSL .jar file to the eclipse Annotation Factory Path.
This setup worked as expected. It generated the custom Q classes and I could use them in my code. When now running the mvn clean install on the command line, every class in my code throws the error cannot find symbol, because the class is missing. Is there anything else I need to configure - similar to the .jar file in the eclipse settings - to make the build process work?
EDIT: This question is not a duplicate of this question because I did not ask why this error (cannot find a symbol) occurs but rather how to configure QueryDSL to also work on the command line.
EDIT2: I have now tried to integrate the build-helper-maven-plugin to use multiple source paths as an input. This did not help either. I also tried to generate the files into a src folder. It did not help either.
When I first compile the library in eclipse, the mvn compile goes through on the command line, but mvn clean compile still fails, because it just uses the compiled files of eclipse again. The apt-maven-plugin is executed, which can be seen just before the build process fails:
[INFO] --- apt-maven-plugin:1.1.3:process (default) # project1 ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
[INFO]
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: [...]
EDIT3: When I remove every import statement which is referring to the Q classes, the build process goes through (obviously). It is, however, remarkable, that the Q classes get compiled correctly in that case. They appear in the target folder as .class files as they should. Could it be, that the Q classes are compiled too late?
Here is an excerpt of the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
[...]
<prerequisites>
<maven>3.0.0</maven>
</prerequisites>
<dependencies>
[...]
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.3</version>
</dependency>
</dependencies>
<build>
<defaultGoal>spring-boot:run</defaultGoal>
<plugins>
[...]
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
[...]
</build>
</project>
This is the configuration of the eclipse project settings:
This is the error message which is displayed in the console:
[INFO] --- maven-processor-plugin:2.2.4:process (process) # project1 ---
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: cannot find symbol
import static com.project1.domain.QUser.user;
^
symbol: class QUser
location: package com.project1.domain
[ERROR] diagnostic: C:\Users\user1\git\project1\src\main\java\com\project1\repository\UserRepositoryImpl.java:3: error: static import only from classes and interfaces
import static com.project.domain.QUser.user;
^
This is old question but this is how i find my solution, added classifier for jpa dependency:
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
My complete pom:
<!-- BEGIN: BUILD -->
<build>
<!-- BEGIN: PLUGINS -->
<plugins>
<!-- BEGIN: apt-maven-plugin -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${apt.version}</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/apt</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<!-- END: apt-maven-plugin -->
</plugins>
<!-- END: PLUGINS -->
</build>
<!-- END: BUILD -->
<!-- BEGIN: DEPENDENCIES -->
<dependencies>
<!-- *********************************************** -->
<!-- BEGIN: 'QUERYDSL DEPENDENCIES' -->
<!-- BEGIN: 'querydsl-apt' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl-apt.version}</version>
</dependency>
<!-- END: 'querydsl-apt' -->
<!-- BEGIN: 'querydsl-jpa' -->
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl-jpa.version}</version>
<classifier>apt</classifier>
</dependency>
<!-- END: 'querydsl-jpa' -->
<!-- *********************************************** -->
<!-- END: 'QUERYDSL DEPENDENCIES' -->
</dependencies>
For me, it didn't work because it conflicted with maven-compiler-plugin with already set annotation processor. Just deleted the use of apt-maven-plugin and added its annotation processor in maven-compiler-plugin.
<build>
<plugins>
<!-- related to issues:-->
<!-- - https://github.com/querydsl/querydsl/issues/2654 -->
<!-- - https://github.com/querydsl/querydsl/issues/2242 -->
<!-- Using apt-maven-plugin conflicts with other annotation processors (like mapStruct) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>5.0.0</version>
<classifier>jpa</classifier>
</path>
<path>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</path>
<path>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- <groupId>com.mysema.maven</groupId>-->
<!-- <artifactId>apt-maven-plugin</artifactId>-->
<!-- <version>1.1.3</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>process</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <outputDirectory>target/generated-sources</outputDirectory>-->
<!-- <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
But there is an issue with using querydsl annotation processor in maven-compiler-plugin. You have to add jakarta.persistence-api and javax.annotation-api.
I would rather use profile to generate these Qclasses only when db change occurs.
cons:
-your diff in pull requests is clean when you don't change db schema because for each generation these files tend to generate differently for some reason (atleast in my case).
-you can manage witch of tables present in your db will have Qclasses (sometimes it is a pain when you forget to regenerate them after changing db schema)
-well not that it is lots of time . but builds are faster if You don't change schema and profile is turned off.
Try something like this and turn on profile when You want to generate changed schema Qclasses :
<properties>
<whitelisted.tables>
user_accunt,
other
</whitelisted.tables>
</properties>
<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>org.postgresql.Driver</jdbcDriver>
<jdbcUrl>jdbc:postgresql://localhost:port/dbname</jdbcUrl>
<packageName>your.package.name.for.q</packageName>
<jdbcUser>dbusername</jdbcUser>
<jdbcPassword>dbpassword</jdbcPassword>
<targetFolder>${project.basedir}/src/main/java/</targetFolder>
<spatial>true</spatial>
<tableNamePattern>${whitelisted.tables}</tableNamePattern>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The generated-source directory are not automatically included in the jar.
You need to use the Maven build helper plugin to fix this issue, for example:
https://github.com/alexec/javahelp-skeleton/blob/master/pom.xml
You can try out few things:
1.try to put <clearOutputDir>false</clearOutputDir> in your configuration tag
2. Sometimes classes might not be getting generated before the compile phase. So try to put phase in your plugin
<execution>
<phase>generate-sources</phase>
<goals>
<goal>...</goal>
</goals>
</execution>
By convention Maven assumes all source code is in 'src/main/java', compiles this and put all *.class file in target.
So if you have a class 'Alien.java' in <project-root>/alice/in/wonderland, your won't be able to access it (in src/main/java) because maven puts everything from src/main/java in classpath for your compiler and hence compiler is unaware of any source code (*.java) anywhere else.
In your case you are generating your source code in directory target/generated-sources/java, so you will have to tell maven about it. As mentioned in some other answers you may use build-helper-plugin for this, let maven know that your source resides on target/generated-sources/java by
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources/java</source>
<source>alice/in/wonderland</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Edit: You have mentioned wrong path in build-helper-plugin
I see although you are using build helper plugin but you are using wrong path
--- build-helper-maven-plugin:1.9.1:add-source (add-source) # project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
Instead of src\main\generated you should use <source>target/generated-sources/java</source>
I am using jooq codegen plugin in maven to generate code from xml schema file.
<configuration>
<generator>
<database>
<name>org.jooq.util.xml.XMLDatabase</name>
<properties>
<!-- Use any of the SQLDialect values here -->
<property>
<key>dialect</key>
<value>MYSQL</value>
</property>
<!-- Specify the location of your database file -->
<property>
<key>xml-file</key>
<value>${project.basedir}/src/main/resources/schema.xml</value>
</property>
</properties>
</database>
<generate>
<daos>true</daos>
<pojos>true</pojos>
<records>true</records>
<relations>true</relations>
<globalObjectReferences>false</globalObjectReferences>
</generate>
<target>
<!-- The destination package of your generated classes (within the
destination directory) -->
<packageName>com.generated.classes</packageName>
<!-- The destination directory of your generated classes. Using
Maven directory layout here -->
<directory>${project.basedir}/src/generated/classes</directory>
</target>
</generator>
</configuration>
Is there a solution to generate code from two different schema files. Example: schema-other.xml.
This is not yet supported by the XMLDatabase meta data source. The pending feature request is: https://github.com/jOOQ/jOOQ/issues/6260
There are workarounds, though:
Using separate configurations
If the two schemas / files are not linked, you can run two independent code generation runs. If you're using Maven, you could do it like this (see also this question):
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.9.4</version>
<executions>
<execution>
<id>first-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<generator>
<database>
<name>org.jooq.util.xml.XMLDatabase</name>
...
<properties>
<property>
<key>xml-file</key>
<value>file1.xml</value>
</property>
</properties>
</database>
...
<target>
<packageName>com.generated.classes.schema1</packageName>
<directory>${project.basedir}/src/generated/classes</directory>
</target>
</generator>
</configuration>
</execution>
<execution>
<id>second-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<!-- jOOQ configuration here -->
</configuration>
</execution>
</executions>
</plugin>
If you're using standalone code generation, just configure two separate runs.
Merging the XML files
You could of course merge the two XML files manually into a single one, e.g. by using XSLT for automatic merging, or manually.
I have a MySQL 5.7 instance that needs to have two DBs with identical schemas. I'm trying to use flyway with multiple schemas to accomplish this. I'm using the Maven plugin and v5.1.38 of the MySQL connector. Here is my POM config:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0</version>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306</url>
<user>root</user>
<password>mypassword</password>
<schemas>
<schema>stage</schema>
<schema>public</schema>
</schemas>
</configuration>
</plugin>
Running from an empty DB, this is the output:
[INFO] Database: jdbc:mysql://192.168.99.100:3306 (MySQL 5.7)
[INFO] Successfully validated 3 migrations (execution time 00:00.013s)
[INFO] Creating schema `stage` ...
[INFO] Creating schema `public` ...
[INFO] Creating Metadata table: `stage`.`schema_version`
[INFO] Current version of schema `stage`: 0
[INFO] Migrating schema `stage` to version 1 - initialize schema
[INFO] Migrating schema `stage` to version 2 - seed users
[INFO] Migrating schema `stage` to version 3 - create read items proc
[WARNING] DB: PROCEDURE stage.read_items does not exist (SQL State: 42000 - Error Code: 1305)
[INFO] Successfully applied 3 migrations to schema `stage` (execution time 00:01.824s).
It creates both schemas, but then only runs the migrations for the first one. Am I doing something wrong, or is this a bug in Flyway?
Update:
I've tried to create two executions for the Maven plugin using this config:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.1</version>
<executions>
<execution>
<id>migrate-stage</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306/stage</url>
<user>root</user>
<password>password</password>
<schemas>
<schema>stage</schema>
</schemas>
</configuration>
</execution>
<execution>
<id>migrate-pub</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:mysql://192.168.99.100:3306/public</url>
<user>root</user>
<password>password</password>
<schemas>
<schema>public</schema>
</schemas>
</configuration>
</execution>
</executions>
</plugin>
That gives me the following error:
Unable to connect to the database. Configure the url, user and password!
This seems to be similar to the following : Flyway database migration to multiple schemas
As Mr. Fontaine suggest you should split your schema's for this scenario.
I'm not certain about the correct usage of the schema-tag as I'm new to Flyway myself.
Hope this helps!
It's not the answer I was hoping for, but having tried everything else, I wound up just duplicating the SQL for the 2nd schema, adding a use public; or use stage; before the respective part.
The code I'm working on is using jaxb2-maven-plugin from org.codehaus.mojo to generate Java classes from XSD schema. I'm looking for a way to automatically implement equals() and hashCode() methods for those classes, but it seems there is not a way. I know that there are other JAXB2 Maven plugins that do that (http://confluence.highsource.org/display/J2B/Home for example), but I was wondering if anyone of you encountered this issue before and if there's a way for fixing it. I'm generating the classes using the xjc goal.
JAXB2 Basics you're mentioning is not a property of maven-jaxb2-plugin, it is a standalone set of JAXB 2.x plugins you can use with XJC - or jaxb2-maven-plugin or whatever.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<arguments>
<argument>-Xequals</argument>
<argument>-XhashCode</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.12.0</version>
</dependency>
</dependencies>
</plugin>
What I wanted to ask - why not just use maven-jaxb2-plugin? It has so much more functionality compared to the Codehaus plugin - including configuration support for JAXB2 plugins.
I would strongly disagree with using JAXB generated classes as business objects in your code. The classes that are generated by JAXB are beans that are just meant to essentially move element information from the xml file, to the bean's fields. I personally always have my SOAP service convert these generated bean classes to my actual business objects, as XML->Java and vice versa conversion is not black and white all the time. Note that this is my personal opinion, and would love for some others to weigh in on what they do in this situation.
To answer your question though, use a different plug in, or just your use your IDE to make some equals and hashCode methods.
Hope that helps.
EDIT:
I forgot to put my reasoning for this, apologies. Let us say in the next version of your project you want to add some more behavior to your JAXB generated classes, but also want to make some changes to your schema. Now you are regenerating the JAXB generated classes, putting the old behaviors back in, and making your application far more susceptible to bugs in my opinion. The JAXB generated classes are supposed to reflect your XML schema types (and thus your SOAP messages) not your business logic. Hope that makes sense.
This is the easiest way to do. Please update version as per your requirements.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-commons-lang</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>JAXB generate content classes</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/schema</schemaDirectory>
<outputDirectory>${project.build.directory}/generated-sources/jaxb</outputDirectory>
<schemaFiles>**/*.xsd</schemaFiles>
<packageName>com.lexus.web.content.model</packageName>
<arguments>-Xcommons-lang</arguments>
</configuration>
</execution>
</executions>
</plugin>
You might also want to consider using a fluent builder interface (facilitates the handling of the generated JAXB classes) and a reference to a catalog file in case you are referencing an xmldsig-core-schema (speeds up the generation process, as no remote Schemas from W3C are queried - their servers usually delay the response).
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>net.java.dev.jaxb2-commons</groupId>
<artifactId>jaxb-fluent-api</artifactId>
<version>2.0.1</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml</groupId>
<artifactId>jaxb-xjc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml</groupId>
<artifactId>jaxb-xjc</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
<packageName>[your package name goes here]</packageName>
<outputDirectory>${build.directory}/generated/src/main/java</outputDirectory>
<bindingDirectory>${basedir}/src/main/resources/xsd</bindingDirectory>
<extension>true</extension>
<catalog>${basedir}/src/main/resources/xsd-catalog/catalog.cat</catalog>
<extension>true</extension>
<arguments>-Xfluent-api -Xequals -XhashCode -XtoString</arguments>
</configuration>
</plugin>
Here is how the catalog file looks like:
--
sample catalog file.
double hyphens are used to begin and end a comment section.
--
SYSTEM "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" "xmldsig-core-schema.xsd"
And here is the link to the xmldisg-core-schema.xsd: http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd
Please note that the link is not broken - the W3C server is just delaying the response a few seconds. Can me very cumbersome if that happens during your automated build process, which includes JAXB generation.
My answer is for those who can't afford any third part dependency on their generated code.
The org.jvnet.jaxb2_commons:jaxb2-basics plugin adds a lots of org.jvnet includes in the generated code and your project will depend on org.jvnet.jaxb2_commons:jaxb2-basics-runtime.
The org.andromda.thirdparty.jaxb2_commons:commons-lang-plugin plugin generates code which depends on commons-lang:commons-lang. This dependency might be easier to bear depending on the situation.
I finally found this source code, it might be included in com.sun.xml.bind:jaxb-xjc at some point (version 2.2.4 ?), but until then I can't see any other solution than writing your own plugin.
PS: I can't access confluence.highsource.org, I get a 404. I guess it might have been helpful.
PPS: In my situation, the application I am building is targeted to an environment which has a very limited set of allowed Java libraries (incongruous security restrictions). I was a bit disappointed by the fact that jaxb2_commons includes a bunch of org.jvnet dependencies in the generated source, just for adding a boring equals method. I can understand the strategy of jvnet, their tools are very powerful, I may just be trying and using a sledgehammer to crack a nut. Still, I was sorry to note that it was so difficult to find a suitable tool for my situation.
There is also a fluent-builder plugin for JAXB that doesn't necessarily generate dependencies to third-party code. Plus, it is a true "Builder" design pattern, whereas the "fluent-api" plugin just adds builder-like methods to the generated classes.
It is: https://github.com/mklemm/jaxb2-rich-contract-plugin
It also has options to make the generated classes immutable and it can generate methods to copy the state of existing objects into a new builder instance, also supporting "partial" object copy.
For me the simplest way to do is using maven-jaxb2-plugin (as mentioned in the accepted answer):
Add in pom.xml <dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.12.0</version>
</dependency>
Add the plugin
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<generateDirectory>target/generated-sources</generateDirectory>
<generatePackage>my.package</generatePackage>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.12.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
See
JAXB2 Basics Plugins maven-jaxb2-plugin documentation/example
Add toString, hashCode, equals while generating JAXB classes in Java - Another similar stackoverflow thread