简体   繁体   中英

Client/Server with Web Services. How to deal with generated sources in project setting?

I am developing a simple Client Server application.

The server side is a web service and deploys nicely to the application server with a wsdl file.

My other project, the client (lets say it is written in Swing), calls these web service methods. Because these web service methods use custom objects (not just string int etc...), i need to generate source files from the web services project.

In my Maven POM files, What is the best approach to dealing with the generated source files?

  1. call a wsimport on the client project
  2. call a wsimport on the server project, then somehow copy across to client project.
  3. call wsgen on the client project
  4. call wsgen on the server project, then somehow copy across to client project

The way I understand it, wsgen creates all the generated files from the web service java class (annotated with @Webservice ), whereas the wsimport creates these files form the wsdl file.

In general the vehicle I'd use is a project that builds a Library (Jar) for your WSDL.

I'd then deploy that to my Maven Repository and create a dependency in the POM file to pull it in.

For Maven you can use plugins to achieve this. Please see the example below for converting wsdl from Java code.

<plugin>  
      <groupId>org.apache.cxf</groupId>  
      <artifactId>cxf-java2ws-plugin</artifactId>  
      <version>2.6.3</version>  

      <dependencies>  
        <dependency>  
            <groupId>org.apache.cxf</groupId>  
            <artifactId>cxf-rt-frontend-jaxws</artifactId>  
            <version>${version.cxf}</version>  
        </dependency>  
        <dependency>  
            <groupId>org.apache.cxf</groupId>  
            <artifactId>cxf-rt-frontend-simple</artifactId>  
            <version>${version.cxf}</version>  
        </dependency>  
      </dependencies>  

      <executions>  
        <execution>  
          <id>process-classes</id>  
          <phase>process-sources</phase>  
            <configuration>  
              <className>com.Mycompany.name.work</className>  
              <outputFile>${project.build.sourceDirectory}/wsdl/work.wsdl</outputFile>  
              <genWsdl>true</genWsdl>  
              <verbose>true</verbose>  
            </configuration>  
            <goals>  
              <goal>java2ws</goal>  
            </goals>  
          </execution>  
      </executions>  

    </plugin> 

There is one more way to achieve this. You can generate the classes from WSDL in advance covert that to a jar file. Add java dependency in pom file for that jar. If you want to change the WSDl location more often, You can alter the Service class to read the Web Service Url from a property file. This way you will be flexible to change WSDL location also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM