SAXParseException with jdk8 and maven-jaxb2-plugin

This question has the same root cause as this one. There are two ways to solve this problem:

Setting the javax.xml.accessExternalSchema system property:

If you are only building locally, you can add this line to a file named jaxp.properties (if it doesn't exist) under /path/to/jdk1.8.0/jre/lib :

javax.xml.accessExternalSchema=all

This won't work if you might be working on the project with others, especially if they are still using jdk7. You could just run your maven build with the system property specified on the command line:

$mvn <target and options> -Djavax.xml.accessExternalSchema=all

You can also use a plugin to set the system property for you:

<plugin>
    <!-- Needed to run the plugin xjc en Java 8 or superior -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <id>set-additional-system-properties</id>
            <goals>
                <goal>set-system-properties</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <properties>
            <property>
                <name>javax.xml.accessExternalSchema</name>
                <value>all</value>
            </property>
            <property>
                <name>javax.xml.accessExternalDTD</name>
                <value>all</value>
            </property>
        </properties>
    </configuration>
</plugin>

You can also configure the maven-jaxb2-plugin to set the property:

<plugin>
   <groupId>org.jvnet.jax-ws-commons</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>2.3</version>
   <configuration>
     <!-- Needed with JAXP 1.5 -->
     <vmArgs>
         <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
     </vmArgs>
   </configuration>
</plugin>

Setting the target version: If you don't want to use system properties, you can set up the maven-jaxb2-plugin to target version 2.0:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>${maven.plugin.jaxb2.version}</version>
    <configuration>
        <args>
            <arg>-target</arg>
            <arg>2.0</arg>
        </args>
    </configuration>
</plugin>

With the 2.4 version of the plugin:

<externalEntityProcessing>true</externalEntityProcessing>

Tags:

Java

Xsd

Maven