Greg Marut
Greg Marut

Reputation: 193

use maven to generate java classes from xsd without annotations

Is there any way to use maven to generate java classes from an XSD (similar to jaxb2-maven-plugin) but just simply generates pojos without the javax.xml annotations?

Upvotes: 3

Views: 1273

Answers (2)

Water-whipper
Water-whipper

Reputation: 1

You can use Perl regex replacements on the xjc generated java to remove all the javax annotations and references as below:

$s =~ s/\@\w+\([^\(\)]+\)//smg;

$s =~ s/\@\w+\r\n//g;

$s =~ s/javax\.xml\.datatype\.XMLGregorianCalendar/java\.util\.Date/g;

$s =~ s/import javax.*;\r\n//g;

$s =~ s/XMLGregorianCalendar/Date/g;

It is not perfect in its treatment of spaces/carriage returns between annotations, but worked for me on a commercial project to generate the POJOs I needed.

See the full script here: https://github.com/ajbarber/JAXStripper

Upvotes: 0

Related Questions