我有一个很大的 xsd 文件(带有导入),只有当 xjc 编译器根据每个 xsd 文件内指定的目标属性选择包名称时才能生成该文件。如果我指定一个特定的包名称,那么它会尝试将所有生成的内容放入该包中,并且我会遇到大量名称冲突。
问题在于包名称。我想为这些包名称添加前缀。
理想情况下,我希望 com.othercompany.spec._2.Error 变为 com.mycompany.productx.data.spec.Error 。
但我可以接受 com.mycompany.productx.data.com.othercompany.spec._2.Error
后者只需要“com.mycompany.productx.data”。作为所有生成的包名称的前缀。
这有可能吗?
或者,我可以采用 xjc 生成的输出,并让 Eclipse 将 java 文件移动到另一个包中,但这是一个手动步骤,我希望有一个自动构建过程来处理它,这样当其他人必须重新生成它时 6几个月后,他们就不必考虑这个了。
I have a large xsd file (with imports), which can only be generated when the xjc compiler gets to pick package names based on the target attributes specified inside each of the xsd files. If I specify a specific package name, then it tries to place all generated content in that one package and I get a ton of name collisions.
The issue is with the package names. I would like to prefix these package names.
Ideally I'd like com.othercompany.spec._2.Error to become com.mycompany.productx.data.spec.Error instead.
But I can live with com.mycompany.productx.data.com.othercompany.spec._2.Error
The latter would only require "com.mycompany.productx.data." to be prefixed to all the generated package names.
Is this possible at all?
Alternatively, I could take the xjc generated output, and have Eclipse move the java files into the other package, but that's a manual step and I'd like an automated build process to handle it, so that when someone else has to regenerate it 6 months down the line, they don't have to think about this.
发布评论
评论(1)
要为每个 XML 模式获取不同的包名称,您可以利用 XJC 中的剧集文件扩展名分别从 XML 模式生成类。
从 a.xsd 生成 Java 类到包
com.example.a
从 b.xsd(导入 a.xsd)生成 Java 类到包
com.example.b
了解更多信息
To get a distinct package name per XML schema, you could generate classes from the XML schemas separately by leverage the episode file extension in XJC.
Generate Java Classes from a.xsd to package
com.example.a
Generate Java Classes from b.xsd (that imports a.xsd) to package
com.example.b
For More Information