jaxb xsd前缀包名 [英] jaxb xsd prefix package names

查看:115
本文介绍了jaxb xsd前缀包名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的xsd文件(带导入),只有当xjc编译器根据每个xsd文件中指定的目标属性选择包名时才能生成。如果我指定一个特定的包名,那么它会尝试将所有生成的内容放在那个包中,并且我会收到大量的名称冲突。

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.

问题在于包名。我想在这些包名前加上前缀。
理想情况下,我希望com.othercompany.spec._2.Error成为com.mycompany.productx.data.spec.Error。
但我可以使用com.mycompany.productx.data.com.othercompany.spec._2.Error

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

后者只需要com.mycompany .productx.data。将所有生成的包名称作为前缀。

The latter would only require "com.mycompany.productx.data." to be prefixed to all the generated package names.

这有可能吗?

或者,我可以获取xjc生成的输出,并让Eclipse将java文件移动到另一个包中,但这是一个手动步骤,我想要一个自动构建过程来处理它,以便当其他人必须在6个月后重新生成它,他们不必考虑这个。

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.

推荐答案

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

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.

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

Generate Java Classes from a.xsd to package com.example.a

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

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

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

更多信息

  • http://blog.bdoughan.com/2011/12/reusing-generated-jaxb-classes.html

这篇关于jaxb xsd前缀包名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆