代码之家  ›  专栏  ›  技术社区  ›  Larry Cai

Axis2 Maven示例

  •  17
  • Larry Cai  · 技术社区  · 15 年前

    我尝试使用AxIS2(1.5.1)版本来从WSDL文件生成Java代码,但我无法确定什么是正确的POM.XML。

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                <version>1.5.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2code</goal>
                        </goals>
                        <configuration>
                            <wsdlFile>src/main/resources/wsdl/stockquote.wsdl</wsdlFile>
                            <databindingName>xmlbeans</databindingName>
                            <packageName>a.bc</packageName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2</artifactId>
            <version>1.5.1</version>
        </dependency>
    </dependencies>
    

    当我键入mvn compile时,它会抱怨

    Retrieving document at 'src/main/resources/wsdl/stockquote.wsdl'.
    java.lang.ClassNotFoundException: org.apache.xml.serializer.TreeWalker
    

    如果我试图找到TreeWalker,那么找到合适的JAR文件就很麻烦了。

    你能给我个提示吗?或者给我正确的pom.xml

    [更新]xalan-2.7.0.jar也需要depedent,jar文件被破坏(由于nexus问题),thx pascal

    4 回复  |  直到 10 年前
        1
  •  22
  •   Pascal Thivent    15 年前

    这可能不是最佳的,但是下面的pom.xml似乎允许编译生成的代码:

    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.stackoverflow</groupId>
      <artifactId>Q2888422</artifactId>
      <version>1.0-SNAPSHOT</version>
      ...
      <dependencies>
        <dependency>
          <groupId>org.apache.axis2</groupId>
          <artifactId>axis2</artifactId>
          <version>1.5.1</version>
        </dependency>
        <dependency>
          <groupId>org.apache.ws.commons.axiom</groupId>
          <artifactId>axiom-api</artifactId>
          <version>1.2.6</version>
        </dependency>
        <dependency>
          <groupId>org.apache.ws.commons.axiom</groupId>
          <artifactId>axiom-impl</artifactId>
          <version>1.2.6</version>
        </dependency>
        <dependency>
          <groupId>axis</groupId>
          <artifactId>axis-wsdl4j</artifactId>
          <version>1.5.1</version>
        </dependency>
        <dependency>
          <groupId>org.apache.xmlbeans</groupId>
          <artifactId>xmlbeans</artifactId>
          <version>2.3.0</version>
        </dependency>
        ...
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.5.1</version>
            <executions>
              <execution>
                <goals>
                  <goal>wsdl2code</goal>
                </goals>
                <configuration>
                  <wsdlFile>src/main/resources/wsdl/stockquote.wsdl</wsdlFile>
                  <databindingName>xmlbeans</databindingName>
                  <packageName>a.bc</packageName>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
    

    这个pom.xml是一个结果或尝试错误加上一些谷歌搜索,我找不到一个有工作设置的官方或非官方资源。说真的,为什么设置一个Axis2项目这么困难?还有一个我不喜欢轴心国的原因。

        2
  •  4
  •   tibi    14 年前

    注意必须向上推配置(示例错误)

        <plugins>
        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.5.1</version>
                    <configuration>
                        <wsdlFile>src/main/resources/wsdl/stockquote.wsdl</wsdlFile>
                        <databindingName>xmlbeans</databindingName>
                        <packageName>a.bc</packageName>
                    </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    
        3
  •  2
  •   cosbor11    10 年前

    多亏了Pascal的pom,我可以通过使用最新版本来实现它。此外:

    • 我必须加上 build-helper-maven-plugin 插件,以便我的客户机类可以访问代理存根。
    • 我删除了 package 配置选项
    • 我改变了自己 outputDirectory

    这是我的POM:

    <?xml version="1.0" encoding="UTF-8"?>
    <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.yourcompany</groupId>
    <artifactId>axis2-server-proxy</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    
    <dependencies>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>1.2.15</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-impl</artifactId>
            <version>1.2.15</version>
        </dependency>
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-wsdl4j</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                <version>1.6.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsdl2code</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/</outputDirectory>
                            <wsdlFile>src/main/wsdl/services_visa_com_realtime_realtimeservice_v6_PublicV2.wsdl</wsdlFile>
                            <databindingName>xmlbeans</databindingName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.build.directory}/generated-sources/</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

        4
  •  1
  •   Vitaly Olegovitch    11 年前

    这是Pascal Thivent提供的POM的更新版本。

    主要的修改是版本名不同,需要neethi。

    <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.example</groupId>
        <artifactId>my-wsdl2code-example</artifactId>
        <version>1.0</version>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.axis2</groupId>
                    <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                    <version>1.6.1</version>
                    <executions>
                        <execution>
                            <id>execution_id</id>
                            <goals>
                                <goal>wsdl2code</goal>
                            </goals>
                            <configuration>
                                <packageName>com.example.wsdl</packageName>
                                <wsdlFile>src/main/wsdl/web-service.wsdl</wsdlFile>
                                <databindingName>xmlbeans</databindingName>
                            </configuration>
                        </execution>
                    </executions>
    
                    <dependencies>
    
                        <dependency>
                            <groupId>org.apache.xmlbeans</groupId>
                            <artifactId>xmlbeans</artifactId>
                            <version>2.6.0</version>
                        </dependency>
    
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
        <dependencies>
    
            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2</artifactId>
                <version>1.6.1</version>
            </dependency>
    
            <dependency>
                <groupId>axis</groupId>
                <artifactId>axis-wsdl4j</artifactId>
                <version>1.5.1</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.neethi</groupId>
                <artifactId>neethi</artifactId>
                <version>3.0.2</version>
            </dependency>
    
    
            <dependency>
                <groupId>org.apache.ws.commons.axiom</groupId>
                <artifactId>axiom-impl</artifactId>
                <version>1.2.14</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.xmlbeans</groupId>
                <artifactId>xmlbeans</artifactId>
                <version>2.6.0</version>
            </dependency>
    
        </dependencies>
    
    </project>
    
    推荐文章