CXF Wsdl2Java 最佳实践
我目前正在使用 cxf 2.4.0,我的代码是 Web 服务的调用者。我能够使用 Maven 中的 cxf 插件生成客户端 java 文件。我的问题是生成文件的最佳实践是什么?我应该编译生成的文件并将生成的类文件打包到单个 jar 文件中,还是应该将所有生成的 java 文件包含在构建路径中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我让 CXF 在 target 下生成代码,它默认选择 target/ generated-sources/cxf ,这对我来说很好。 (如果您使用 xjc 来处理模式,它会使用类似的方案。Maven 非常适合约定!)
我有时会将生成的代码放入其自己的 Maven 模块中,这有时可以简化事情; Eclipse 对生成的源代码并不完全满意(它不喜欢清理会将源代码从它的脚下撕下来这一事实),因此将其放在视线之外会使事情变得更加简单。毕竟,它只是一个碰巧从 WSDL 文档生成的库......
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…
对于生成的代码,我通常在“main”(main/src/java - main/ generated/java)下创建一个“生成”文件夹,并且我有 CXF 在那里生成类。然后我只需将“生成”文件夹添加到编译器源路径中。
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.
创建一个构建任务(ant/maven),生成代码并将编译后的代码打包成jar文件。当wsdl发生变化时,您只需重新运行构建任务即可。
如果您选择生成源,请使用生成 注释。大多数 wsdl 生成工具都有此选项。
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.