简体   繁体   English

在Java App中引用JAXB生成的类

[英]Referencing JAXB-generated Classes in a Java App

I have an app for which I am thinking of using Java classes generated from an XSD using JAXB. 我有一个应用程序,正在考虑使用从使用JAXB的XSD生成的Java类。 Because of the DRY principle, I feel I should make the class generation part of the build process and not include them in source control. 由于DRY原理,我觉得我应该使类生成成为构建过程的一部分,而不应将它们包括在源代码管理中。

But, if I do this, how can I write the client code that references the to-be-generated Java classes? 但是,如果这样做,如何编写引用待生成的Java类的客户端代码? I guess the build would work okay, if I compile the code after the class generation, but it seems weird to be writing to a non-existent API (that is only generated at build time). 我猜想,如果我在类生成之后编译代码,构建就可以了,但是似乎很奇怪地要写入不存在的API(仅在构建时生成)。

What is the usual practice for referencing JAXB-generated classes in client code in regard to this problem? 关于此问题,在客户端代码中引用JAXB生成的类的通常做法是什么?

It's absolutely normal. 绝对正常 At my previous work we had been living with JAXB-generated classes for three years. 在我以前的工作中,我们一直使用JAXB生成的类三年。 So, put ".xsd" files and ant/maven task (wsimport, xjc, etc.) under version control and think about this xsd-files as about primary document. 因此,将“ .xsd”文件和ant / maven任务(wsimport,xjc等)置于版本控制下,并将此xsd文件视为主要文档。 Generated java code in your case is secondary document (like javadocs generated by normal java files). 在您的情况下,生成的Java代码是辅助文档(如普通Java文件生成的javadocs)。 So these documents doesn't deserve to be put under version control (unless you want to do some integrated vcs diff). 因此,不应将这些文档置于版本控制下(除非您要执行一些集成的vcs diff)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM