I am trying to run a webservice that I coded in Apache CXF. I keep getting this error:
Stacktrace:] with root cause
java.lang.ClassNotFoundException: org.apache.cxf.message.Message
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
I have the cxf-core
artifact added to my pom file and also I can see it included in the WAR file. And also the JAR which is actually throwing the exception. The part of the code that is throwing the exception is:
getBindingProvider().getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, connectTimeout);
getBindingProvider().getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPointUrl);
getBindingProvider().getRequestContext().put("com.sun.xml.internal.ws.request.timeout", 3720000);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Content-Type", Collections.singletonList("application/soap+xml"));
headers.put(Message.CONTENT_TRANSFER_ENCODING, Collections.singletonList("UTF-8"));
headers.put(Message.ENCODING, Collections.singletonList("UTF-8"));
getBindingProvider().getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
Am I doing something wrong?
I am building it with the maven-jar-plugin, like so:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<addDefaultEntries>true</addDefaultEntries>
<addBuildEnvironmentEntries>true</addBuildEnvironmentEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<attachClasses>true</attachClasses>
<includeEmptyDirectories>true</includeEmptyDirectories>
<outputDirectory>${project.basedir}/target/</outputDirectory>
</configuration>
</plugin>
How are you running it? If you run the war file, which contains the cxf jar file, which contains the Message class, it should not throw a classcastexception. Unless you have conflicting dependencies. Or something goes wrong with classloaders.
Check for conflicting jars. In intellij, they are marked at the right of your screen. Eclipse has something similar.