1

In my resources folder src/main/resources, I have an xsd folder with subfolders named create and update.

So the folder structure looks like :

src/main/resources/xsd
src/main/resources/xsd/create/create.xsd
src/main/resources/xsd/update/update.xsd

What I am trying to figure out is how to generate the Java Objects in their own respective packages to organize the code using XJC and maven-jaxb2-plugin

I want to generate the CREATE Java objects in src/main/java/com/myapp/dto/create

And UPDATE Java objects in src/main/java/com/myapp/dto/update

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>
        <!-- user-added-plugin-->
        <plugin>
            <!-- https://mvnrepository.com/artifact/org.jvnet.jaxb2.maven2/maven-jaxb2-plugin -->
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.15.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- CREATE Schema-->
                <schemaDirectory>${project.basedir}/src/main/resources/xsd/create</schemaDirectory>
                <schemaIncludes>
                    <include>*.xsd</include>
                </schemaIncludes>
                <generatePackage>com.myapp.dto.create</generatePackage>
                <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
                
                <!-- UPDATE Schema -->
                <schemaDirectory>${project.basedir}/src/main/resources/xsd/update</schemaDirectory>
                <schemaIncludes>
                    <include>*.xsd</include>
                </schemaIncludes>
                <generatePackage>com.myapp.dto.update</generatePackage>
                <generateDirectory>${project.basedir}/src/main/java</generateDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

My current pom.xml <build> code only generates the UPDATE Java objects in com.myapp.dto.update but it never generates CREATE Java objects in com.myapp.dto.create. It does not even create the path: com.myapp.dto.create

I am not sure how to generate the CREATE on the desired path. Eventually I will need to generate Java objects for DELETE schema. That's why I'm hoping to generate the Java objects accordingly on their respective package/folders.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
heisenberg
  • 1,784
  • 4
  • 33
  • 62
  • First never generate code into `src/main/java` better leave the conventions and let the plugins generate the code into `target/generate_sources`(plus packages etc.)... ? – khmarbaise May 15 '22 at 19:44
  • 1
    Does this answer your question? [How can I tell jaxb / Maven to generate multiple schema packages?](https://stackoverflow.com/questions/2857081/how-can-i-tell-jaxb-maven-to-generate-multiple-schema-packages) – slindenau May 19 '22 at 11:17

1 Answers1

0

Have a look at PluginExecution here: https://maven.apache.org/xsd/maven-4.0.0.xsd

In your example, you've got a single execution with two bits of configuration.

Instead, try multiple executions, each with their own configuration.

        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                Create Config here.
                </configuration>
            </execution>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                Update Config here.
                </configuration>
            </execution>
        </executions>
user1717259
  • 2,717
  • 6
  • 30
  • 44