J. *_*bel 2 java soap wsdl web-services maven
我正在尝试使用插件jaxb2-maven-plugin从wsdl创建Java类。
我使用1.5版和以下代码(链接:从WSDL使用jaxb2-maven-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>
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
但是,当我更改为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]
Run Code Online (Sandbox Code Playgroud)
有人知道该新插件版本如何使用WSDL文件吗?
我已经找到了解决方案。
当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>
Run Code Online (Sandbox Code Playgroud)
不同之处不仅在于sintaxis。该版本不会在proyect(src / main / java)中创建类,而是在您编写的目录outputDirectory和的包中创建packageName。当您使用生成的类时,它就像是在同一个对象中一样是透明的。