javaeclipsemavenxdoclet

Maven-based Code Generator


I have a need to have a config.xml file in my Eclipse project, and to use that file as the input to a Maven goal. That goal will use config.xml to auto-generate code (both XML and Java) under a generated/ directory (also in my project).

Thus:

MyProject/
    src/main/config
        config.xml
    src/main/java
        (All my Java source)
    (rest of my project)
    generated
        source/
            java/
            xml/

Thus the Maven goal would get kicked off prior to any compile- or build-related goals and would use config.xml to populate the generated/source/* directories as I need them. Those sources would then be available for subsequent goals to process.

Does such a tool exist? The closest I've been able to find is XDoclet but I have two concerns with it:

  1. I can't tell how flexible it is; i.e., to what degree I can put my own config "stuff" inside of config.xml, give XDoclet an XSD and let it go to town; more on this below
  2. Can't seem to find any Maven goals/plugins for it

As for the first item/issue, what I mean is this: ideally I'd like to put any kind of XML inside config.xml. So then, this ideal tool should only need an XSD for that XML, and some XSLT (or the likes) to determine how to autogenerate code from the XML found inside the config file.

I am not sure if XDoclet allows for such flexibility.

Any ideas or suggestions? There has to be something out there like this! Thanks in advance,


Solution

  • XDoclet is pretty flexible, but it purpose it to process java sources and generate something out of it. If you start with some xml, your best choice would be XSLT transformation - xdoclet ist not suitable for this.