1、使用 trang.jar生成xsd文件
java -jar trang.jar test.xml test.xsd
tarng.jar下載鏈接:https://note.youdao.com/s/7qYsVXtQ
2、使用maven插件生成實體
在pom.xml文件中添加以下配置即可:
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <version>2.5.0</version> <executions> <execution> <id>xjc</id> <goals> <goal>xjc</goal> </goals> </execution> </executions> <configuration> <packageName>com.example.package.name</packageName> <schemaDirectory>${project.basedir}/src/main/resources/schema</schemaDirectory> <outputDirectory>${project.build.directory}/generated-sources/xjc</outputDirectory> </configuration> </plugin> </plugins> </build>
其中,packageName為生成的Java類的包名,schemaDirectory為XSD文件存放的目錄,outputDirectory為生成Java類的輸出目錄。執行 mvn jaxb2:xjc 即可在指定的輸出目錄下生成對應的Java類。
浙公網安備 33010602011771號