求助:如何将XSD+XJB转换为不含JAXB注解的POJO
问题:XSD转无JAXB注解POJO失败,@XmlAccessorType与@XmlType注解无法移除
项目结构
- pom.xml
- src/main/resources/schema.xsd
使用Maven及jaxb2-basics-annotate插件进行转换,pom.xml配置如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>xsd-to-pojo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>XSD to Pojo</name> <properties> <plugin.version>1.1.0</plugin.version> <jaxb.version>2.3.1</jaxb.version> <maven-jaxb2-plugin.version>0.14.0</maven-jaxb2-plugin.version> </properties> <packaging>jar</packaging> <dependencies> <dependency> <groupId>org.glassfish.jaxb</groupId> <artifactId>jaxb-runtime</artifactId> <version>${jaxb.version}</version> <scope>provided</scope> </dependency> </dependencies> <build> <defaultGoal>compile</defaultGoal> <plugins> <plugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>${maven-jaxb2-plugin.version}</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <encoding>UTF-8</encoding> <extension>true</extension> <args> <arg>-Xannotate</arg> <arg>-XremoveAnnotation</arg> </args> <plugins> <plugin> <groupId>org.jvnet.jaxb2_commons</groupId> <artifactId>jaxb2-basics-annotate</artifactId> <version>${plugin.version}</version> </plugin> </plugins> </configuration> </plugin> <plugin> <inherited>true</inherited> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build> </project>
运行mvn compile后,target目录生成的Java类代码如下:
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "gh16Type", propOrder = { "x" }) public class Gh16Type { protected Object x; public Object getX() { return x; } public void setX(Object value) { this.x = value; } public boolean isSetX() { return (this.x!= null); } }
已配置-XremoveAnnotation参数,但生成的类仍保留@XmlAccessorType和@XmlType注解,请求解决此问题。问题解决后,请测试将指定binding.xjb文件放入src/main/resources/后的转换效果。
内容的提问来源于stack exchange,提问作者joccafi
相关产品推荐
相关产品推荐

