views:

566

answers:

1

I'm trying to use a jaxb plugin to insert a interface into a choice element generating the classes from maven. The problem is that I can't seem to figure out how to do so from maven, the repository isn't clear from the documentation and the only example (bellow) doesn't work, it seems to ignore the plugin (maven reports no error about not finding it) or the plugin doesn't have all the adds-ons currently listed in the project documentation:

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.6.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <generatePackage>br.com.wonder.nfe.xml</generatePackage>
                <args>
                    <arg>-Xifins</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>basic</artifactId>
                        <version>0.4.1.5</version>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

I have these in the root pom:

<pluginRepositories>
    <pluginRepository>
        <id>maven2-repository.dev.java.net</id>
        <url>http://download.java.net/maven/2&lt;/url&gt;
    </pluginRepository>
    <pluginRepository>
        <id>maven-repository.dev.java.net</id>
        <name>Java.net Maven 1 Repository (legacy)</name>
        <url>http://download.java.net/maven/1&lt;/url&gt;
        <layout>legacy</layout>
    </pluginRepository>
</pluginRepositories>

Running that gives:

Error while setting CmdLine options '[-Xifins, -episode, /home/administrador/JavaApp/wnfe3/wnfe-ejb/target/generated-sources/xjc/META-INF/sun-jaxb.episode]'!

Embedded error: unrecognized parameter -Xifins

+1  A: 

I'm really not sure this is the "right" way to solve this but, this is what I did. First, download the Interface Insertion Plugin xjc-if-ins.jar from https://jaxb2-commons.dev.java.net/interface-insertion/xjc-if-ins.jar (couldn't find a jar containing IfInsertPluginImpl.class in the java.net maven repository).

Then, install the jar in the local repository:

mvn install:install-file -DgroupId=org.jvnet.jaxb2_commons \
                         -DartifactId=xjc-if-ins \
                         -Dversion=1.0-SNAPSHOT \
                         -Dpackaging=jar \
                         -Dfile=xjc-if-ins.jar

Finally, add the jar as a dependency of the maven-jaxb2-plugin in the plugin section:

<build>
  <plugins>
    <plugin>
      <groupId>org.jvnet.jaxb2.maven2</groupId>
      <artifactId>maven-jaxb2-plugin</artifactId>
      <version>0.6.2</version>
      <executions>
        <execution>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <extension>true</extension>
        <args>
          <arg>-Xifins</arg>
        </args>
        <plugins>
          <plugin>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>basic</artifactId>
            <version>0.4.1.5</version>
          </plugin>
        </plugins>
      </configuration>
      <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>xjc-if-ins</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
      </dependencies>
    </plugin>
    ...
  </plugins>
  ...
</build>

As I said, this is maybe not the cleanest way to configure the jaxb2 plugin to use the Interface Insertion Plugin but, with this setup, the generate goal doesn't complain about the -Xifins extension.

Pascal Thivent
Seems like there is really no way to do so without adding the jar in the local repository, I filled a issue for this, thanks
solerman
I agree, we shouldn't have to do this manual stuff and this jar should 1. be available in the java.net repository 2. should be added to the plugin dependencies. Oh, don't forget to accept this answer :)
Pascal Thivent
Have you had any luck getting this to work with wsimport?
Sionide21
@Sionide21 Who? Me?
Pascal Thivent
I should have said has anyone. I can't figure out where to put that dependency to get it passed through from wsimport to jaxb.
Sionide21
@Sionide21 You should open an new question, the commenting system is not appropriate to answer this.
Pascal Thivent
My bad. I'll do that
Sionide21