maven-jaxb2-plugin: java.lang.NoSuchFieldError: encoding

This is the TLDR; version of this bug, so if the following solution doesn’t work for you, you might want to read it all.

When upgrading to a new version of Maven you might be faced with the following exception


[ERROR] Failed to execute goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate (schema-generate) on project WSModel: 
Execution schema-generate of goal org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate failed: 
An API incompatibility was encountered while executing org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.1:generate: 
java.lang.NoSuchFieldError: encoding

 

The problem is caused by a more recent version of com.sun.xml.bind:jabx-xjc being used when running the maven-jaxb2-plugin. It can be easily solved by excluding it from your plugin dependencies:

<plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <executions>
                    <execution>
                        <id>schema-generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <specVersion>2.1</specVersion>
                            <schemaDirectory>src/main/resources/xsd/models</schemaDirectory>
                            <schemaIncludes>
                                <include>
                                    XSD_releaseV00-09.xsd
                                </include>
                            </schemaIncludes>
                            <generateDirectory>target/generated-sources/xjc</generateDirectory>
                            <generatePackage>a.b.c</generatePackage>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.jvnet.jaxb2-commons</groupId>
                        <artifactId>property-listener-injector</artifactId>
                        <version>1.0</version>
                        <exclusions>
                            <exclusion>
                                <groupId>com.sun.xml.bind</groupId>
                                <artifactId>jaxb-xjc</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s