users@jaxb.java.net

Re: XJC error message

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 16 Nov 2006 11:29:59 +0100

Hi.

> I have extending FieldRendererFactory, GenericFieldRenderer.
>
> When I run my build file on ant,
>
> It showed runtime-error message
>
> java.lang.IllegalAccessError: Class myplugin.MyGenericFieldRenderer can
> not access a member of class
> com.sun.tools.xjc.generator.bean.field.SingleField with modifiers
> "protected"

Something is wrong with the code of MyGenericFieldRenderer.

> After that I tried to extend the class SingleClass.
> Here I added the enum of Messages hard-coded into this class.
>
> And still while parsing xml schema
> I got an error message
>
> C:\UserData\salimher\testJava\plugin\build.xml:42:
> java.lang.IllegalArgumentException: trying to create the same field
> twice: addressUnit

Obviously you're trying to create the same field within the defined class twice.
Review your field renderer code.

> But I have no idea why this happens, while I don't even get the line
> number where this error caused.
> This schema work fine when I don't override those XJC classes.
>
> Any idea?
> Or can we show the line number causing the error using ant?

Try -d -v.

I would also suggest that you implement (or use) some kind of test harness for
plugins. When I develop plugins, I use maven-jaxb2-plugin-testing where I have
stuff like RunXJC2Mojo. This allows executing plugins from within an IDE like
Eclipse, with all debugging etc.
Here's how a typical test class look like:

public class RunToStringPlugin extends RunXJC2Mojo {

   @Override
   public File getSchemaDirectory() {
     return new File(getBaseDir(), "src/test/resources");
   }

   @Override
   protected void configureMojo(AbstractXJC2Mojo mojo) {
     // TODO Auto-generated method stub
     super.configureMojo(mojo);
     mojo.setForceRegenerate(true);
   }

   @Override
   public List<String> getArgs() {
     final List<String> args = new ArrayList<String>(super.getArgs());
     args.add("-XtoString");
     return args;
   }
}

RunXJC2Mojo is a JUnit test case, runnable from Eclipse.

In the example above, schemas are loaded from src/test/resource, toString plugin
is activated in getArgs().

Bye.
/lexi