Maven jaxb2:xjc failing to generate code
Asked Answered
S

11

22

I have added the following plugin into the Maven build in pom.xml

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration> 
                <extension>true</extension>                             
                <clearOutputDir>false</clearOutputDir>
                <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
                <schemaFiles>myapp.xsd</schemaFiles>                                                        
                <outputDirectory>${basedir}/src/main/java</outputDirectory>         
                <bindingDirectory>src/main/resources/xsd</bindingDirectory>     
                <bindingFiles>myapp-bindings.xjb</bindingFiles>
            </configuration>
        </execution>
    </executions>                       

</plugin>

Following is the build error.

[INFO] Ignored given or default xjbSources [C:\WorkSpace\MyApp\src\main\xjb], since it is not an existent file or directory.
[INFO] Ignored given or default sources [C:\WorkSpace\MyApp\src\main\xsd], since it is not an existent file or directory.
[WARNING] No XSD files found. Please check your plugin configuration.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.273s
[INFO] Finished at: Tue May 12 16:24:26 EDT 2015
[INFO] Final Memory: 9M/124M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "dev-artifactory" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.1:xjc (default) on project pml-jasypt-authentication-service: MojoExecutionException: NoSchemasException -> [Help 1]

I am confused, why is the plugin not referring to the paths and files specified in the configuration.

Synaeresis answered 12/5, 2015 at 20:28 Comment(0)
K
23

Version 2.1 has changed how sources are specified

http://mojo.codehaus.org/jaxb2-maven-plugin/xjc-mojo.html#sources

e.g

<configuration>
...
  <sources>
     <source>some/explicit/relative/file.xsd</source>
     <source>/another/absolute/path/to/a/specification.xsd</source>
     <source>a/directory/holding/xsds</source>
 </sources>
</configuration>

I'm having a whole world of other problems so sticking with 1.6 as jshark suggested is a good plan

Keefer answered 20/5, 2015 at 17:9 Comment(3)
Damn, it's likes changes everywhere. I'm migrating a system from JDK7 to JDK11, and it's a whole can of worms with getting XSD working right.Salpingotomy
how to have the generated classes inside a certain packageRobbie
For Java 11, better to stick with version1.5! See medium.com/@nihatonder87/…Hunks
G
19

version 2.1 has a bug.

You can use <version>2.2</version> with the new syntax:

<configuration>
...
  <sources>
     <source>some/explicit/relative/file.xsd</source>
     <source>/another/absolute/path/to/a/specification.xsd</source>
     <source>a/directory/holding/xsds</source>
 </sources>
</configuration>

You can use <version>1.6</version> with the old syntax:

<configuration>
    ...
    <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory>
    <schemaFiles>myapp.xsd</schemaFiles> 
</configuration>
Galven answered 19/10, 2015 at 17:38 Comment(0)
I
7

I had the same problem today, and resolved it by putting:

<version>1.6</version>

on the plugin definition (which is in general good practice to do)

Iinden answered 13/5, 2015 at 9:20 Comment(0)
R
3

I got it working by setting compiler version to JDK 1.8 and jaxb2-maven-plugin version 1.5 According to the documention it will work with minimum JDK 1.6 [ The link may drop dead if its changed in the site]. For example :

<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.mntq.jaxb.xsd.to.pojo</groupId>
  <artifactId>XsdToPojo</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <build>
        <finalName>PersistencePoJO</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
             <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 package of your generated sources -->
                <packageName>com.mntq.jaxb.pojo</packageName>
            </configuration>
        </plugin>
        </plugins>
    </build>
</project> 
Ragan answered 5/8, 2017 at 11:0 Comment(0)
H
1

We can also use as below:

           <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>
Haft answered 12/1, 2017 at 15:6 Comment(0)
B
1

For the recent ones, you might want to try this (which worked for me)

  <dependencies>
    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.2</version>
    </dependency>
    <dependency>
      <groupId>com.sun.activation</groupId>
      <artifactId>jakarta.activation</artifactId>
      <version>1.2.1</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <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>
          <packageName>......</packageName>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>2.3.2</version>
          </dependency>
          <dependency>
            <groupId>com.sun.activation</groupId>
            <artifactId>jakarta.activation</artifactId>
            <version>1.2.1</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

or (might be a potential solution)

<dependency>
   <groupId>jakarta.xml.bind</groupId>
   <artifactId>jakarta.xml.bind-api</artifactId>
   <version>${jakarta-xml-api.version}</version>
</dependency>

For reference refer this or this.

Beulahbeuthel answered 8/4, 2023 at 6:3 Comment(0)
S
0

I resolved it by checking "Force Update of Snapshot/Release" option in eclipse maven update.

It forces it to update all of the related dependencies.

Swordsman answered 8/4, 2018 at 14:52 Comment(0)
R
0

It will be works, if you just add xerces dependency to end of your jaxb plugin declaration. It's so simple: the plugin just need some class to execution. Give it him now :) I. Senatov.

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <id>xjc-dtd</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <arguments>-dtd</arguments>
                        <dtd>true</dtd>
                        <!-- The package of your generated sources -->
                        <packageName>mi.minet.lurc.dtd</packageName>
                        <schemaDirectory>src/main/resources/dtd</schemaDirectory>
                        <schemaFiles>lurc.dtd</schemaFiles>
                    </configuration>
                </execution>
                <execution>
                    <phase>generate-sources</phase>
                    <id>xjc-xsd</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <packageName>mi.minet.lurc.xsd.configuration</packageName>
                        <schemaDirectory>src/main/resources/xsd</schemaDirectory>
                        <schemaFiles>configuration.xsd</schemaFiles>
                        <clearOutputDir>false</clearOutputDir>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                    <version>2.11.0</version>
                </dependency>
            </dependencies>
        </plugin>
Rauwolfia answered 8/6, 2019 at 13:51 Comment(1)
No, not needed, because the jaxb2-maven-plugin does not rely on xerces to work. I just tried it, with and without your tip, it wasn't even loaded. I don't understand, why you drop your pom snippet here. Did you read the Exception from the OP? The problem here is, that no Schema was found, not a compile error, due to some missing library.Mazur
T
0

In my case, I had it work by downgrading my jdk compilateur version from jdk 10 to jdk 1.8

Toscanini answered 25/2, 2020 at 14:48 Comment(0)
S
0

In some cases you should use mvn clean before build for example

mvn clean compile
Stylopodium answered 18/7, 2020 at 13:13 Comment(0)
D
0

you can try different plugin like

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.org.threesixtyfive</groupId>
    <artifactId>jaxb-text</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JaxbTest</name>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.9.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/xsd</schemaDirectory>
                    <schemaIncludes>
                        <include>Patient.xsd</include>
                    </schemaIncludes>
                    <bindingDirectory>${project.basedir}/src/main/xsd</bindingDirectory>
                    <bindingIncludes>
                        <include>global.xjb</include>
                    </bindingIncludes>
                    <generateDirectory>${project.basedir}/src/generated</generateDirectory>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project> 
Dyan answered 1/7, 2023 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.