[英]Regenerate classes after changes in XSD files from maven dependency in maven-jaxb2-plugin
[英]Generating Java classes from XSD maven dependency in maven with JAXB (or others)
我有一個數據模型作為 XSD 文件存儲在 Maven 存儲庫中。 我的目標是創建一個包含代表此模型的所有 Java 類的 jar。 我想使用 maven 和 JAXB 來做到這一點。 我知道 maven-jaxb2-plugin(codehouse-mojo 和 java-net,還不確定它們有什么不同),但我沒有看到使用 maven 依賴項中的 XSD 作為輸入的方法。 我是否必須編寫自己的插件才能做到這一點?
如果有更好的工具,它不一定是 JAXB。
免責聲明:我是maven-jaxb2-plugin
。
檢查文檔,它就在那里。 請參閱指定要編譯的內容 - 指定 URL、文件集和 Maven 工件資源。
例子:
<configuration>
<schemas>
<!--
Compiles a schema which resides
in another Maven artifact.
-->
<schema>
<dependencyResource>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-tests-po</artifactId>
<!-- Can be defined in project dependencies or dependency management -->
<version>${project.version}</version>
<resource>purchaseorder.xsd</resource>
</dependencyResource>
</schema>
</schemas>
</configuration>
您還可以使用目錄將架構 URL 重寫為Maven 工件資源。
例子:
REWRITE_SYSTEM "http://schemas.opengis.net" "maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc"
這會將 URI http://schemas.opengis.net/ows/2.0/owsAll.xsd
重寫為maven:org.jvnet.ogc:ogc-schemas:jar::!/ogc/ows/2.0/owsAll.xsd
。 這將引用ogc-schemas
JAR 工件中的ogc/ows/2.0/owsAll.xsd
資源。
據我所知,這些特性是maven-jaxb2-plugin
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.