Frage

I'm using the -clientjar wsimport parameter to export my WebService into a jar.

>wsimport -d C:\webservice -keep -clientjar webservice.jar http://localhost:8080/WebService?wsdl

A folder with the source code (.java files) and a webservice.jar are created.

The jar looks like this:

com
  |
  company
        |
        webservice
                 |
                 a bunch of .class files

META-INF
       |
       wsdl
          |
          wsdl file

However, when I put it on the WEB-INF/lib folder in my project, the classes are in the (default package) and are named like

com\company\webservice\file.class

I can't understand why. I've also used the -p parameter to specify a package name but it doesn't work.

Any clues?

War es hilfreich?

Lösung

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") )

Andere Tipps

I think the problem here is that -clientjar option is meant for an entirely different purpose than the OP expects.

The purpose of the -clientjar option is to embed a copy of the WSDL inside the generated artifacts so that it can become part of the application's jar file. The benefit of having a bundled WSDL (and actually using it of course) is that the web service consumer does not have to make a call to the endpoint to download the WSDL every time it initiates itself.

Links:

https://weblogs.java.net/blog/ramapulavarthi/archive/2010/09/03/wsimport-clientjar-option-ease-client-side-web-service-progra

Using jaxws-maven-plugin with -clientjar option

I had the same problem. Finally decided not to use the -clientjar option and generated a jar manually with jar.exe and works.

1.) Unzip/unjar clientjar

2.) jar file using

jar cvf <jarName>.jar <root_folders> 

example:

jar cvf weather.jar com META_INF

I used -clientjar so it will do all the work for me, but used my favorite file archiver to unzjar and jar it again.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top