Search code examples
javamavenjaxbcxfeclipse-classpath

Same Package, Same Class in two Maven Projects a WAR and a JAR, classpath issue


I am having some classpath issue. I have a Web Application which is a web service. It uses JaxB and CXF. The web service has a dependecy of another JAR which is a Web Service Client. Now both the client and the service codes are generated by using wsdl2java plugin. The problem looks like this:

Parent WebService WAR
--PackageA
  --ClassB
Dependency Jar
--PackageA
  --ClassB

So both of them have the same package and the same class name and since these are generated by the plugin, it makes difficult to refactor one of the package so that they would not be identical. The WebService calls the client and in client code initializes the parent classB from web service instead of the classB from web service client Jar. The only problem in this ClassB is that they have one method which takes differnet parameter, in one class B it takes, Date whereas in another classB it takes XmlGregorianCalendar. So while calling the client i am getting nosuchmethodexception.

Here is what i tried so far without luck:

1: In the Client jar i tried giving the full package and class name to initialize the ClassB

2: In the Client jar i tried wiring the classes using Spring bean and surprisingly it is still wiring the class from the webService instead of the client

3: In the web service ClassB, i tried adding the same method that takes the right parameter. This works partially but result in another exception which is not good.

Looking forward for your help. Thanks!

Solved the issue by passing extra args to wsdl2java plugin while generating classes from the wsdl as per user2880879 suggestion like this:

<extraarg>-p</extraarg>
<extraarg>http://www.example.com=mypackagename</extraarg>  

Solution

  • I believe you are creating webservice using top down approach, means write java class first using jaxws annotations and then create wsdl using cxf maven plugin or ant, and use this wsdl to create client ?

    If you are following this approach then you can provide binding file when you generate web service client code. click here to know what is binding file and how to write.

    In this binding file you can specify package name you want to change for client code.