CXF Maven wsdl2java插件未在生成的jaxb类中生成toString()方法 [英] CXF maven wsdl2java plugin not generating toString() methods in the generated jaxb classes

查看:115
本文介绍了CXF Maven wsdl2java插件未在生成的jaxb类中生成toString()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用了CXF maven插件,该插件将wsdl文件转换为适当的Java类。但是在生成的Java类中看不到toString()方法。您能否让我知道如何生成toString()方法。以下是我在项目中使用过的pom.xml的代码段:

I have used CXF maven plugin in my project which converts wsdl file to appropriate Java classes. But I don't see toString() method in the generated Java classes. Can you please let me know how to generate toString() method. Below is the snippet of my pom.xml which I've used in my project:

    <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.trx</groupId>
  <artifactId>resxWebservices</artifactId>
  <version>10.4.1</version>

  <name>resxWebservices</name>
  <packaging>jar</packaging>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>2.6.0</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <sourceRoot>src</sourceRoot>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>./resxWebservices.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-xjc-Xts</extraarg>
                  </extraargs>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.cxf.xjc-utils</groupId>
            <artifactId>cxf-xjc-runtime</artifactId>
            <version>2.6.0</version>
          </dependency>
          <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
          </dependency>
          <dependency>
            <groupId>org.apache.cxf.xjcplugins</groupId>
            <artifactId>cxf-xjc-ts</artifactId>
            <version>2.6.0</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
          <executable>${JAVA_HOME}/bin/javac</executable>
          <compilerVersion>1.6</compilerVersion>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.apache.cxf.xjc-utils</groupId>
      <artifactId>cxf-xjc-runtime</artifactId>
      <version>2.6.0</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.6</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf.xjcplugins</groupId>
      <artifactId>cxf-xjc-ts</artifactId>
      <version>2.6.0</version>
    </dependency>
  </dependencies>
</project>


推荐答案

我相信首先您必须使pom变得整洁免费。

I believe first you have to make your pom little clutter free.

您需要具有2个依赖关系才能生成 toString()方法。你们两个都在使用。您唯一的错误是在 cxf-codegen-plugin 依赖项中包含 cxf-xjc-runtime

从上述位置删除它。

并将其放入模块/项目依赖项中。

它将开始工作。下面是示例代码段:

You need to have 2 dependency to get the toString() method generated. Both you are using. Only mistake you are doing is to have cxf-xjc-runtime in your cxf-codegen-plugin dependency.
Remove this from said location.
And put it in module/project dependency.
It will start working. Below is the example snippet:

<dependencies>
    ....
    <dependency>
        <groupId>org.apache.cxf.xjc-utils</groupId>
        <artifactId>cxf-xjc-runtime</artifactId>
        <version>3.0.5</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>3.1.6</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${basedir}/src/main/generated</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${basedir}/../someService.wsdl</wsdl>
                                <extraargs>
                                    <extraarg>-xjc-Xts</extraarg>
                                </extraargs>
                            </wsdlOption>                               
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.cxf.xjcplugins</groupId>
                    <artifactId>cxf-xjc-ts</artifactId>
                    <version>3.0.5</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
    </plugins>

</build>

这样做之后,您将得到如下结果:

After doing this, you will have result like below:

/**
 * Generates a String representation of the contents of this type.
 * This is an extension method, produced by the 'ts' xjc plugin
 * 
 */
@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, JAXBToStringStyle.DEFAULT_STYLE);
}

这篇关于CXF Maven wsdl2java插件未在生成的jaxb类中生成toString()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆