maven配置:主要引用包及pluginsjava
<properties> <axis2.version>1.6.1</axis2.version> </properties> <dependencies> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-kernel</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-http</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-local</artifactId> <version>${axis2.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-wsdl2code-maven-plugin</artifactId> <version>1.6.1</version> <executions> <execution> <id>wsdl2code-client</id> <phase>generate-sources</phase> <goals> <goal>wsdl2code</goal> </goals> </execution> </executions> <configuration> <wsdlFile>src/main/resources/wsdl/IXman.wsdl</wsdlFile> <packageName>com.stub.generated</packageName> <generateServicesXml>false</generateServicesXml> <unpackClasses>true</unpackClasses> </configuration> </plugin> </plugins> </build>
經過wsdlFile屬性指定wsdl所在文件。apache
若是是有多個wsdl須要生成java代碼,則能夠用下面的配置:maven
<plugin> <groupId>org.apache.axis2</groupId> <artifactId>axis2-wsdl2code-maven-plugin</artifactId> <version>1.6.0</version> <executions> <execution> <id>ws1</id> <goals> <goal>wsdl2code</goal> </goals> <configuration> <unpackClasses>true</unpackClasses> <databindingName>adb</databindingName> <packageName>org.example.stackoverflow.axis2-maven</packageName> <wsdlFile>src/main/resources/service1.wsdl</wsdlFile> <outputDirectory>target/generated-sources</outputDirectory> <syncMode>sync</syncMode> </configuration> </execution> <execution> <id>ws2</id> <goals> <goal>wsdl2code</goal> </goals> <configuration> <unpackClasses>true</unpackClasses> <databindingName>adb</databindingName> <packageName>org.example.stackoverflow.axis2-maven</packageName> <wsdlFile>src/main/resources/service2.wsdl</wsdlFile> <outputDirectory>target/generated-sources</outputDirectory> <syncMode>sync</syncMode> </configuration> </execution> </executions> </plugin>
注意,這段xml配置,若是使用axis2-wsdl2code:wsdl2code命令去生成會報錯,但使用install者能夠生成成功。ui
以後經過中間代碼調用便可。spa
@Test public void testWs() throws Exception{ AIServiceStub aiServiceStub=new AIServiceStub(); AIRequest aiRequest=new AIRequest(); aiRequest.setMsgHeader("test"); aiRequest.setMsgBody("test"); AIResponse response= aiServiceStub.aIService_visit(aiRequest); System.out.println(response.getRes()); }