I am trying using the pluggin jaxb2-maven-plugin
to create the Java class from the wsdl.
With the version 1.5 this code from Generate classes with jaxb2-maven-plugin from WSDL works:
<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>
<!-- Package to store the generated file -->
<packageName>com.example.demo.wsdl</packageName>
<!-- Treat the input as WSDL -->
<wsdl>true</wsdl>
<!-- Input is not XML schema -->
<xmlschema>false</xmlschema>
<!-- The WSDL file that you saved earlier -->
<schemaFiles>horarios.wsdl</schemaFiles>
<!-- The location of the WSDL file -->
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<!-- The output directory to store the generated Java files -->
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<!-- Don't clear output directory on each run -->
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
But when use plugin version 2.3.1, I get this error:
Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project demo: MojoExecutionException: NoSchemasException -> [Help 1]
Does someone know how use WSDL file with this new plugin version?
I have already found the solution.
When the jaxb2-maven-plugin version is >= 2.0 you have to use the follow configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.example.demo.wsdl</packageName>
<sourceType>wsdl</sourceType>
<sources>
<source>src/main/resources/horarios.wsdl</source>
</sources>
<outputDirectory>target/generated-sources/</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
The difference is not only the syntax. That version does not create the class within the project (src/main/java), it creates in the directory that you wrote in outputDirectory
and in the package of packageName
.
When you use the class generated it is transparent like if it would be in the same project.