2012-05-16 86 views
3

我是Maven和Axis2的新手。我的項目由三個模塊組成:客戶端,接口和服務器。服務是基於POJO的。 WSDL正在服務器模塊中構建。接口模塊包含常見的東西,如服務接口和bean。Axis2與Maven的最佳實踐

我是否應該將WSDL生成(或手動複製)到接口模塊中?我應該在客戶端模塊上生成客戶端代碼嗎?模塊結構是否正常?我想要做的就是使構建過程自動化,但嚴格構造。

回答

6

它不會清除您稱爲「接口」的組件。 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)。您可以在谷歌搜索一些pom.xml軸示例(例如:http://wso2.org/library/90)。

下面我有一些XML,你可以用它來建立POM(WSC):

<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> 
+0

我做控制服務器和客戶端創建,並希望分開一些常見的豆類進入分離模式。它似乎不是非常流行的解決方案,所以我即將擺脫接口模塊... –