Web services 使用axis和maven访问web服务
我试图弄清楚如何使用Axis访问Java中的Web服务 据我所知,以下是我需要做的:Web services 使用axis和maven访问web服务,web-services,maven-2,axis,wsdl2java,webservice-client,Web Services,Maven 2,Axis,Wsdl2java,Webservice Client,我试图弄清楚如何使用Axis访问Java中的Web服务 据我所知,以下是我需要做的: 使用WSDL文件+Axis工具生成Java文件 编译并打包生成的Java文件,然后使用这些文件上的连接方法使用这些对象 在尝试这样做的过程中,我陷入了困境: 我从中随机选择了一个Web服务 我以以下方式使用axistools maven插件: <build> <plugins> <plugin> <groupId>o
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<configuration>
<urls>
<!--<url>http://soap.amazon.com/schemas2/AmazonWebServices.wsdl</url>-->
<!--<url>http://ws.xwebservices.com/XWebEmailValidation/V2/XWebEmailValidation.wsdl</url>-->
<url>http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx?WSDL</url>
</urls>
<!--<sourceDirectory>${project.build.sourceDirectory}/wsdl</sourceDirectory>-->
<packageSpace>com.company.wsdl</packageSpace>
<testCases>true</testCases>
<serverSide>true</serverSide>
<subPackageByFileName>true</subPackageByFileName>
<outputDirectory>${project.build.directory}/src/generated-sources</outputDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
org.codehaus.mojo
AxisToolsMaven插件
http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx?WSDL
com.company.wsdl
真的
真的
真的
${project.build.directory}/src/generated sources
生成源
wsdl2java
问题是:
我可以成功地运行mvn生成源代码,它确实生成Java文件。但我似乎无法编译这些Java文件。
当我运行mvn clean install时,它会给我一大堆编译错误。我遗漏了哪一步?根据您对我的一条评论的回答,我的建议是使用JAX-WS实现,比如Java 6中包含的JAX-WS实现,或者(两者都比过时的Axis好得多) 下面是一个基于JAX-WS RI及其应用程序的示例:
你得到了什么编译错误?一大堆“预期的”,“预期的”,“类型的非法开始”,“不是一个语句”我看了java类,它看起来很好:Axis是一个很强的要求吗?不。。。我正在学习如何做这是我的沙盒应用程序。想做任何最好的实践。似乎Axis是事实上的工具。我不介意用另一种方式。
<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.stackoverflow</groupId>
<artifactId>Q3479139</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Q3479139</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven 2</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven2-repository.dev.java.net</id>
<url>http://download.java.net/maven/2</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlUrls>
<wsdlUrl>http://ws.xwebservices.com/XWebEmailValidation/V2/XWebEmailValidation.wsdl</wsdlUrl>
</wsdlUrls>
<!-- The name of your generated source package -->
<packageName>com.example.myschema</packageName>
<!-- generate artifacts that run with JAX-WS 2.0 runtime -->
<target>2.0</target>
<!-- Specify where to place generated source files -->
<sourceDestDir>${project.build.directory}/generated-sources/wsimport</sourceDestDir>
</configuration>
</execution>
</executions>
<!-- if you want to use a specific version of JAX-WS, you can do so like this -->
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-tools</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.example.myschema;
import junit.framework.TestCase;
public class EmailValidationTest extends TestCase {
XWebEmailValidationInterface service = new EmailValidation().getEmailValidation();
ValidateEmailRequest request = new ValidateEmailRequest();
ValidateEmailResponse response = null;
public void testEmails() {
request.setEmail("foo@bar.com");
response = service.validateEmail(request);
assertEquals("EMAIL_SERVER_NOT_FOUND", response.getStatus());
request.setEmail("foo@gmail.com");
response = service.validateEmail(request);
assertEquals("NOT_VALID", response.getStatus());
}
}