使用 axis2 和 Maven 的 Web 服务

Web Service with axis2 and Maven

我必须使用 axis2 和 Maven 在 Eclipse 中创建 Web 服务,但我遇到了很多问题。这是 pom.xml:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.ratra.ws</groupId>
  <artifactId>MavenAxis2WS</artifactId>
  <packaging>war</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>MavenAxis2WS</name>
  <url>http://maven.apache.org</url>
   <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-java2wsdl-maven-plugin</artifactId>
        <version>1.5.4</version>
         <executions>
          <execution>
            <phase>process-classes</phase>
            <goals>
              <goal>java2wsdl</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <className>com.ratra.ws.MavenAxis2WS.MavenAxis2WebService</className>
          <outputFileName>${project.build.directory}/MavenAxis2WebService.wsdl</outputFileName>
        </configuration>
      </plugin>
    </plugins>
  </build> 
 <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
  <groupId>org.apache.axis2</groupId>
  <artifactId>axis2</artifactId>
  <version>1.5.4</version>
</dependency>
 <dependency>
  <groupId>org.apache.axis2</groupId>
  <artifactId>axis2-transport-http</artifactId>
  <version>1.5.4</version>
  <exclusions>
            <exclusion>
                <groupId>commons-httpclient</groupId>
                <artifactId>commons-httpclient</artifactId>
            </exclusion>
        </exclusions>
</dependency>
 <dependency>
  <groupId>org.apache.axis2</groupId>
  <artifactId>axis2-transport-local</artifactId>
  <version>1.5.4</version>
</dependency>
<dependency>
  <groupId>org.apache.xmlbeans</groupId>
  <artifactId>xmlbeans</artifactId>
  <version>2.4.0</version>
  <exclusions>
            <exclusion>
                <groupId>stax</groupId>
                <artifactId>stax-api</artifactId>
            </exclusion>
        </exclusions>
</dependency>
  </dependencies>
</project>

Eclipse 给我这个错误:描述资源路径位置类型 生命周期配置未涵盖的插件执行:org.apache.axis2:axis2-java2wsdl-maven-plugin:1.5.4:java2wsdl(执行:默认,阶段:process-classes)pom.xml /MavenAxis2WS 第 20 行 Maven 项目构建生命周期映射问题

如果我在命令行 mvn package 和 mvn process-classes 上写,eclipse 会生成 wsdl 文件,但它是空的。 我无法创建 Web 服务。请帮我。 我需要一个完整的例子,其中每个步骤都有完整的描述。 我需要用这个文件夹创建一个项目:src/main/java。 我希望有人能帮助我!!

谢谢!!!!

编辑:

如果我删除进程-classes 会出现此错误:描述资源路径位置类型 生命周期配置未涵盖的插件执行:org.apache.axis2:axis2-java2wsdl-maven-plugin:1.5.4:java2wsdl(执行:默认,阶段:process-classes)pom.xml /MavenAxis2WS 第 20 行 Maven 项目构建生命周期映射问题。如果我删除

<execution>
        <goals>
          <goal>java2wsdl</goal>
        </goals>
      </execution>
    </executions> 

我没有任何错误,但是当我 运行 mvn package 或 mvn process-classes.

时,eclipse 不会创建 wsdl

MavenAxis2WebService class 是:

package com.ratra.ws.MavenAxis2WS;
public class MavenAxis2WebService {
  public String ping(String text) {
    if (text == null) {
      return "Service is up and available";
    }
    return "Service is up and available, message: " + text;
  }
}

当我尝试 运行 http://localhost:8080/MavenAxis2WS/services/MavenAxis2WebService?wsdl 获得 HTTP 状态 500 - javax.servlet.ServletException:org.apache。axis2.deployment.DeploymentException:org/apache/commons/httpclient/HttpException。 我postweb.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0">
  <display-name>MavenAxis2WS</display-name>
  <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

在此博客上,您可以了解如何制作客户端部分,从而拥有 wsdl 并尝试与现有服务器通信 http://briansjavablog.blogspot.fr/2013/01/axis2-web-service-client-tutorial.html.

在这一点上,你什么都没有,你就是服务器http://sunnyratra.me/tag/apache-axis2-maven-example/

有简单但完整的示例,希望对您有所帮助