class not found exception after replacing library in eclipse - java

UPDATE (I have updated the question since I only experience the following error)
I have replaced a Jena library (to get the newer version) in my Eclipse web application. Though I can use the new library and compile without error, I receive the the following exceptions when my code reaches the methods of Jena.
SEVERE: Servlet.service() for servlet [com.packages.servlets.CreatePatternServlet] in context with path [/TempProject] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class com.hp.hpl.jena.rdf.model.impl.ModelCom
I have log4j.properties in my project and other solutions I have came across did not seem to help.
Many thanks in advance

The Jena library depends on slf4j, so you need to get the slf4j-api.jar on your classpath. If you use Maven, you can simple add the Jena library with this XML snippet:
<dependency>
<groupId>com.hp.hpl.jena</groupId>
<artifactId>jena</artifactId>
<version>2.6.4</version>
</dependency>
and it would pull all the dependencies without any additional work on your part.

Problem solved when I added the libraries also into lib folder under WEB-INF.

Related

NoClassDefFoundError for com.sun.xml.internal.ws.fault.SOAPFaultBuilder

Our web service client in live environment recently got the exception:
java.lang.NoClassDefFoundError: Could not initialize class com.sun.xml.internal.ws.fault.SOAPFaultBuilder
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:107)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
at com.sun.proxy.$Proxy146.search(Unknown Source)
....
I've done a lot of search online, including a few posts here at StackOverflow:
Catching webservice exception with CXF: NoClassDefFoundError: SOAPFaultBuilder
Could not initialize class com.sun.xml.internal.ws.fault.SOAPFaultBuilder
java.lang.NoClassDefFoundError: Could not initialize class com.sun.xml.internal.ws.fault.SOAPFaultBuilder
And my understanding was our client received a SOAP Fault from the server and it's missing some jar file. So I'm trying to solve the problem by first recreating it.
I created a simple Web Service server project in Eclipse which has a web method throws a simple fault class annotated by #WebFault. Then I created a simple Web Service client project which consumes the web method. The client project doesn't have any additional libraries/jars in its classpath; all it has is the JRE. To my surprise, it didn't throw the NoClassDefFoundError exception! Instead, I got the javax.xml.ws.soap.SOAPFaultException I defined on the server side.
The class SOAPFaultBuilder is indeed in rt.jar in JRE. So the simple web service projects I created probably just work as they should. However, how come the web service client in our live environment throw the NoClassDefFoundError exception? That project definitely has rt.jar in the classpath.
Can anyone please shed some light on this problem? If it's missing some jar files (either from the jaxws RI or Apache CXF or others), why would the super simple client I created didn't throw the error? Both the live environment and my local environment use Java7u51.
I have encountered the same problem and I could subsequently resolve this.
Due to the following error mentioned in the Problem, the underlying cause of the SOAP Fault could not be found.
I followed the steps mentioned in the following link, to identify the reason for NoClassDefFoundError.
http://javarevisited.blogspot.in/2011/06/noclassdeffounderror-exception-in.html
I could find the following errors in my application log:
java.lang.ExceptionInInitializerError
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
The reason for the above classcast exception is due to conflicting jar files.
rt.jar (this is present in jre classpath)
jaxb-impl-2.0.1.jar (this is present in my application classpath).
I have removed the file jaxb-impl-2.0.1.jar from my classpath and the actual error is gone.
I had the same erorr and I resolved this issue by deleting the jax-impl.jar from the tomcat lib folder. It was a possible conflict of the jaxb jar versions with one of my webapps installed in tomcat.
http://programtalk.com/java/i-was-running-gwt-application-on-tomca/

JSP not importing second class

This should be a very easy question but I am not able to get this fixed. I have 2 import statements and in Netbeans it does not show any error but when I run the project, I am getting a ClassnotFoundDef error
<%# page import="mastertables.BranchMaster, mastertables.CreateBranchMaster"%>
both the classes are in the same package. The error is
javax.servlet.ServletException: java.lang.NoClassDefFoundError:org/hibernate/HibernateException
Please help, I am stuck on this small thing.
Thanks,
Abhijeet.
The application server is not able to retrieve the org.hibernate.HibernateException in the classpath. In this case i think you actually have the hibernate jars in your classpath, but the application server is complaining about not being able to find its definition.
Think about it: the most obvious exception for a missing dependency would be a ClassNotFoundExeption.
You are not getting this one, and you are also getting problems on instantiating an hibernate exception. Who would throw an hibernate exception if not the hibernate library itself.
So some part of hibernate is already loaded in the classpath, but not this specific class.
In my experience i'd check for libraries version conflicts/mismatch. Check the version of all the hibernate jars and dependencies.

Using Coda Hale Yammer Metrics library in Websphere Application Server 7

I am trying to add metrics library to existing webservice on WAS 7. I am getting below error
Error 404: javax.servlet.UnavailableException: SRVE0203E: Servlet [AdminServlet]: com.yammer.metrics.reporting.AdminServlet was found, but is missing another required class. SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server. SRVE0187E: Check your class path to ensure that all classes required by the servlet are present.SRVE0210I: This problem can be debugged by recompiling the servlet using only the classes in the application's runtime class path SRVE0234I
What are the other run-time dependencies required for metrics-servlet-2.2.0?
I have metrics-core-2.2.0.jar and metrics-servlet-2.2.0.jar in my WEB-INF\lib folder.
Threads, ping and healthcheck servlets work fine.
I think your missing some more required jars, are you not using maven or gradle for dependency management
Please refer here to know all required jars that metrics-servlet-2.2.0.jar depends on. http://mvnrepository.com/artifact/com.yammer.metrics/metrics-servlets/3.0.0-BETA1
My suggestion is, it is always difficult to maintain dependencies without Maven/Gradle or any other build tools :).

NoClassDefFoundError IN Struts2 framework

I am using Struts2 framework and using HttpClient class for making put request.
When I try to call httpClient's requestEntity method in LoginAction class I am getting the following error.
SEVERE: Exception starting filter struts2
java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
I have included all the required jar files in the class path.
Kindly help me figure out what could be the problem.
If you are using older version( apache commons less than 3.0) then that class will not be available in old jar. You have to use Apache commons 3.0 library. org/apache/commons/httpclient/methods/RequestEntity class is added since v3.0. Check javadoc.
Generally If we do not have jar added in classpath(or not in project) then we get ClassNotFoundException and if we have jar included in project and it is in classpath but particular class is not available then we get NoClassDefFoundError.

Maven / Spring: AopNamespaceUtils NoSuchMethod Error

Using Maven to build my project under windows works fine, but when I build it under Linux I get a NoSuchMethodError regarding one of the spring libs.
I am guessing it is something to do with class loader differences cross-platform and somewhere in my dependencies and I may have the same class twice but windows is loading one while linux loads the other?
Has anyone come across this problem before, or have any advice on how I can debug this error further?
nested exception is java.lang.NoSuchMethodError:
org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Lorg/w3c/dom/Element;)V:
java.lang.NoSuchMethodError:
org.springframework.aop.config.AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(Lorg/springframework/beans/factory/xml/ParserContext;Lorg/w3c/dom/Element;)V
at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser$AopAutoProxyConf
Stack Trace Pastie
POM.xml Pastie
Your spring dependencies have too many different versions:
org.springframework:spring-beans:jar:2.5.6:compile
org.springframework:spring-aop:jar:2.0.8:compile
org.springframework:spring-jms:jar:3.0.5.RELEASE:compile
Make all spring dependencies have the same version (preferably 3.0.5.RELEASE)

Categories

Resources