- 
                Notifications
    You must be signed in to change notification settings 
- Fork 103
JAXB2 Namespace Prefix Plugin
        Laurent Schoelens edited this page Jan 15, 2024 
        ·
        5 revisions
      
    This plugin adds :
- 
javax.xml.bind.annotation.XmlNsannotations topackage-info.javafiles for JAXB2.
- 
jakarta.xml.bind.annotation.XmlNsannotations topackage-info.javafiles for JAXB 3+.
Those annotations tells Jaxb to generate XML schema's instances with specific namespaces prefixes, instead of the auto-generated (ns1, ns2, ...) prefixes. Definition of thoses prefixes is done in the bindings.xml file.
The plugin is activated by the -Xnamespace-prefix
<?xml version="1.0"?>
<jxb:bindings version="3.0"
  xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:namespace="http://jaxb2-commons.dev.java.net/basic/namespace-prefix">
  <jxb:bindings schemaLocation="unireg-common-1.xsd">
    <jxb:schemaBindings>
      <jxb:package name="ch.vd.unireg.xml.common.v1" />
    </jxb:schemaBindings>
    <jxb:bindings>
      <namespace:prefix name="common-1" />
    </jxb:bindings>
  </jxb:bindings>
</jxb:bindings>Starting from 4.0.1 version of the plugin (see #457), you can also define extra binding prefix by providing the namespaceURI argument as parameter.
Defining namespaceURI as the targetNamespace will make the plugin run as attribute was undefined.
<?xml version="1.0"?>
<jxb:bindings version="3.0"
  xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:namespace="urn:jaxb.jvnet.org:plugin:namespace-prefix">
  <jxb:bindings schemaLocation="unireg-common-1.xsd">
    <jxb:schemaBindings>
      <jxb:package name="ch.vd.unireg.xml.common.v1" />
    </jxb:schemaBindings>
    <jxb:bindings>
      <namespace:prefix name="common-1" />
      <namespace:prefix name="other" namespaceURI="anotherNamespaceURI" />
    </jxb:bindings>
  </jxb:bindings>
</jxb:bindings>This will generate the following annotations on the package-info.java file, if targetNamespaceOfCommon1 is the targetNamespace of the unireg-common-1.xsd XSD
    @XmlNs(namespaceURI = "targetNamespaceOfCommon1", prefix = "common-1"),
    @XmlNs(namespaceURI = "anotherNamespaceURI", prefix = "other")- Home
- Migration guide
- 
JAXB Maven Plugin
- Quick Start
- 
User Guide
- Basic Usage
- Specifying What To Compile
- Referencing Resources in Maven Artifacts
- Using Catalogs
- Using Episodes
- Modular Schema Compilation
- Controlling the Output
- Using JAXB Plugins
- Using a Specific JAXB Version
- Configuring Extension, Validation and XML Security
- IDE Integration
- Miscellaneous
- Configuring Proxies
 
- Maven Documentation
- Configuration Cheat Sheet
- Common Pitfalls and Problems
 
- 
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
- 
JAXB2 Basics Plugins List
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Commons Lang Plugin
- Default Value Plugin
- Fluent API Plugin
- Namespace Prefix Plugin
- Value Constructor Plugin
- Boolean Getter Plugin
- CamelCase Plugin
- XML ElementWrapper Plugin
- Parent Pointer Plugin
- Property Listener Injector Plugin
 
 
- Annox
- JAXB Annotate Plugin
- 
HyperJAXB3
- Build System Support
- Customization Guide
- Databases
- Development guide
- Extension guide
- FAQ
- IDE Support
- Java Persistence
- JAXB
- JDK Support
- Project Templates
- 
Reference
- Adding vendor-specific annotations
- Features
- Integrating Hyperjaxb3 in builds
- Introduction
- Making schema-derived classes ready for JPA
- Adding required properties
- Applying workarounds for JAXB vs. JPA conflicts
- Enforcing top-level classes
- Generating equals and hashCode methods
- Generating ORM metadata
- Generating persistence unit descriptor
- JPA 2 Support
- Making classes serializable
- Testing generated mappings
 
- Reference - single page
- Related Projects
- Sample projects
- Solutions
- Target Scenarios
- Test Projects
- Tutorials
 
- Best Practices
- FAQ
- Sample Projects
- Support
- License
- Distribution