I'm currently using cxf 2.4.0 and my code is a caller to a webservice. I was able to generate the client side java files using the cxf plugin in Maven. My question is what is the best practice for the generated files? Should I compile the generated files and package the generated class files into a single jar file or should I include all of the generated java files in the build path?
I get CXF to generate the code under target, it picks target/generated-sources/cxf by default, which is good by me. (If you're using xjc for handling a schema, it uses a similar scheme. Maven is great for conventions!)
What I sometimes do is put the generated code in its own maven module, which can sometimes simplify things; Eclipse is not entirely happy with generated source code (it doesn't like the fact that cleaning rips the source code out from under it's feet) so corralling that out of sight makes things much simpler. After all, it's just a library that happens to be generated from a WSDL document…
For generated code, I normally create a "generated" folder under "main" (main/src/java - main/generated/java) and I have CXF to generate the classes there. Then I just add the "generated" folder to the compiler source path.
Create a build task (ant/maven) that generates the code and packages the compiled code into a jar file. When the wsdl changes, you only have to re-run the build task.
If you choose to generate the source, use the Generated annotation. Most wsdl generation tools have this option.
精彩评论