CXF-RS: Java Code Generation from xml/xsd

Cleaner approach is to use xjc like this:



Continue to dirty approach below if u need to:

When working with CXF-RS services often we start with XML message that will be served. After that we go through endless iteration of generating the right Java POJO's for the XML. The library like apache XMLBeans generate the Java code but the code generated is not what a developer would write and generally tedious to modify and understand.

I have come across a work around for generating Java classes from XSD (xml) which is very close to what a developer with decent experience will write. 

Follow the steps given below to explore the solution:
1. Generate the wsdl from from xsd as given in at this link (http://cxf.apache.org/docs/xsd-to-wsdl.html).
2. The Java classes can be generated from wsdl from maven plugin entry below find complete details here http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html


 org.apache.cxf
 cxf-codegen-plugin
 ${cxf.version}
 
  
   generate-sources
   generate-sources
   
    ${project.build.directory}/generated/cxf
    
     
      ${basedir}/src/main/wsdl/myService.wsdl
     
    
   
   
    wsdl2java
   
  
 


Hope this reduce your headache. Happy coding :)

Comments

Popular posts from this blog

java.net.SocketException: Connection reset

Hide empty last column from Table/Tree Viewer

Spring: implements interface not working in @Controller