users@jaxb.java.net

RE: JAXB compilation plugin

From: Jonathan Johnson <jonjohnson_at_mail.com>
Date: Wed, 8 Feb 2006 22:44:33 -0500

Kohsuke,

In writing the JAXB Maven 2 compiler plugin I have been trying different
API/interfaces to generate the source code from the schema while supporting
all the required options that we all expect. Below you suggested using
com.sun.tools.xjc.api.Driver or com.sun.tools.xjc.XJC2Task.

XJC2Task will not work because the code is tightly bound to the Ant classes
(see XJC2Task.getProject()).

There are two Driver classes, I'm unclear on the difference between the two

com.sun.tools.xjc.api.Driver
com.sun.tools.xjc.Driver

In conclusion, I found that

com.sun.tools.xjc.Driver.run(String[] args, XJCListener listener)

will probably work the best.

Sound right to you?

- Jonathan

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:kohsuke.kawaguchi_at_sun.com]
Sent: Friday, January 27, 2006 8:33 PM
To: users_at_jaxb.dev.java.net
Subject: Re: JAXB compilation plugin



Welcome! I added you to http://jaxb2-sources.dev.java.net/ as a
developer, so you should be able to put your files to CVS [1]

Jonathan Johnson wrote:
> Kohsuke suggested creating a JAXB 2 Maven plugin for java.net. Both the
JAXB
> and Maven efforts could benefit from this - so here we go...
>
> I invite anyone to contribute advice for the following...
>
> Requirements for the JAXB/Mavin 2 plugin.

I think we can start with the simplest. A plugin that invokes XJC with a
bunch of options, in the pre compilation phase of maven 2.

> JAXB generation procedures, configurations and gotchas

I can think of a few ways to go.

   - com.sun.tools.xjc.api.Driver.main is the CLI entry point,
     so you can invoke this to drive the entire XJC. The Driver
     class has a few other run methods that's useful for
     automation (such as one that takes XJCListener, which allows
     you to (probably) easily hook error report into Maven's
     error report system.

     This is easier to drive, but you have to define yet another
     syntax for configuring XJC in pom.xml, then you have to convert
     them to String[].

   - com.sun.tools.xjc.XJC2Task is the Ant task implementation.
     Since Maven also configures plugins through XML, it would
     be really nice if the plugin configuration XML can be used
     to populate an XJC2Task instance. In that way, we can reuse
     XJC's ant task syntax with Maven, so people don't have to
     learn a new syntax, and there's no need to constantly update
     a plugin to keep up with syntax changes in XJC (not that it
     happens often, but still...)

     I'd imagine this would be harder, but I'd imagine there's
     some code either in Ant or Maven that you can reuse.

> Maven 2 plugin development

As James suggested, I think it's easier to start by looking at what
other plugins do. If you don't mind using the same license as they do,
then you can even copy their code.


[1]
https://jaxb2-sources.dev.java.net/source/browse/jaxb2-sources/jaxb-maven2-p
lugin/
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com