Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wsimport -clientjar generates classes in (default package)

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?

like image 569
Bubumuk Avatar asked Sep 23 '13 19:09

Bubumuk


People also ask

What does wsdl2java generate?

wsdl2java takes a WSDL document and generates fully annotated Java code from which to implement a service. The WSDL document must have a valid portType element, but it does not need to contain a binding element or a service element. Using the optional arguments you can customize the generated code.

What is Wsimport in Java?

The wsimport command-line tool processes an existing Web Services Description Language (WSDL) file and generates the required artifacts for developing Java™ API for XML-Based Web Services (JAX-WS) web service applications.

What is Wsimport explain different options of it?

The wsimport command generates the following JAX-WS portable artifacts. These artifacts can be packaged in a WAR file with the Web Services Description Language (WSDL) file and schema documents and the endpoint implementation to be deployed. The wsimport command also provides a wsimport Ant task.

What is Wsgen and Wsimport?

wsgen and wsimport are the tools for JAX-WS web services that generates artifacts. These artifacts helps for deployment and invocation of JAX-WS web services. To generates artifacts, wsgen reads end point of web services and generates the required class files.


1 Answers

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") )
like image 95
Stas Avatar answered Oct 04 '22 22:10

Stas