javamavenpluginspom.xmljaxb2-maven-plugin

How do I define schema directory in JAXB2 maven plugin version 2.4?


I am trying to define the directory for my schema in my pom.xml. I keep getting an error saying "Element schemaDirectory is not allowed here". I am guessing this element is not supported in this version. So how do define my schema directory in this version?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>${project.basedir}src/main/resources</schemaDirectory>
        <outputDirectory>${project.basedir}src/main/java</outputDirectory>
    </configuration>
</plugin>

Thanks in advance!


Solution

  • This is valid for older version eg. 1.5:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <schemaDirectory>${project.basedir}src/main/resources</schemaDirectory>
                        <outputDirectory>${project.basedir}src/main/java</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

    For version 2.4, according to documentation there is no longer schemaDirectory tag https://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.4/xjc-mojo.html

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.4</version>
        <executions>
            <execution>
                <id>xjc</id>
                <goals>
                    <goal>xjc</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <outputDirectory>${project.basedir}src/main/java</outputDirectory>
            <sources>
                <source>${project.basedir}src/main/resources</source>
            </sources>
        </configuration>
    </plugin>