9

Is there a way to configure JAXB to so that a generated class implements a specified interface? I'm intending to use JAXB generated classes as DAO's and they should be able implement my DAO interface.

C. Ross
  • 31,137
  • 42
  • 147
  • 238
  • 1
    The same as [Generating a JAXB class that implements an interface](http://stackoverflow.com/questions/1271980). – dma_k Feb 07 '12 at 22:40
  • Thanks @dma_k I'll mark it for closure. – C. Ross Feb 07 '12 at 23:49
  • possible duplicate of [Generating a JAXB class that implements an interface](http://stackoverflow.com/questions/1271980/generating-a-jaxb-class-that-implements-an-interface) – C. Ross Feb 07 '12 at 23:49

2 Answers2

6

Unfortunately, it looks like the interface-injection plugin mentioned in some of the other answers is no longer well supported. In fact, I'm having trouble finding the JAR for download.

Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin).

The JAXB2 Basics Plugins documentation includes instructions for using the plugin with Ant and Maven.

The JAXB2 Basics Plugins provides a number of other utilities which you might also find useful (such as autogeneration of equals, hashCode, and toString methods).

Jim Hurne
  • 7,187
  • 4
  • 44
  • 44
  • 1
    Unfortunately it seems like the JAXB2 Basics Plugin lacks now of any documentation. This is the only site left: http://static.highsource.org/jaxb2-basics/jaxb2-basics-tools/project-info.html – Strinder Aug 06 '13 at 09:49
  • Here's a maven sample configuration that shows how to use 'jaxb2-basics` as a extension to `cxf-xjc-plugin`: https://gist.github.com/pulkitsinghal/8163296 – pulkitsinghal Dec 28 '13 at 19:57
5

The interface injection plugin for XJC lets you do this.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 5
    the website doesn't exist anymore, is the solution obsolete? What is the way to do it now? – Franz Kafka Mar 29 '12 at 13:46
  • I'm going nuts trying to make this work. The referred link doesn't work anymore and applies to ALL the generated objects which most of the times is useless! Anyone know if this interface injection plugin can still be used and how? – Clint Eastwood Dec 18 '13 at 12:09