我是Maven和Axis2的新手。我的项目包括三个模块:客户端,接口和服务器。服务是基于POJO的。 WSDL正在服务器模块上构建。接口模块包含服务接口和bean之类的常见内容。
我应该将WSDL生成(或手动复制)到接口模块中吗?我应该在客户端模块生成客户端代码吗?模块结构好吗?我想做的就是让构建过程自动化但结构严谨。
答案 0 :(得分:7)
它不会清除您称为“界面”的组件。 对于Web服务构建,有两种主要方法:
我建议采用第一种方法,因为并不总是可以控制开发的两个方面。您可以使用第二种方法从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)。
下面我有一些可以用来构建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>