Maven Jaxb2 xjc plugin error No schemas have been found

47,127

Solution 1

As you did not provide any schemaDirectory, the plugin is trying to generate Java sources from all XML schema files in the default schema directory. You should configure the plugin according to the documentation :

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>1.5</version>
  <executions>
    <execution>
      <id>id1</id>
      <goals>
    <goal>xjc</goal>
      </goals>
      <configuration>
       <outputDirectory>target/generated-sources/jaxb</outputDirectory>
       <packageName>com.your.package.jaxb</packageName>
       <schemaDirectory>src/main/xsd</schemaDirectory>
       <schemaFiles>jaxb.xsd</schemaFiles>
      </configuration>
    </execution>
  </executions>
</plugin>

Solution 2

Try to make sure that jaxb.xsd is present under src/main/resources, the plugin is waring since it coudn't find the scheme in the specified location.

Solution 3

We can use as below in pom.xml file

   <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
            <execution>
                <id>id1</id>
                <goals>
                    <goal>xjc</goal>
                </goals>
                <configuration>
                    <outputDirectory>src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>
                    <packageName>com.subu.xsd.model</packageName>
                    <schemaDirectory>src/main/java/schemadir</schemaDirectory>
                    <schemaFiles>XYZ.xsd</schemaFiles>
                </configuration>
            </execution>
        </executions>
    </plugin>
Share:
47,127
mCY
Author by

mCY

Updated on August 25, 2020

Comments

  • mCY
    mCY over 3 years

    These days I've spent some time on JAXB for converting XSD to Java Class and vice versa. Here's a very good tutorial for beginners, http://www.journaldev.com/1312/how-to-generate-java-classes-from-xsd-using-xjc-maven-plugin. I follow the steps strictly, but always get error when mvn clean install

    Here's my pom.xml file.

    <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>jd</groupId>
        <artifactId>jd</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        <build>
            <plugins>
                <!-- Plugin required to build java classes from XSD using XJC -->
                <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>
                        </execution>
                    </executions>
                    <configuration>
                       <!-- The name of your generated source package -->
                        <arguments>-extension -npa -b ${project.basedir}/src/main/java/com/moodys/jaxb/global.xjb</arguments>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    But when I type mvn clean install, it always give me error as following:

    C:\Users\congy\Desktop\Work\workspace\JaxbFromClass>mvn clean jaxb2:xjc
    [INFO] Scanning for projects...
    [INFO]
    [INFO] ------------------------------------------------------------------------
    [INFO] Building jd 0.0.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ jd ---
    [INFO] Deleting C:\Users\congy\Desktop\Work\workspace\JaxbFromClass\target
    [INFO]
    [INFO] --- jaxb2-maven-plugin:1.5:xjc (default-cli) @ jd ---
    [INFO] Generating source...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.487s
    [INFO] Finished at: Thu Jul 04 19:09:37 CST 2013
    [INFO] Final Memory: 4M/122M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc (default-cli) on project jd: No schemas have been found -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    

    Can anyone show me the cause or simply tell me what should I refer to for further information?

    Another question is : according to this question Difference of Maven JAXB plugins, there's at least three jaxb plugins. So all of these plugins are all generated for the same purposes? If so ,why?

    Thanks in advance!

  • BlueLettuce16
    BlueLettuce16 over 10 years
    Try to remove following line: <outputDirectory>target/generated-sources/jaxb</outputDirect‌​ory>
  • zygimantus
    zygimantus about 6 years
    What is actually jaxb.xsd? Is it a file name?
  • LAMRIN TAWSRAS
    LAMRIN TAWSRAS almost 6 years
    @zygimantus yes, it's the schema of which you want to generate Java object classes