How to ignore classes from imported schemas in the generated jar for a particular schema

Nikhil Ambekar

I have a xsd file a.xsd which imports another xsd b.xsd. I want to create a jar of all the classes from the a.xsd but ignore classes generated from b.xsd. My pom file is as follows.

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.personal.proj</groupId>
    <artifactId>schema-model</artifactId>
    <version>1.0.0</version>
    <name>SchemaModel</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.12.3</version>
                <executions>
                    <execution>
                        <id>id</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/xsd</schemaDirectory>
                            <schemaIncludes>
                                <include>a.xsd</include>
                            </schemaIncludes>
                            <schemaExcludes>
                                <exclude>b.xsd</exclude>
                            </schemaExcludes>
                            <forceRegenerate>true</forceRegenerate>
                            <removeOldOutput>true</removeOldOutput>
                            <bindingDirectory>src/main/xsd</bindingDirectory>
                            <bindingIncludes>
                                <include>schema.xjb</include>
                            </bindingIncludes>
                            <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

My schema.xjb file is

<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="a.xsd" node="/xs:schema">
    <jxb:schemaBindings>
        <jxb:package name="com.a.model" />
    </jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="b.xsd" node="/xs:schema">
    <jxb:schemaBindings>
        <jxb:package name="com.b.model" />
    </jxb:schemaBindings>
</jxb:bindings>

This link shows how this can be done, but i am unable to configure it.If i need to add episodes, i need to generate it(b.episode) in the same build and use it for generation of a.jar

lexicore

Use map="false" on b.xsd bindings:

<jxb:bindings schemaLocation="b.xsd" node="/xs:schema">
    <jxb:schemaBindings map="false">
        <jxb:package name="com.b.model" />
    </jxb:schemaBindings>
</jxb:bindings>

Still some of the classes may be generated (XJC has some problems with that). I often delete them in a post-processing step in the build.

I generally recommend using episodes for such things. Here's a test project for episodes.

Disclaimer: I'm the author of the .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make generated classes contain Javadoc from XML Schema documentation

How to ignore JAVA_TOOLS_OPTIONS for a particular jar?

How to design nested classes in a .NET Core API to get to a particular schema?

Generation of XSD restrictions in a schema generated from Java JAXB annotated classes

Gradle: How to exclude a particular package from a jar?

wsimport - Imported schema with no namespace ==> package with name 'generated'

How do you set generated classes from the same schema but in different generations to eachothers request/response objects without traversing them?

How to ignore nodes from imported graphs when validating RDF with SHACL?

How to create tables from imported foreign schema with plpgsql loop function

Maven - How to exclude dependencies from generated JAR

How to include runtime dependency in jar generated from gradle jar task

How to edit .java files imported in Eclipse from a .jar file

How do I exclude a package from an imported JAR for a project in Eclipse?

classes of jar file cannot be imported in netbeans

Does jar file not contain imported packages and classes?

How to make TypeScript happy with extending classes imported from 'node modules'?

How to access classes from a module imported template literals?

How to disable automatic linting of imported classes from modules?

How to use classes from .jar files?

How to load Classes at runtime from a folder or JAR?

How to delete particular common record from all tables in particular schema (T SQL)?

generate classes from schema

How to ignore generated files from Go test coverage

Parse Json into a schema-generated set of classes

How to get simple graphql mutation query from generated schema?

How to change the format of POJOs generated from JSON Schema?

How to ignore particular example in cucumber

SQL Server : How to copy a particular table from one schema to other schema on the same db,same server

How to use super() to inherit a particular class from multiple father classes?