ClassCastException between internal classes and Axis’ classes


Have you tried turning it off and on again?

The Problem

The Java application fails with a ClassCastException between classes from package com.sun.xml.internal and classes from package org.apache.axis, for instance:

java.lang.ClassCastException: com.sun.xml.internal.messaging.saaj.soap.impl.ElementImpl cannot be cast to org.apache.axis.message.MessageElement

The Reason

The application expects to be using Axis’ classes, whereas at runtime “system” (internal) classes happen to be loaded instead.

The Solution

If you have a “dedicated” environment, try telling Java to use Axis’ classes, setting up the appropriate system variables in JVM’s launch script.
If you are using Tomcat, for instance, try adding the following in catalina.sh (or .bat):

JAVA_OPTS="$JAVA_OPTS -Djavax.xml.soap.SOAPFactory=org.apache.axis.soap.SOAPFactoryImpl"
JAVA_OPTS="$JAVA_OPTS -Djavax.xml.soap.MessageFactory=org.apache.axis.soap.MessageFactoryImpl"
JAVA_OPTS="$JAVA_OPTS -Djavax.xml.soap.SOAPConnectionFactory=org.apache.axis.soap.SOAPConnectionFactoryImpl"

View original post