Java 从soapwsdl生成客户机jar
我正在尝试与一些soapweb服务交互,这些服务具有基本的身份验证,我有url、用户名和密码。现在我想在java代码中使用这个web服务,所以我需要为它创建一个jar文件 我已经看到了下面的URL,但不确定我是否正确地遵循了它。 我已从下载了axis 2-1.6.2 (仅二进制分布)Java 从soapwsdl生成客户机jar,java,web-services,apache,soap,ant,Java,Web Services,Apache,Soap,Ant,我正在尝试与一些soapweb服务交互,这些服务具有基本的身份验证,我有url、用户名和密码。现在我想在java代码中使用这个web服务,所以我需要为它创建一个jar文件 我已经看到了下面的URL,但不确定我是否正确地遵循了它。 我已从下载了axis 2-1.6.2 (仅二进制分布) 我有一个客户存根,它是。。。我看到有人说要将它与build.xml一起使用,但我在任何地方都找不到build.xml。。。。请告诉我设置ApacheAxis和ant需要安装什么?蚂蚁在这里干什么 Axis2支持多
我有一个客户存根,它是。。。我看到有人说要将它与build.xml一起使用,但我在任何地方都找不到build.xml。。。。请告诉我设置ApacheAxis和ant需要安装什么?蚂蚁在这里干什么 Axis2支持多种方式来支持Web服务客户端。最常见的方法是编写文档并生成解析WSDL文件描述的SOAP消息的Java代码 下面的回答描述了调用web服务的多种方法。最后一部分描述了一个groovy脚本,该脚本使用Axis2生成并使用ANT编译的类:
$AXIS2_HOME/bin/wsdl2java.sh -d adb -s -o mydir -uri http://www.xmlme.com/WSShakespeare.asmx?WSDL
这将生成以下文件:
└── mydir
├── build.xml
└── src
└── com
└── xmlme
└── webservices
└── ShakespeareStub.java
如果检查生成的java代码,您将发现与WSDL文件中定义的XML模式类型相匹配的java类,从而简化了SOAP消息的序列化和反序列化
“build.xml”文件包含编译生成的java代码的逻辑
cd mydir
ant
构建运行时,默认情况下将创建jar文件,如下所示:
└── mydir
├── build
│ ├── classes
│ │ └── ..
│ │ ..
│ └── lib
│ └── Shakespeare-test-client.jar
├── build.xml
└── src
└── com
└── xmlme
└── webservices
└── ShakespeareStub.java
这个jar文件现在可以由希望访问Web服务的java(或中的示例groovy脚本)包含。Mark的答案是可行的,但我更像是一个专业人士,希望最终将输出jar专业化。 以下是如何使用Maven
mydir/MyWsdl.WSDL
)pom.xml
文件(如下所示)mvn包
└── mydir
├── MyWsdl.wsdl
├── pom.xml
└── target (add this dir to .gitignore)
├── generated-sources
├── mywsdl-0.1.0-SNAPSHOT.jar
├── mywsdl-0.1.0-SNAPSHOT-sources.jar
└── mywsdl-0.1.0-SNAPSHOT-javadoc.jar
以及pom.xml
文件的源代码
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mywsdl</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>My WSDL client</name>
<build>
<plugins>
<!-- Generates JAVA source files from the WSDL -->
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.6.2</version>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
<configuration>
<packageName>com.example</packageName>
<wsdlFile>MyWsdl.wsdl</wsdlFile>
<!-- TODO: Update this file with new WSDL versions -->
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
4.0.0
com.example
mywsdl
0.1.0-SNAPSHOT
我的WSDL客户端
org.apache.axis2
axis2-wsdl2code-maven-plugin
1.6.2
wsdl2code
com.example
MyWsdl.wsdl
org.apache.maven.plugins
maven源插件
附加来源
罐子
org.apache.maven.plugins
maven javadoc插件
附加javadocs
罐子
org.apache.axis2
axis2
1.6.2
org.apache.axis2
axis2亚洲开发银行
1.6.2
org.apache.ws.commons.axiom
axiom api
1.2.14
org.apache.ws.commons.axiom
简化公理
1.2.14
UTF-8
我无法编辑,因为它将少于6个字符,但pom.xml的第一行缺少一个x:“x”mlns:xsi=“。。。。。