Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.highsource:maven-jaxb2-plugin:4.0.8'
}
dependencies {
implementation("com.github.highsource:maven-jaxb2-plugin:4.0.8")
}
<dependency>
<groupId>com.github.highsource</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>4.0.8</version>
</dependency>
libraryDependencies += "com.github.highsource" % "maven-jaxb2-plugin" % "4.0.8"
:dependencies [[com.github.highsource/maven-jaxb2-plugin "4.0.8"]]
Welcome to the most advanced and feature-full sets of JAXB-related tools.
The project is currently containing the following tools :
Please check our Migration Guide for any questions about migrating from previous releases to newers one.
| Version | Maven | JDK | JAXB | JPA (HyperJaxb3) | |-------------------------|:------------|:----:|:----:|:-----------------:| | From 4.0.2 | 3.1.0 | 11 | 4.0 | 3.1 | | 4.0.0 | 2.x and 3.x | 11 | 4.0 | 3.1 | | From 3.0.2 until 4.0.0 | 3.1.0 | 8 | 3.0 | 3.0 | | 3.0.0 and 3.0.1 | 2.x and 3.x | 8 | 3.0 | 3.0 | | From 2.0.10 until 3.0.0 | 3.1.0 | 8 | 2.3 | 2.2 | | From 2.0.0 until 2.0.10 | 2.x and 3.x | 8 | 2.3 | 2.2 |
The build is tested against JDK11, JDK17 and JDK21 (also JDK8 for versions before v4).
Please refer to the wiki for the full documentation.
This project is not developed, supported or in any other way affiliated with Apache, Eclipse or Oracle.
It was a completely independent development by its creator, Alexey Valikov.
It is now maintained by a group of people who are interested in keeping jaxb-tools working with future versions of Java and Jakarta.
This Maven plugin generates Java classes during Maven builds from XML Schemas (as well as WSDL, DTDs, RELAX NG formats).
It wraps and enhances the JAXB Schema Compiler (XJC) with its own set of plugins and customization points.
*.xsd
) and bindings (*.xjb
) into the src/main/resources
folder.pom.xml
:<project ...>
...
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<version>4.0.8</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
The current version 4.X of this plugin supports only JAXB 4.X (Jakarta based).
Versions 2.X and 3.X supports JAXB 2.3 and JAXB 3.0 with JDK8 support and baseline :
org.jvnet.jaxb:jaxb-maven-plugin:3.0.1
- JAXB 3.0org.jvnet.jaxb:jaxb-maven-plugin:2.0.9
- JAXB 2.3If you need an older JAXB version, you can use one of the following variants, which are no longer supported :
org.jvnet.jaxb2.maven2:maven-jaxb22-plugin:0.15.1
- JAXB 2.2.org.jvnet.jaxb2.maven2:maven-jaxb21-plugin:0.15.2
- JAXB 2.1.org.jvnet.jaxb2.maven2:maven-jaxb20-plugin:0.15.2
- JAXB 2.0.If you experience issues with the Mojohaus JAXB2 Maven Plugin (org.codehaus.mojo:jaxb2-maven-plugin
),
please file it on their project page.
JAXB Plugins (former JAXB Basics) is an open source project which provides useful plugins and tools for JAXB 4.x reference implementation.
For the current version 4.X and the previous version 3.X, its artifacts are named org.jvnet.jaxb:jaxb-plugins
, while the previous verions 2.X were named org.jvnet.jaxb:jaxb2-basics
. So, please replace all "jaxb2-basics" with "jaxb-plugins" in the following documentations (also in wiki) if you use versions 3.X and 4.X.
Please refer to the wiki for documentation.
JAXB Basics can only be used with JAXB/XJC 4.x.
equals(...)
methods.hashCode()
methods.equals(...)
method.hashCode()
method.toString()
methods.copy(...)
deep copying.merge(...)
methods to merge data from two source objects into the given object.aOrBOrC
.EnumValue<T>
interface.jaxb.index
files listing schema-derived classes.toString()
, hashCode()
and equals()
methods using Apache commons-lang3.default
attribute.jakarta.xml.bind.annotation.XmlNs
annotations to package-info.java
filesgetXXX
instead of isXXX
.jakarta.xml.bind.annotation.XmlElementWrapper
annotation to simplify generated structure.jaxb-plugins-runtime
)setXXX
methodParse Java annotations from text or XML resources.
Please refer to the wiki for documentation.
// Parse annotation from the string
XAnnotation<XmlRootElement> xannotation =
(XAnnotation<XmlRootElement>) XAnnotationParser.INSTANCE.parse
("@jakarta.xml.bind.annotation.XmlRootElement(name=\"foo\")");
// Create an instance of the annotation
XmlRootElement xmlRootElement = xannotation.getResult();
assertEquals("foo", xmlRootElement.name());
assertEquals("##default", xmlRootElement.namespace());
// Analyze the structure of the annotation
assertEquals(String.class, xannotation.getFieldsMap().get("name").getType());
assertEquals("##default", xannotation.getFieldsMap().get("namespace").getResult());
JAXB Annotate Plugin is capable of adding or removing arbitrary annotations to/from the generated sources.
It is also capable of removing all XML related annotations from the generated sources and also the ObjectFactory
. This new capability can be used in order to generate plain Java POJO from XSD without depending on JAXB artifacts.
Please refer to the wiki for documentation.
-Xannotate
-switch.You can annotate your schema-derived elements using normal Java annotation syntax. (Old XML syntax is still supported but no longer recommended.)
Current limitations:
.
) as delimiter (not $
).You can put your annotations directly in schema:
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
jaxb:version="3.0"
xmlns:annox="urn:jaxb.jvnet.org:annox"
jaxb:extensionBindingPrefixes="annox">
<xsd:complexType name="FooType">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
<annox:annotate target="package">@jakarta.annotation.Generated({"XJC","JAXB Annotate Plugin"})</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="bar" type="xsd:string"/>
<xsd:element name="foobar" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>@java.lang.SuppressWarnings({"unchecked","rawtypes"})</annox:annotate>
<annox:annotate target="setter">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="setter-parameter">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="getter">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="field">@java.lang.Deprecated</annox:annotate>
<annox:annotate target="class">@java.lang.Deprecated</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xs:simpleType name="FooEnum">
<xs:annotation>
<xs:appinfo>
<annox:annotateEnumValueMethod>@java.lang.Deprecated</annox:annotateEnumValueMethod>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="BAR"/>
<xs:enumeration value="BAZ"/>
</xs:restriction>
</xs:simpleType>
</xsd:schema>
Or in binding files:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="urn:jaxb.jvnet.org:annox"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jaxb https://jakarta.ee/xml/ns/jaxb/bindingschema_3_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox"
version="3.0">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='issueJIIB39CType']">
<annox:annotateClass>@jakarta.xml.bind.annotation.XmlRootElement(name="IssueJIIB39CType")</annox:annotateClass>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='issueJIIB39CType']/xs:attribute[@name='test']">
<annox:annotate target="field">@javax.xml.bind.annotation.XmlAttribute(required=false, name="test")</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
You can use the following customization elements in the urn:jaxb.jvnet.org:annox
namespace:
annotate
with the optional target
attribute
package
class
getter
setter
setter-parameter
field
enum-value-method
enum-fromValue-method
annotateProperty
annotatePackage
annotateClass
annotateElement
annotateEnum
annotateEnumConstant
annotateEnumValueMethod
- annotate the value()
method of the enumannotateEnumFromValueMethod
- annotate the fromValue(String)
method of the enumThe urn:jaxb.jvnet.org:annox
namespace must be declared in the jaxb:extensionBindingPrefixes
attribute via prefix, ex.:
xmlns:annox="urn:jaxb.jvnet.org:annox"
jaxb:extensionBindingPrefixes="xjc annox"
Note: the previous http://annox.dev.java.net
namespace is still supported but no longer exists. We decided to change this namespace
but keep older one too to avoid breaking older builds. Please migrate to new namespace of the plugin urn:jaxb.jvnet.org:annox
.
-XremoveAnnotation
-switch.You can remove annotations using customizations directly in schema:
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
jaxb:version="3.0"
xmlns:annox="urn:jaxb.jvnet.org:annox"
jaxb:extensionBindingPrefixes="annox">
<xsd:complexType name="FooType">
<xsd:annotation>
<xsd:appinfo>
<annox:removeAnnotation class="jakarta.xml.bind.annotation.XmlType" />
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="bar" type="xsd:string"/>
<xsd:element name="foobar" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:removeAnnotation class="jakarta.xml.bind.annotation.XmlElement" target="field" />
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Or in binding files:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:annox="urn:jaxb.jvnet.org:annox"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jaxb https://jakarta.ee/xml/ns/jaxb/bindingschema_3_0.xsd"
jaxb:extensionBindingPrefixes="xjc annox"
version="3.0">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='FooType']">
<annox:removeAnnotation class="jakarta.xml.bind.annotation.XmlType" />
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='FooType']//xs:element[@name='foobar']">
<annox:removeAnnotation class="jakarta.xml.bind.annotation.XmlElement" target="field" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
You can use the following customization elements in the urn:jaxb.jvnet.org:annox
namespace:
removeAnnotation
with the optional target
attribute:
package
class
getter
setter
setter-parameter
field
enum-value-method
enum-fromValue-method
removeAnnotationFromProperty
removeAnnotationFromPackage
removeAnnotationFromClass
removeAnnotationFromElement
removeAnnotationFromeEnum
removeAnnotationFromEnumConstant
removeAnnotationFromEnumValueMethod
- removes annotation from the value()
method of the enumremoveAnnotationFromEnumFromValueMethod
- removes annotation from the fromValue(String)
method of the enumThe urn:jaxb.jvnet.org:annox
namespace must be declared in the jaxb:extensionBindingPrefixes
attribute via prefix, ex.:
xmlns:annox="urn:jaxb.jvnet.org:annox"
jaxb:extensionBindingPrefixes="xjc annox"
Note: the previous http://annox.dev.java.net
namespace is still supported but no longer exists. We decided to change this namespace
but keep older one too to avoid breaking older builds. Please migrate to new namespace of the plugin urn:jaxb.jvnet.org:annox
.
org.jvnet.jaxb:jaxb-plugin-annotate
as XJC plugin-Xannotate
or -XremoveAnnotation
switchExample:
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-Xannotate</arg>
<arg>-XremoveAnnotation</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugin-annotate</artifactId>
</plugin>
<!-- Artifact with custom annotations -->
<plugin>
<groupId>com.acme.foo</groupId>
<artifactId>my-custom-annotations</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
See this example.
Note that annotations are first compiled in the annotations
module and the added to the classpath of the jaxb-maven-plugin
in the schema
module:
See this example.
Hyperjaxb3 provides relational persistence for JAXB objects. This is preview feature (please give feedback if any problems).