我正在尝试使用插件jaxb2-maven-plugin从wsdl创建Java类。
在1.5版本中,来自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>但是当使用插件版本2.3.1时,我得到了这个错误:
Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:2.3.1:xjc (xjc) on project demo: MojoExecutionException: NoSchemasException -> [Help 1]有人知道如何在这个新的插件版本中使用WSDL文件吗?
发布于 2017-07-07 03:24:36
我已经找到了解决方案。
当jaxb2-maven-plugin版本是>= 2.0时,您必须使用以下配置:
<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>不同之处不仅仅在于语法。该版本不会在项目中创建类(src/main/java),它会在您在outputDirectory中编写的目录和packageName包中创建。
当您使用生成的类时,它是透明的,就像它在同一个项目中一样。
发布于 2017-07-19 05:38:46
如果您想从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>https://stackoverflow.com/questions/44955247
复制相似问题