[英]xsd import from different project, generate java class
I have two projects, A and B. In project AI have common.xsd file where I use cxf-xjc-plugin to generate java classes which work good. 我有两个项目,A和B.在项目AI中有common.xsd文件,我使用cxf-xjc-plugin生成工作正常的java类。 Next, I want to reuse this created files and type difinitions from common.xsd in main.xsd file in project B and don't generate classes from project A again, but there is a problem, because I can't include full path in my main.xsd file
接下来,我想重用这个创建的文件,并从项目B的main.xsd文件中的common.xsd中键入difinitions,并且不再从项目A生成类,但是有一个问题,因为我不能包含完整路径我的main.xsd文件
<xs:import namespace="..." schemaLocation="PATH_TO_PROJECT_A/common.xsd" />
or you classpath I read that it is possible to use http, but I can't use it. 或者你的类路径我读到可以使用http,但我不能使用它。 Is there a way to use a maven or something to do this ?
有没有办法使用maven或其他东西来做到这一点?
Yes, this is possible, keywords are: 是的,这是可能的,关键字是:
Required disclaimer: I'm the author of the maven-jaxb2-plugin
which provides these features. 必需的免责声明:我是提供这些功能的
maven-jaxb2-plugin
的作者。
Update: 更新:
I tried to use separate schema compilation, but unfortunately I can't undersant it.
我试图使用单独的模式编译,但不幸的是我不能忽略它。 Should I create separate jar only for xsd file and use it as a dependency ?
我应该只为xsd文件创建单独的jar并将其用作依赖项吗? Now I have dependency to the whole project A which contains generated classes and xsd file
现在我依赖于整个项目A,它包含生成的类和xsd文件
This is enough. 这就够了。 You need a JAR with generated classes, XSD files and
META-INF/sun-jaxb.episode
. 您需要一个带有生成类,XSD文件和
META-INF/sun-jaxb.episode
。 All of this is normally generated by default. 所有这些通常都是默认生成的。
Then you can use this JAR as an "episode". 然后你可以将这个JAR用作“剧集”。 XJC will use
sun-jaxb.episode
resource as binding file automatically, and this file basically says something like "don't generate anything for the schema in namespace X, use the following classes instead." XJC将自动使用
sun-jaxb.episode
资源作为绑定文件,并且该文件基本上表示“不为命名空间X中的模式生成任何内容,而是使用以下类”。 This is one part which allows you to avoid redundant generation of classes. 这是允许您避免冗余生成类的一部分。 This works mostly , but sometimes XJC still generates a few things - they can be safely deleted.
这主要是有效的 ,但有时候XJC仍会产生一些东西 - 它们可以被安全地删除。
The other thing is that you want to use schemas from the JAR. 另一件事是你想要使用JAR中的模式。 This can be done with catalogs and a special entity resolver which is by default delivered by the
maven-jaxb2-plugin
. 这可以通过目录和特殊实体解析器来完成,默认情况下由
maven-jaxb2-plugin
。
So just use any schemaLocation
and then rewrite it in the catalog file: 所以只需使用任何
schemaLocation
,然后在目录文件中重写它:
REWRITE_SYSTEM
"https://acme.com/foo/a.xsd"
"maven:com.acme.foo:foo-a!/a.xsd"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.