NoClassDefFoundError when starting job in Karaf

i am experiencing some issues when i want to call a job from Karaf. When I run it in Talen Open Studio it works fine.

I have one parent job which handles a POST request and then starts a child job which executes a POST with a tRESTClient component.

The parent job looks as follows:

And this is the design of the child job:

I used a simple API for testing the tRestClient:

As I already mentioned running this job in Open Studio works fine. The problem occurs when I deploy it in Karaf. I get this exception:

Exception in component tRunJob_1 (RestRequestParent)
java.lang.RuntimeException: java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean
at local_project.restrequestparent_0_1.RestRequestParent.tRESTRequest_1_LoopProcess(RestRequestParent.java:2145)
at local_project.restrequestparent_0_1.RestRequestParent$RestServiceProviderImpl4TalendJob.processRequest(RestRequestParent.java:391)
at local_project.restrequestparent_0_1.RestRequestParent$RestServiceProviderImpl4TalendJob.path1(RestRequestParent.java:479)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:192)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:103)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1182)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1116)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
at org.eclipse.jetty.server.Server.handle(Server.java:534)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:333)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:283)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:108)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean
at local_project.restrequestparent_0_1.RestRequestParent.tRESTRequest_1_LoopProcess(RestRequestParent.java:1638)
... 34 more
Caused by: java.lang.ClassNotFoundException: org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean cannot be found by local_project.RestRequestParent_0.1.0
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 35 more

Any idea how this can be solved? I am using version 7.0.1 and Java 1.8 by the way.

Re: NoClassDefFoundError when starting job in Karaf

Hi,

thank you very much for your help.

These are my initial settings for tRunJob.

I didn't check "Use an independent process to run subjob" which resulted in this NoClassDefFoundError.

However, I also tried to build this job with this option enabled and got the same result that is also described in your article and in the Jira issue: the child job returns 1 and the main class could not be found.

Now do I understand this correctly that this is currently a bug in Talend Open Studio and cannot be solved?

Re: NoClassDefFoundError when starting job in Karaf

Hi @Basit,Apparently, this has something to do with class loading config in v7. I compiled an OSGi bundle of the same job from Talend 6.4.1 and put it in the Talend 7 container. It worked.Unfortunately, you can't import project made with 7 in 6. I migrated from 6 and fortunately, I had the project archived under version control.Maybe someone could find a workaround, probably editing pom files, but for now, I'll stay with Talend 6.