Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet - java

I am using eclipse neon.3 version and tomcat 8.5.15,I tried to execute simple hello world program using spring mvc but I am getting this issue=>
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet.
It happened only with spring mvc projects,rather than spring mvc,other codes executed successfully. Also mentioned the jar files which I have uploaded.
Please help me.

There is no javax.servlet-api.jar in the classpath. Maybe it is not in tomcat's lib folder.
Try to add this jar to your WEB-INF/lib directory. To download a jar go to https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.1.0

I had the same problem when I first tried to use Tomcat. If you imported HttpServlet class from jakarta.servlet.http try importing it from javax.servlet.http instead, that's what worked for me. Since I used jakarta-servlet-api dependency I expected to find the HttpServlet class in the javax.servlet.http package, however I was wrong.
I extracted the jakarta-servlet-api.jar and saw that the package is called javax.
So I imported HttpServlet from javax.servlet.http instead and it worked fine.

Related

org.apache.cxf.bus.extension.ExtensionException in WAS9 server

Can you please help me with following error I'm facing in WAS9 environment:
In order to resolve the import
org.apache.cxf.binding.soap.SoapHeader
I added the following dependencies in my pom.xml:
cxf-api-2.7.7
cxf-rt-bindings-soap-2.7.7
But when I'm trying to run my application, I'm getting the following error.
Default Executor-thread-7] ([ ]) Controllerclass - org.apache.cxf.bus.extension.ExtensionException
at org.apache.cxf.bus.extension.Extension.load(Extension.java:222)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:199)
at org.apache.cxf.bus.extension.ExtensionManagerImpl.initialize(ExtensionManagerImpl.java:118)
at org.apache.cxf.bus.extension.ExtensionManagerBus.doInitializeInternal(ExtensionManagerBus.java:147)
at org.apache.cxf.bus.CXFBusImpl.initialize(CXFBusImpl.java:191)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createBus(LibertyApplicationBusFactory.java:119)
at com.ibm.ws.jaxws.bus.LibertyApplicationBusFactory.createClientScopedBus(LibertyApplicationBusFactory.java:86)
at com.ibm.ws.jaxws.metadata.JaxWsClientMetaData.<init>(JaxWsClientMetaData.java:28)
at com.ibm.ws.jaxws.metadata.JaxWsModuleMetaData.getClientMetaData(JaxWsModuleMetaData.java:123)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:84)
at com.ibm.ws.jaxws.support.JaxWsMetaDataManager.getJaxWsClientMetaData(JaxWsMetaDataManager.java:123)
at com.ibm.ws.jaxws.client.LibertyProviderImpl.createServiceDelegate(LibertyProviderImpl.java:56)
at javax.xml.ws.Service.<init>(Service.java:57)
Caused by: java.lang.InstantiationException:org.apache.cxf.bus.osgi.OSGIBusListener
at java.lang.Class.newInstance(Class.java:427)
at org.apache.cxf.bus.extension.Extension.load(Extension.java:218)
Caused by: java.lang.NoSuchMethodException:org.apache.cxf.bus.osgi.OSGIBusListener.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
The server where your WAS9 has been deployed has different version of the above jar file. You need to have same version of jar files both in your eclipse where you have developed your codes and the server where you are deploying the war or ear.
mavan dependency file pom.xml is used during your project compilation. It might add the jar in your binary under lib folder as well. But WAS9 might considering the one which is in server's CLASSPATH. Hence check your class path and replace that jar with the one which you have mentioned in your pom.xml file. Hope that will fix your issue.
We can eliminate this exception by adding webProfile-7.0 in our server.xml, but how ever this is not working with javaee-7.0 not sure, if one knows about how to handle this in javaee-7.0 please share your approach.

classloading in Wildfly 9

I am deploying my application to Wildfly 9 and I am getting a strange error that resembles class loading problems. The same war file deploys successfully to Tomcat so I am guessing Wildfly is bundling com.google classes and somehow it is interfering with the bundled libraries in the war file.
First, the error looks like this:
Caused by: java.lang.IllegalAccessError: tried to access method com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/concurrent/ConcurrentMap; from class com.google.inject.internal.Annotations$AnnotationChecker
at com.google.inject.internal.Annotations$AnnotationChecker.<init>(Annotations.java:104)
at com.google.inject.internal.Annotations.<clinit>(Annotations.java:122)
at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:362)
at com.google.inject.Key.strategyFor(Key.java:354)
at com.google.inject.Key.get(Key.java:222)
at org.eclipse.sisu.wire.ParameterKeys.<clinit>(ParameterKeys.java:28)
at org.eclipse.sisu.wire.DependencyAnalyzer.<init>(DependencyAnalyzer.java:92)
at org.eclipse.sisu.wire.ElementAnalyzer.<init>(ElementAnalyzer.java:87)
at org.eclipse.sisu.wire.WireModule.configure(WireModule.java:74)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:94)
at com.google.inject.Guice.createInjector(Guice.java:71)
at com.google.inject.Guice.createInjector(Guice.java:61)
and I have both guava-16.0.1.jar and sisu-guice-3.1.0-no_aop.jar inside my war file's lib folder.
so I basically need to solve this issue, whether it is a class loading issue or not.

java.lang.ClassNotFoundException: javax.persistence.Entity

I got a sample project, copied from somewhere else, when I am trying to run it in netbeans I am getting some error/exceptions in tomcat's console window.
java.lang.ClassNotFoundException: javax.persistence.Entity
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at org.springframework.core.type.classreading.RecursiveAnnotationAttributesVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:167)
at org.springframework.asm.ClassReader.a(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
javax.persistence is already added to my project. I even removed and re-added in netbeans but still same error. This error is when running the web applictation not when compiling.
You need to add following Jar Files to your Build Path: -
javax.persistence_2.0.3.v201010191057.jar
org.eclipse.persistence.jpa_2.3.0.v20110604-r9504.jar
org.eclipse.persistence.jpa.equinox_2.3.1.v20111018-r10243.jar
org.eclipse.persistence.antlr_2.3.0.v20110604-r9504.jar
org.eclipse.persistence.asm_2.3.0.v20110604-r9504.jar
Preferably adding the first one will work, as javax.persistence.Entity is found in that Jar only.
But you may also need to add the later ones, for working with JPA
Google them with the name of JPA Jars. You will get them.
The javax.persistence.Entity is a class inside the Java EE SDK library “javaee.jar“, you are missing this jar file in your project classpath.
refer this http://www.mkyong.com/hibernate/java-lang-classnotfoundexception-javax-persistence-entity/

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.

<HTTP> <BEA-101163> <Could not load user defined listener:

I have modified an EAR for Weblogic 10 ( BEA 10 )which is already running on BEA 8..
I am getting the following error while deploying the EAR..
[HTTP:101163]Could not load user defined listener: com.xxx.xxxx.jmx.LifecycleListener java.lang.NoClassDefFoundError: com/tibco/sdk/MException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357) at java.lang.Class.getConstructor0(Class.java:2671) at java.lang.Class.newInstance0(Class.java:321) at java.lang.Class.newInstance(Class.java:303) at weblogic.servlet.internal.WebComponentContributor.getNewInstance(WebComponentContributor.java:187) at weblogic.servlet.internal.WebComponentContributor.createListenerInstance
Have you faced this error ?Please help me...
From the Exception it seems that some library is missing from your ear file. Make sure that com.xxx.xxxx.jmx.LifecycleListener is a valid package and included correctly in your ear.
If you are developing and building the ear with JDeveloper make sure you add this lib in your application resources. If you do this manualy make sure that this lib exists in your WEB-INF/lib folder

Categories

Resources