我们尝试使用gradle、xsd和xjc生成JAXB类,JAXB类应该包含XmlRootElement注解,以便可以将其公开为Web服务响应。我们跟踪了http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html链接,它帮了我们很大的忙,但我们无法找到仅使用gradle的特定示例。因此,我们找到了一些东西,并将其作为答案与大家分享。
我们尝试使用gradle、xsd和xjc生成JAXB类,JAXB类应该包含XmlRootElement注解,以便可以将其公开为Web服务响应。我们跟踪了http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html链接,它帮了我们很大的忙,但我们无法找到仅使用gradle的特定示例。因此,我们找到了一些东西,并将其作为答案与大家分享。
8条答案
按热度按时间qeeaahzv1#
build.gradle应如下所示
schema.xsd
binding.xjb
也可以使用xjb
现在您可以运行任务'jaxb',一切就绪。干杯!
User.java
ymzxtsji2#
pn9klfpd3#
所有其他的答案都是过时的,截至本文撰写时。
jakarta.xml.bind:jakarta.xml.bind-api
提供。org.glassfish.jaxb:jaxb-runtime
给出。org.glassfish.jaxb:jaxb-xjc
给出的。Jakarta XML Binding (previously called JAXB) Reference Implementation。
xjc选项。
下面是一个使用KotlinDSL的完整工作示例:
vaj7vani4#
我的版本使用gradle原生功能来生成jaxbclasses。
或者,如果您的架构依赖于外部XSD,请使用“Oasis Catalog”技术在本地解析外部XSD。在这种情况下,还可以禁用XML架构验证以防止验证错误。
或者,您可以使用自定义jaxb绑定来调整jaxb类。
基本上是一个gradle自定义任务,它调用Java VM中可用的XJCTask ant任务,在我的示例中,库来自Java 8。任务名称是“generateSources”,需要调整到您的模式位置。
如果您需要目录,请创建一个文件“catalog.xml”,该文件可能如下所示:
用于jax绑定
如果除了jaxb生成之外,您还需要包含这些类来构建。您需要调整gradle源代码布局和依赖关系。
就这样了!
qxsslcnc5#
使用gradle-jaxb-plugin的Gradle配置
xjc配置中注解掉的值是默认值-如果需要可以更改。
和gradle.properties档案
并将其与Intellij链接,请将以下内容添加到您的build.gradle文件中
whhtz7ly6#
我一直在使用Sping Boot * 生成SOAP Web服务 * 指南作为参考。这里是GitHub中build.gradle文件的链接。
https://github.com/spring-guides/gs-producing-web-service/blob/master/complete/build.gradle
bn31dyow7#
这是一个适用于我的Java 11 / Gradle 6的解决方案。最近,在我的一个项目上更新构建系统后,我发现在Gradle中通过Ant任务使用XJC时出现了一些问题-这种方法只使用普通Gradle,没有Ant。
更新:按照this question,使用GlassFish实现可以避免Sun内部依赖关系的问题
hwamh0ep8#
这就是我在Java 14和Gradle 6.7中的工作方式我的build.gradle文件看起来像这样: