Apace CXF - How to generate java classes in a specific root package?

520 views Asked by At

this works "fine" when generating the .java:

"C:\Program Files\apache-cxf-3.5.2\bin\wsdl2java.bat" -client http://localhost:10000/Framework.TbGes.TbGes?wsdl

but it generates many (100+) packages, all in different roots.

It I try instead: wsdl2java.bat -p com.test -client http://localhost:10000/Framework.TbGes.TbGes?wsdl

I get some thousands time this error:

WSDLToJava Error: http://virtual-1:10000/Framework.TbGes.TbGes?xsd=xsd24 [0,0]: Due dichiarazioni causano un conflitto nella classe ObjectFactory. http://virtual-1:10000/Framework.TbGes.TbGes?xsd=xsd39 [0,0]: (Relativo allerrore riportato sopra) Questa รจ laltra dichiarazione.
http://virtual-1:10000/Framework.TbGes.TbGes?xsd=xsd39 [0,0]: Due dichiarazioni causano un conflitto nella classe ObjectFactory.

I suppose wsdl2java is trying to generate all the classes DIRECTLY inside com.test, forgetting the (sub)package name defined in the WDSL, and creating conflicts in case of classes with same name

Question: is there any option, to tell wsdl2java to generate all classes in the package com.test, but also keeping the sub-packages as defined in the WDSL ?

Example:

omitting "-p com.test", those are created:

package webproxyobj_dospinaction.services.web.microarea;

package setuserinteractionmode.services.web.microarea;

I would like that with "-p com.test", the same 2 are created like this:

package com.test.webproxyobj_dospinaction.services.web.microarea;

package com.test.setuserinteractionmode.services.web.microarea;

thank you

1

There are 1 answers

2
SpaceTrucker On

Based on the documentation on https://cxf.apache.org/docs/wsdl-to-java.html there is the option

-p [ wsdl-namespace= ] PackageName

Specifies zero, or more, package names to use for the generated code.
Optionally specifies the WSDL namespace to package name mapping.

So you probably have to add a mapping for every wsdl namespace you encounter in your wsdl. You should be able to use a regex-search-and-replace in the wsdl to generate that command line argument. However this might become very long and depending on your os and shell may exceed a command line lenght limit.