There are two options of achieving this , both works like a charm. And both options can be automated from ant\gradle you name it .
1.To use -clientjar and then to repack the sources
2.Manually insert the wsdl into jar and customize the wsdLlocation URL
Assuming you have C:\WSDL\SO\stas.wsdl (I was running on windows)
CD C:\WSDL\SO\
First option
C:\WSDL\SO>wsimport -clientjar StasWebServiceClient.jar stas.wsdl
This creates StasWebServiceClient.jar jar file , but when importing it to eclipse, the sources are not importable , because of the topic problem (default package).
=> Unzip the jar file to current folder , you can use 7zip, or any other great zip tool , or you can run
C:\WSDL\SO>jar xf StasWebServiceClient.jar
to unzip the jar .
Folder hierarchy should look like
C:\WSDL\SO\META-INF
C:\WSDL\SO\stas.wsdl(original wsdl)
C:\WSDL\SO\StasWebServiceClient.jar(generated jar file)
C:\WSDL\SO\META-INF\wsdl(created by -clientjar)
C:\WSDL\SO\META-INF\wsdl\stas.wsdl(copied by -clientjar)
C:\WSDL\SO\com\...
/* all generated classes\sources */
C:\WSDL\SO\com\...
=> Do
C:\WSDL\SO>jar -cvf StasWebServiceClientCorrect.jar com META-INF
this will create another jar , StasWebServiceClientCorrect.jar , which now has the correct packaging .
Second option
=> Run wsimport
C:\WSDL\SO>wsimport -keep stas.wsdl
to generate the code .I always like to have -keep option there , but it's up to you.
=> create META-INF folder
C:\WSDL\SO>mkdir META-INF
=> Create META-INF/wsdl folder
C:\WSDL\SO>cd META-INF
C:\WSDL\SO\META-INF>mkdir wsdl
=> go one folder up .
C:\WSDL\SO\META-INF>cd ..
=> Copy stas.wsdl file into META-INF\wsdl\stas.wsdl
C:\WSDL\SO>copy stas.wsdl META-INF\wsdl\stas.wsdl
=> Create a jar archive
C:\WSDL\SO>jar -cvf StasWebServiceClient.jar com META-INF
Import the jar to workspace. When you will be creating the actual call to the service , use :
StasService stasService = new StasService(StasService.class.getClassLoader().getResource("META-INF/wsdl/stas.wsdl") )