How to generate equals() and hashcode() methods using wsimport in jaxws
Asked Answered
P

3

8

The generated classes from my WSDL using wsimport are not having equals() and hashcode() methods. How can I customize and generate the client classes to get equals() and hashcode() methods.

I am not sure about using JAXB to achieve this.

In Axis2.0 generated stubs these methods are generated but not sure why such a basic thing is not available in JAXWS!

Psychometry answered 29/6, 2011 at 15:50 Comment(0)
S
7

You can use the JAXB2 Basics Plugin to generate equals() and hashcode() methods:

Swanskin answered 29/6, 2011 at 17:52 Comment(2)
Thanks, I will check this with wsimport, meantime can you please give an example if you have one.Psychometry
502 Bad Gateway.. is it only these few days?Earthy
P
1

More information on how it worked. I have to add classpath to jaxb2-commons and without which wsimport runs without complaining but nothing happens! After adding the classpath as below

<path id="jaxb2-commons.classpath">
    <fileset dir="${dir.toolchain}/noarch/jaxb2-basics-dist-0.6.0">
        <include name="**/*.jar" />
    </fileset>
</path>

the below wsimport worked as expected

<wsimport wsdl="@{dir-wsdl}/@{name-wsdl}"
          taskname="wsimport-@{service}"
          destdir="@{dest-dir}"
          sourcedestdir="@{source-dest-dir}"
          package="@{package}"
          keep="@{keep}"
          verbose="@{verbose}"
          xdebug="@{xdebug}"
          xnocompile="@{xnocompile}"
          target="2.1">
    <binding dir="@{dir-wsdl}" includes="bindings-wsdl-@{name-wsdl}.xml, bindings-schema-@{name-wsdl}.xml" />
    <xjcArg value="-Xequals" />
    <xjcArg value="-XhashCode" />
    <xjcArg value="-XtoString" />
    <!-- Generates per-package jaxb.index file which lists all of the schema-derived classes in this package.-->
    <xjcArg value="-Xjaxbindex" />
    <xjcArg value="-Xsetters" />
</wsimport>
Psychometry answered 30/6, 2011 at 12:28 Comment(1)
It'd be helpful if you specified how you added the classpath to wsimport.Coryza
M
1

If you are looking to generate hashcode() and equals() using wsimport in maven, check this answer on how to generate value constructors, but also includes the configuration for generating hashcode() and equals() too:

How do I make wsimport generate constructors?

Monoicous answered 2/1, 2014 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.