我有.wsdl文件并使用wsimport我正在生成类来使用webservices。
问题是我需要将toString方法添加到生成的类中。我看到它在xjc中是可能的,但在wsimport中无法找到方法。
你知道怎么做吗?
目前该功能看起来像
<basename property="basename.file" file="${file}" />
<mkdir dir="/tmp" />
<exec executable="wsimport">
<arg value="-catalog" />
<arg value="jax-ws-catalog.xml" />
<arg value="-s" />
<arg value="${src.generated}" />
<arg value="-keep" />
<arg value="-d" />
<arg value="/temp" />
<arg value="-Xnocompile" />
<arg value="file://mock_${basename.file}" />
</exec>
答案 0 :(得分:0)
根据link
CXF XJC toString插件提供了XJC插件,用于更新生成的bean以实现toString方法以覆盖默认的Object.toString方法。它使用Apache Commons Lang ToStringBuilder类来构建String,因此需要在类路径上提供commons-lang.jar。
添加参数-Xts
答案 1 :(得分:0)
免责声明:我是JAXB2-Basics XJC插件强大功能包的作者。
您可以使用ToString中的JAXB2-Basics进行此操作。它使用类似于commons-lang
的“战略”方法,但生成无反射的代码 - 这意味着生成的toString()
方法将非常快。
您将获得如下内容:
public String toString() {
final ToStringStrategy strategy = JAXBToStringStrategy.INSTANCE;
final StringBuilder buffer = new StringBuilder();
append(null, buffer, strategy);
return buffer.toString();
}
public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) {
strategy.appendStart(locator, this, buffer);
appendFields(locator, buffer, strategy);
strategy.appendEnd(locator, this, buffer);
return buffer;
}
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy strategy) {
{
USAddress theShipTo;
theShipTo = this.getShipTo();
strategy.appendField(locator, this, "shipTo", buffer, theShipTo);
}
{
USAddress theBillTo;
theBillTo = this.getBillTo();
strategy.appendField(locator, this, "billTo", buffer, theBillTo);
}
// ...
return buffer;
}
Ant的使用或多或少如下:
<target name="generate-sources">
<taskdef name="xjc" classname="org.jvnet.jaxb2_commons.xjc.XJC2Task">
<!-- XJC2 Task classpath -->
<classpath>
<fileset dir="${basedir}/lib">
<include name="activation-*.jar"/>
<include name="jaxb-api-*.jar"/>
<include name="jaxb-impl-*.jar"/>
<include name="jaxb-runtime-*.jar"/>
<include name="jaxb-core-*.jar"/>
<include name="jsr173_api-*.jar"/>
<include name="stax-api-*.jar"/>
<include name="jaxb-xjc-*.jar"/>
<include name="jaxb2-basics-ant-*.jar"/>
<include name="slf4j-*.jar"/>
<include name="jcl-over-slf4j-*.jar"/>
</fileset>
</classpath>
</taskdef>
<mkdir dir="${basedir}/target/generated-sources/xjc"/>
<xjc destdir="${basedir}/target/generated-sources/xjc" extension="true">
<arg line="
-Xequals
-XhashCode
-Xinheritance
-XtoString
-Xcopyable
-XenumValue"/>
<binding dir="${basedir}/src/main/resources">
<include name="**/*.xjb"/>
</binding>
<schema dir="${basedir}/src/main/resources">
<include name="**/*.xsd"/>
</schema>
<!-- Plugins -->
<classpath>
<fileset dir="${basedir}/lib">
<include name="jaxb2-basics-plugins-*.jar"/>
</fileset>
</classpath>
</xjc>
</target>
distribution有一个可立即运行的Ant示例(请参阅jaxb2-basics-sample-basic-<VERSION>-ant-src.zip
)。