jaxb xsd 前缀包名

发布于 2024-12-26 10:01:03 字数 489 浏览 4 评论 0 原文

我有一个很大的 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

场罚期间 2025-01-02 10:01:03

要为每个 XML 模式获取不同的包名称,您可以利用 XJC 中的剧集文件扩展名分别从 XML 模式生成类。

从 a.xsd 生成 Java 类到包 com.example.a

xjc -d out -p com.example.a -episode a.episode a.xsd

从 b.xsd(导入 a.xsd)生成 Java 类到包 com.example.b

xjc -d out -p com.example.b b.xsd -extension -b a.episode

了解更多信息

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

xjc -d out -p com.example.a -episode a.episode a.xsd

Generate Java Classes from b.xsd (that imports a.xsd) to package com.example.b

xjc -d out -p com.example.b b.xsd -extension -b a.episode

For More Information

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文