I got stuck trying to convert a XSD + XJB file to a POJO that has no JAXB annotations inside its code.
Project structure:
- pom.xml
- src/main/resources/schema.xsd
The file schema.xsd can be found here as an example.
I am using Maven and the plugin jaxb2-basics-annotate
Here is my maven file (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>
When I run the command mvn on command line, I get the following Java file, generated in the /target directory:
@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);
}
}
@XmlAccessorType and @XmlType should be removed. But they are still there.
Thanks for any help !
If you get it to work, try to put the file binding.xjb under src/main/resources/ and try again.
We have updated the jaxb-annotate-plugin in jaxb-tools (former location of
org.jvnet.jaxb2.maven2:maven-jaxb2-plugin
, merged with jaxb2-basics, jaxb-annotate-plugin and other related repository), since your problem is related to an issue we filled in there : https://github.com/highsource/jaxb-tools/issues/340The next release will include a new
RemoveXmlAnnotation
Plugin, activable via-XremoveXmlAnnotation
option (and an extraXremoveXmlAnnotation:removeObjectFactory
option to remove ObjectFactory class).The PR has been created and is actually under review. If needed, will be able to backport it to v2 version of the plugin.
Feel free to look at our migration guide since many artifacts where relocated.
EDIT 06/02/2024 : 4.0.2 released, enjoy !