NoSuchMethodError: com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar when application packages jaxp impl in JBoss EAP 7

Solution Verified - Updated

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 7.1

Issue

Application packaging jaxp-ri-2.0.jar (Sun JAXP Implementation classes) is failing when application tries to create new JAXP Schema object with NoSuchMethodError:

java.lang.NoSuchMethodError: com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Ljavax/xml/transform/Source;)Lcom/sun/org/apache/xerces/internal/xni/grammars/Grammar;
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
	at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
	at java.lang.Thread.run(Thread.java:748)
	at org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: java.lang.NoSuchMethodError: com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(Ljavax/xml/transform/Source;)Lcom/sun/org/apache/xerces/internal/xni/grammars/Grammar;
	at com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaFactoryImpl.newSchema(Unknown Source)
	at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:638)
	at com.redhat.examples.servlet.Servlet.init(Servlet.java:53)
...

Resolution

The application is packaging a jaxp implementation jar that is expecting a different version of the jaxp apis, so the application needs to package the jaxp-apis.jar / xml-apis.jar that corresponds to the implementation jar.

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.