使用 XML 工具: jaxb
2024年4月15日大约 1 分钟
介绍 Java 原生 oxm 工具 jaxb 的使用。
https://github.com/LawssssCat/blog/tree/master/code/demo-java-xml/n11-digester-usage/test/java/org/example/读
::: tabs
@tab XML 文件
File not found@tab 测试用例
File not found:::
写
File not foundmaven 插件 jaxb2-maven-plugin
jaxb2-maven-plugin 是一个用来代替 xjc 和 schemagen 用来完成 java 类和 schema 文件之间互相转换的 maven 插件。
官方地址:https://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/ (⭐⭐⭐)
github:https://github.com/mojohaus/jaxb2-maven-plugin \
mvn jaxb2:schemagen —— 从 Java 类生成 schema
mvn jaxb2:xjc —— 从 schema 文件生成 Java 类例子: https://github.com/LawssssCat/blog/tree/master/code/demo-java-maven/plugin-usage-jaxb2-maven-plugin/
::: tabs
@tab 依赖和插件配置
File not found@tab Java 类(源)
File not found@tab Schema 文件(生成)
File not found@tab Java 类(生成)
File not found:::
maven 插件 maven-jaxb2-plugin
maven 插件 maven-jaxb2-plugin 实现了基于 xsd 配置文件生成对应的 Java 类的功能。 在配置各种模型,属性很多的时候,生成相关文件非常方便。
Github: https://github.com/highsource/jaxb-tools?tab=readme-ov-file#jaxb-maven-plugin
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/tmsad</schemaDirectory>
<schemaIncludes>
<include>*.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
</plugin>