SAP-archive / cloud-weatherapp

New sample application demonstrating the interplay of several HCP services to develop a full fledged application.
Apache License 2.0
17 stars 17 forks source link

java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet #3

Open voicedmendor opened 8 years ago

voicedmendor commented 8 years ago

I am stuck at How to expose business functionality as an external RESTful API. I checked for solutions online but nothing seems to work. Appreciate an help on this.

Deployment is successful. When I try to RUN the application I get the below error stack:

2016 04 19 23:09:00#0-500#INFO#System.out##anonymous#Thread-6#na#N/A#N/A#N/A##Undeploying file with path [C:\Users\mypc\workspace_hcp\Servers2\Java Web Server-config\.\pickup\weatherapp.war]| 2016 04 19 23:09:01#0-500#INFO#System.out##anonymous#Thread-6#na#N/A#N/A#N/A##Undeployment of file with path [C:\Users\mypc\workspace_hcp\Servers2\Java Web Server-config\.\pickup\weatherapp.war] is successful.| 2016 04 19 23:09:03#0-500#INFO#System.out##anonymous#Thread-6#na#N/A#N/A#N/A##Deploying file with path [C:\Users\mypc\workspace_hcp\Servers2\Java Web Server-config\.\pickup\weatherapp.war]| 2016 04 19 23:09:04#0-500#ERROR#org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/weatherapp]##anonymous#Thread-6#na#N/A#N/A#N/A##Servlet [CXFServlet] in web application [/weatherapp] threw load() exception *# *java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet** at org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader.loadClass(BundleWebappClassLoader.java:312) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1146) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1085) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5318) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5610) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) at org.eclipse.gemini.web.tomcat.internal.TomcatServletContainer.startWebApplication(TomcatServletContainer.java:125) at org.eclipse.gemini.web.internal.StandardWebApplication.start(StandardWebApplication.java:109) at org.eclipse.gemini.web.extender.WebContainerBundleCustomizer.addingBundle(WebContainerBundleCustomizer.java:49) at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:482) at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:1) at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:262) at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:234) at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:457) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:847) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1523) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1459) at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1454) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:391) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299) at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291) at com.sap.core.js.deployer.watchservice.WARDeployer.deploy(WARDeployer.java:177) at com.sap.core.js.deployer.watchservice.FileSystemEventsListener.onChange(FileSystemEventsListener.java:37) at org.eclipse.virgo.util.io.FileSystemChecker.notifyListeners(FileSystemChecker.java:245) at org.eclipse.virgo.util.io.FileSystemChecker.check(FileSystemChecker.java:166) at com.sap.core.js.deployer.watchservice.WatchTask.run(WatchTask.java:29) at java.lang.Thread.run(Thread.java:745)|

cguttikonda commented 7 years ago

Hi Have you resolved this issues. If so can can you update the same

Dragomitch commented 7 years ago

Hi there ! I'd the same issue and there's how I solved it.

A little explanation

In the way that the tutorial is done, we create an Dynamic Web Project that will package and send an war to the tomcat server we create. At this point, we have eclipse that generates the war archive and send it to the server (I think that is the Tomcat server that generates them for us at this moment, or something related to him)

After that we setup maven do the same without specifying or setup anything about the workflow of the war archives. As we use maven to download/handle dependencies, we will have exceptions because of not found classes etc ...

Solution

The solution is straightforward now that we understood the problem : change the .war build location to the one that the Tomcat server uses ( .../YourEclipseFolder/Servers/YourServerName-config/pickup ) StackOverFlow post that helped me

TechSkieur commented 7 years ago

Hi there,

I met the exact same problem..but according to @Dragomitch 's solution, the problem still exists. I check the wtpwebapps folder, the weatherapp is deployed there successfully. I am wondering could it possibly be related to the servlet mappings in web.xml? Any one has clue? Thanks for answering.

The logs is below:

type Exception report

message Servlet.init() for servlet CXFServlet threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet CXFServlet threw exception org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615) com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:170) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168) com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94) com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:45) com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1770) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1729) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) java.lang.Class.getConstructors(Class.java:1651) org.apache.cxf.jaxrs.utils.ResourceUtils.findResourceConstructor(ResourceUtils.java:318) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.createSingletonInstance(CXFNonSpringJaxrsServlet.java:368) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.getResourceProviders(CXFNonSpringJaxrsServlet.java:357) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.init(CXFNonSpringJaxrsServlet.java:120) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615) com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:170) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168) com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94) com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:45) com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1770) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1729) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) root cause

java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpUriRequest org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892) org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735) java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) java.lang.Class.getConstructors(Class.java:1651) org.apache.cxf.jaxrs.utils.ResourceUtils.findResourceConstructor(ResourceUtils.java:318) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.createSingletonInstance(CXFNonSpringJaxrsServlet.java:368) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.getResourceProviders(CXFNonSpringJaxrsServlet.java:357) org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.init(CXFNonSpringJaxrsServlet.java:120) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615) com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:170) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962) com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168) com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94) com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:45) com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1770) org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1729) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745)

TechSkieur commented 7 years ago

Problem is identified. Artifact httpclient and httpcore are not published to web-inf/lib, after copy them into the folder, the servlet class can be found.

shumagundam commented 6 years ago

Hi @TechSkieur ,

Where can you find httpclient and httpcore to copy?