title: How do I add an xjc plugin programmatically at runtime?
body: <p>I'm generating JAXB classes from an xsd at runtime using XJC. But by default the <code>maxLength</code> restriction in the xsd isn't annotated.</p>
  
  <p>I found a plugin to deal with this, <a href="https://github.com/krasa/krasa-jaxb-tools" rel="nofollow">krasa-jaxb-tools</a>. I've added the dependencies to my POM, but I can't seem to add the plugin to the XJC process.</p>
  
  <p>I'm using version 2.2.11 of the jaxb-xjc tools. Here are my dependencies:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-xjc&lt;/artifactId&gt;
      &lt;version&gt;2.2.11&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
      &lt;version&gt;2.2.11&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-core&lt;/artifactId&gt;
      &lt;version&gt;2.2.11&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
      &lt;artifactId&gt;jaxb-jxc&lt;/artifactId&gt;
      &lt;version&gt;2.2.11&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;com.github.krasa&lt;/groupId&gt;
      &lt;artifactId&gt;krasa-jaxb-tools&lt;/artifactId&gt;
      &lt;version&gt;1.3&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>I'm trying to instantiate the plugin, configuring it and passing it to the <code>generateCode(Plugins[] extensions, ErrorListener errorListener)</code> method on my <code>S2JJAXBModel</code> model, but it doesn't seem to have any effect. Here's my code:</p>
  
  <pre><code>SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
  schemaCompiler.forcePackageName(packageRoot);
  
  // JAXB Plugin used to get the proper @Size annotations on all fields.
  JaxbValidationsPlugins jaxbValidationPlugin = new JaxbValidationsPlugins();
  
  // Build up list of options for the plugin.
  // First option must be the name of the plugin itself.
  // Options must be prefixed with dashes
  String[] args = new String[] { "-" + JaxbValidationsPlugins.PLUGIN_OPTION_NAME };
  
  try {
      // Activate plugin
      jaxbValidationPlugin.parseArgument(new Options(), args, 0);
  } catch (BadCommandLineException | IOException e1) {
      e1.printStackTrace();
  }
  
  InputSource inputSource = new InputSource(schemaFile.toURI().toString());
  
  schemaCompiler.parseSchema(inputSource);
  S2JJAXBModel model = schemaCompiler.bind();
  
  // Passing the plugin to the method
  JCodeModel jCodeModel = model.generateCode(new Plugin[] {jaxbValidationPlugin}, null);
  </code></pre>
  
  <p>What am I doing wrong?</p>