2017-07-06 3 views
0

J'essaie d'utiliser le plugin jaxb2-maven-plugin pour créer la classe Java à partir du wsdl.Comment créer la classe java à partir de WSDL dans jaxb2-maven-plugin version 2?

J'ai l'obtenir avec la version 1.5 et suit le code (lien: Generate classes with jaxb2-maven-plugin from WSDL):

 <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> 

Mais quand je change 2.3.1 Je reçois l'erreur suivante:

Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project demo: MojoExecutionException: NoSchemasException -> [Help 1] 

Est-ce que quelqu'un sait comment utiliser le fichier WSDL avec cette nouvelle version du plugin?

Répondre

0

J'ai déjà trouvé la solution.

Lorsque la version jaxb2-maven-plugin est> = 2.0, vous devez utiliser la configuration suivante:

   <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> 

La différence est non seulement la sintaxis. Cette version ne crée pas la classe dans le projet (src/main/java), elle crée dans le répertoire que vous avez écrit dans outputDirectory et dans le paquet de packageName. Lorsque vous utilisez la classe générée, elle est transparente comme si elle était dans le même projet.

+0

Plus d'informations concernant: https://stackoverflow.com/questions/35242941/jaxb-maven-plugin-not-generating-classes –

0

Si vous voulez commencer par un XSD:

   <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> 
        <xjbSources> 
         <xjbSource>src/main/resources/global.xjb</xjbSource> 
        </xjbSources> 
        <sources> 
         <source>src/main/resources/Ventas.xsd</source> 
        </sources> 
        <outputDirectory>${basedir}/src/main/java</outputDirectory> 
        <clearOutputDir>false</clearOutputDir> 
       </configuration> 
      </plugin>