5

我是 Maven 和 Axis2 的新手。我的项目由三个模块组成:客户端、接口和服务器。服务是基于 POJO 的。WSDL 正在服务器模块中构建。接口模块包含常见的东西,如服务接口和 bean。

我应该将 WSDL 生成(或手动复制)到接口模块中吗?我应该在客户端模块生成客户端代码吗?模块结构好吗?我想做的就是使构建过程自动化但结构严格。

4

1 回答 1

8

结果不会清除您称为“接口”的组件。对于 Web 服务构建,主要有两种方法:

  • 从 wsdl 开始(即契约/或服务接口描述符)
  • 从代码开始(可能是java接口)

我建议第一种方法,因为并非总是可以控制开发的双方。您可以使用第二种方法从 wsdl 定义 (java2wsdl) 开始,或者使用 altova xmlspy 等工具构建 wsdl。

有了 wsdl,您可以使用 axis2-maven wsdl2code 插件来开发 WSS(Web 服务服务器端)。2.6.0 版中的这个插件只生成服务器的源代码,但您需要将此代码托管在axis2-war 发行版中或作为aar 组件。

有了 wsdl,您可以再次使用 axis2-maven wsdl2code 插件来生成 WSC(Web 服务客户端)。您可以在插件指令中指定要生成测试代码。您可以使用 mvn generate-sources 生成客户端存根,移动生成的源并修改测试。

在这两种情况下,都需要构建初始的pom(这次我还没有找到官方统一或推荐的pom)。您可以在 google 中搜索一些 pom.xml 轴示例(即:http ://wso2.org/library/90 )。

下面我有一些可用于构建 pom (WSC) 的 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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>your_group_id</groupId>
      <artifactId>your_artifact_id</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>your_artifact_id</name>
      <url>http://your_url</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.1</version>
          <scope>test</scope>
        </dependency>

        <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
          <version>2.5</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>jsp-api</artifactId>
          <version>2.1</version>
          <scope>provided</scope>
        </dependency>

        <!-- axis2/axiom: dependencies -->
        <dependency>
              <groupId>org.apache.axis2</groupId>
              <artifactId>axis2</artifactId>
              <version>${axis2.version}</version>
        </dependency>
        <dependency>  
           <groupId>org.apache.axis2</groupId>  
           <artifactId>axis2-transport-local</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-codegen</artifactId>
            <version>${axis2.version}</version>
            <scope>provided</scope>
        </dependency>   

        <!-- axis2-rampart: dependencies -->
        <dependency>
            <groupId>org.apache.rampart</groupId>
            <artifactId>rampart-core</artifactId>
            <version>${axis2.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-jdk14</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- slf4j: dependencies -->
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
          <version>${slf4j.version}</version>
          <!-- 
          <scope>runtime</scope>
          -->
          <exclusions>
            <exclusion>
                <artifactId>log4j</artifactId>
                <groupId>log4j</groupId>
            </exclusion>
          </exclusions>
        </dependency> 
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <!-- log4j: dependencies -->
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>${log4j.version}</version>
          <exclusions>
            <exclusion>
                <artifactId>jmxtools</artifactId>
                <groupId>com.sun.jdmk</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jmxri</artifactId>
                <groupId>com.sun.jmx</groupId>
            </exclusion>
            <exclusion>
                <artifactId>mail</artifactId>
                <groupId>javax.mail</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jms</artifactId>
                <groupId>javax.jms</groupId>
            </exclusion>
          </exclusions>
        </dependency>

        <!-- other: dependencies -->
      </dependencies>


      <build>
        <plugins>
          <plugin>
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>maven-jetty-plugin</artifactId>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
              <warName>${project.artifactId}</warName>
            </configuration>
          </plugin>

          <plugin>
              <groupId>org.apache.axis2</groupId>
              <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
              <version>${axis2.version}</version>
              <executions>
                  <execution>
                    <id>wsc_01</id>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <configuration>
                        <wsdlFile>${codegen.wsc_01.wsdl-uri}</wsdlFile>
                        <packageName>${codegen.wsc_01.package-name}</packageName>
                        <namespaceToPackages>${codegen.wsc_01.namespace-map}</namespaceToPackages>
                        <outputDirectory>${codegen.wsc.target-dir}</outputDirectory>
                        <databindingName>adb</databindingName>
                        <syncMode>sync</syncMode>
                        <generateServerSide>false</generateServerSide>
                        <generateServicesXml>true</generateServicesXml>
                        <generateTestcase>true</generateTestcase>
                        <language>java</language>
                    </configuration>
                  </execution>
                  <!-- other wsc-generation params -->
              </executions>
          </plugin> 

        </plugins>

      </build>

        <properties>
            <slf4j.version>1.6.3</slf4j.version>  
            <log4j.version>1.2.15</log4j.version>
            <axis2.version>1.6.0</axis2.version>
            <rampart.version>1.6.0</rampart.version>

            <!-- codegen.client.properties -->

            <codegen.wsc_01.wsdl-uri>wsdl_relative_path_or_url</codegen.wsc_01.wsdl-uri>
            <codegen.wsc_01.package-name>your_root_package</codegen.wsc_01.package-name>
            <codegen.wsc_01.namespace-map>http://your_url_namespace=your_java_namespace_mapped</codegen.wsc_01.namespace-map>

            <codegen.wsc.target-dir>target/generated-sources/axis2/wsdl2code</codegen.wsc.target-dir>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-jdk14</artifactId>
                    <version>1.5.2</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    </project>
于 2012-06-01T15:37:51.433 回答