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

2

5

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!

Barbican answered 28/2, 2019 at 19:43 Comment(0)
H
9

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>
Heldentenor answered 28/2, 2019 at 20:16 Comment(2)
I am still getting the same error: "Element schemaDirectory is not allowed here".Barbican
For anyone needing to use the later version, the proper format is: <sources><source>...</source></sources> as defined in the documentation.Irving
D
5

For version 2.5.0

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

Then run mvn compile

Drusi answered 8/2, 2022 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.