users@jaxb.java.net

RE: JAXB compilation plugin

From: Jonathan Johnson <jonjohnson_at_mail.com>
Date: Thu, 9 Feb 2006 22:51:25 -0500

>> I'd mildly prefer for you to use the XJC2Task
>> So I think it's still possible to do this.

I'm taking your suggestions to heart ;-) I was able to resolve the missing
project and logging issues when using XJC2Task in a Maven 2 Mojo plugin.
Its invoking the XJC2Task.execute() now, but execute is dumping
NoClassDefFoundError(s).

[info] build id of XJC is 2.0-02/04/2006 12:06 AM(kohsuke)-fcs
[info] Consider using <depends>/<produces> so that XJC won't do unnecessary
compilation
[info] Checking timestamp of src\test\resources\purchaseorder.xsd
[info] the last modified time of the inputs is 1139536362836
[info] the last modified time of the outputs is -9223372036854775808
[info] Compiling
file:/D:/development/jaxb2-sources/jaxb-maven2-plugin/src/test/resources/pur
chaseorder.xsd
[ stderr ] ---------------------------------------------------------------
[ stacktrace ] -----------------------------------------------------------
java.lang.NoClassDefFoundError: javax/activation/DataSource
        at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBu
iltinLeafInfoImpl.java:182)
        at
com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfo
SetImpl.java:25)

I resolved this one by downloading activation.jar (had to do it manually as
Sun does not appear to permit automatic Maven 2 downloads, this is not
good). After adding activation.jar to the repository the domino falls to
this...

java.lang.NoClassDefFoundError: javax/xml/stream/XMLStreamException
        at
com.sun.xml.bind.v2.runtime.JAXBContextImpl.createUnmarshaller(JAXBContextIm
pl.java:607)

Why are these extra jar(s) needed? The pom.xml is attached to show the
current dependencies...

Standard po schema is attached (I suspect its fine). The code is...

        XJC2Mojo xjc2Mojo = new XJC2Mojo(); // Derives from XJC2Task to
resolve logging differences
        xjc2Mojo.setLogger(log);
        xjc2Mojo.setProject(new Project());
        xjc2Mojo.setDestdir(targetDirFile);
        xjc2Mojo.setSchema(schema);
        xjc2Mojo.execute(); // <-- throws class not found errors.


-----Original Message-----
From: Kohsuke Kawaguchi [mailto:kohsuke.kawaguchi_at_sun.com]
Sent: Thursday, February 09, 2006 1:04 AM
To: users_at_jaxb.dev.java.net
Subject: Re: JAXB compilation plugin


Jonathan Johnson wrote:
> XJC2Task will not work because the code is tightly bound to the Ant
classes
> (see XJC2Task.getProject()).

Yes, you are right that it's written for Ant.

But on the other hand, it's surprisingly easy to drive Ant from any Java
program. For example, in one of my hobby project Hudson, I use Ant's
copy task [1]. Maven1 did it all the time (through Jelly.)

So I think it's still possible to do this.

> 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.

That said, I think this method would be also just fine.

I'd mildly prefer for you to use the XJC2Task, because of the nice XML
syntax it already offers, but that's more complicated.

So I think your pick is sound --- and once you get started, and if you
are interested, perhaps I could help to hook up XJC2Task into the maven
plugin.


[1]
https://hudson.dev.java.net/source/browse/hudson/hudson/src/hudson/tasks/Art
ifactArchiver.java?rev=1.2&view=markup
--
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com