users@jaxb.java.net

Re: Setting up a JAXB plugin development environment in Eclipse

From: No 0ne <no0ne_at_no0ne.org>
Date: Thu, 01 Oct 2009 13:33:48 +1000

On Thu, 2009-10-01 at 00:04 +0200, Anders Hessellund wrote:
> Hi,
>
> does anyone here have an easy "recipe" for setting up an environment
> to write JAXB plugins in Eclipse?
>
> -- Anders

Assuming that you ask for a "quick setup allowing one to trace into
(already written or under develpment) plugins", one may try this to
replace the xjc launching sequence with:

a. stick the jaxb libraries (downloading them rather than using the one
distributed with the standard jsdk) in your classpath ("User libraries"
- specifying the "Source code location" for the jars will also improve
you chances during the steps below)

b. start an equivalent xjc processing using the following snipped of
code (fill-in the gaps on exception-catching and other imports needed):

import com.sun.tools.xjc.Driver;

public class Launcher {

  static public void main(String[] args) {
    Class drvClass=Driver.class;
    try {
      Method mainEntryPoint=
       drvClass.getDeclaredMethod(
         "_main",
         new Class[] { String[].class }
       )
      ;
      mainEntryPoint.setAccessible(true); // the _main method is private
      mainEntryPoint.invoke(null, new Object[] { args });
    }
    catch(/* various exceptions here */) {
    }
  }
}
I found the above trick as needed (... eer...chmmm... at least
working... other approaches may also be possible) to get around
different "hacks" in the jaxb's xjc utility, causing it to fall into
using the jaxb libraries packed within jsdk (instead of using the ones
in your classpath)... to the result of no0ne (that's me) not being able
to trace in the jaxb tools' source code.

Then:
c. grab the JAXB specification to have it handy

d. take the source code of whatever already existing plugin you feel
closer to your liking and create a project from them sources. (warning:
shameless boasting here. The
http://www.no0ne.org/general-purpose/PropListInjector/index.html
has a nice balance between the complexity of overwriting/reusing in a
twisted way the classes in the com.sun.tools.xjc.generator.bean package
and the number of such classes to chew. It also may expose some design
flaws... but hey, it's working. Would you feel it's too complex, "fall
back" on simpler plugins, like the CamelCase one)

e. happy tracing (and googling-for/reading other documentation in the
same time. Having something you can trace during execution will enable
one to quickly select from the documentation what's relevant to one's
needs and... stay clueless on other details outside the scope of the
said needs... the way I'm staying now. Good strategy for a starter,
maybe not perfect for a PhD in jaxb, but it worked for me).

f. don't forget that you still want to write some plugin code. Use the
same strategy/setup to develop/trace/debug with your own code.

Best regards,

no0ne