NoClassDefFoundError

971 views
Skip to first unread message

Bert Brecht

unread,
Jun 24, 2016, 2:16:07 PM6/24/16
to AdWords API Forum
Hi,

I started to develop an application using the adwords api. I managed everything so far (test accounts, oauth2 ...) and have my auth and refresh token. Now I'm trying to get the customer id (to see, whether the service works or not):

    private static AdWordsSession createAdWordsSession(String clientId, String clientSecret,
            String refreshToken, String developerToken, String userAgent) throws OAuthException,
            ValidationException {
        // Create a valid OAuth2 credential without using a properties file.
        Credential credential = new OfflineCredentials.Builder()
                .forApi(Api.ADWORDS)
                .withClientSecrets(clientId, clientSecret)
                .withRefreshToken(refreshToken)
                .build()
                .generateCredential();

        // Create a new AdWordsSession without using a properties file.
        return new AdWordsSession.Builder()
                .withDeveloperToken(developerToken)
                .withUserAgent(userAgent)
                .withOAuth2Credential(credential)
                .build();
    }

and running into the following exception:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.api.ads.common.lib.auth.OfflineCredentials$Api
at com.xx.web.GoogleAuth.createAdWordsSession(GoogleAuth.java:137)
at com.xx.web.GoogleAuth.getCampaigns(GoogleAuth.java:122)
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:483)
at javax.el.ELUtil.invokeMethod(ELUtil.java:332)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
... 36 more

Im using the latest API 2.16. Any idea, why?

TIA,
Bert

Shwetha Vastrad (AdWords API Team)

unread,
Jun 24, 2016, 3:46:01 PM6/24/16
to AdWords API Forum
Hi Bert,

Could you check if you have provided all the essential dependencies in the (runtime) classpath? Could you also provide the complete stack trace so I can further investigate? Instructions for setting up the AdWords API Java Client library are available here

Regards,
Shwetha, AdWords API Team.

Bert Brecht

unread,
Jun 28, 2016, 2:41:01 AM6/28/16
to AdWords API Forum
Thanks a lot for your reply.

The classpath is fine. I found out, the java API does not work in a JavaEE environment. It seems to clash with the existing dependency injection in Glassfish 4.1.1. Is it possible to get an API based on JAX-WS only?

brgds,
Bert

You'll find the stacktrace below:

javax.servlet.ServletException: java.lang.ExceptionInInitializerError

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)

at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)

at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)

at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)

at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)

at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)

at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)

at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)

at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)

at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)

at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)

at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)

at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)

at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)

at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)

at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)

at java.lang.Thread.run(Thread.java:744)

Caused by: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError

at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)

at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)

at javax.faces.component.UICommand.broadcast(UICommand.java:315)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)

at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)

... 28 more

Caused by: java.lang.ExceptionInInitializerError

at com.google.api.ads.common.lib.auth.OfflineCredentials$Api.<clinit>(OfflineCredentials.java:66)

at com.xxx.web.GoogleAuth.createAdWordsSession(GoogleAuth.java:137)

at com.xxx.web.GoogleAuth.getCampaigns(GoogleAuth.java:122)

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:483)

at javax.el.ELUtil.invokeMethod(ELUtil.java:332)

at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)

at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)

at com.sun.el.parser.AstValue.invoke(AstValue.java:283)

at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)

at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)

at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)

at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)

at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)

... 36 more

Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:


1) Error injecting constructor, java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;

 at com.google.api.ads.common.lib.utils.AdsUtilityRegistry.<init>(AdsUtilityRegistry.java:31)

 at com.google.api.ads.common.lib.utils.AdsUtilityRegistry.class(AdsUtilityRegistry.java:31)

 while locating com.google.api.ads.common.lib.utils.AdsUtilityRegistry

   for parameter 6 at com.google.api.ads.adwords.lib.utils.AdWordsInternals.<init>(AdWordsInternals.java:48)

 while locating com.google.api.ads.adwords.lib.utils.AdWordsInternals


1 error

at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)

at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)

at com.google.api.ads.adwords.lib.utils.AdWordsInternals.<clinit>(AdWordsInternals.java:37)

... 52 more

Caused by: java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;

at com.google.api.ads.common.lib.utils.AdsUtilityRegistry.<init>(AdsUtilityRegistry.java:33)

at com.google.api.ads.common.lib.utils.AdsUtilityRegistry$$FastClassByGuice$$20ddab28.newInstance(<generated>)

at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)

at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)

at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)

at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)

at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)

at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)

at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)

at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)

at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)

at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)

at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)

at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)

at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)

at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)

at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)

at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)

at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)

at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)

... 54 more

Shwetha Vastrad (AdWords API Team)

unread,
Jun 28, 2016, 12:01:46 PM6/28/16
to AdWords API Forum
Hi Bert,

The adwords-appengine Maven module uses JAX-WS instead of axis. I would recommend that you use this instead of adwords-axis. 

Bert Brecht

unread,
Jun 29, 2016, 11:36:57 AM6/29/16
to AdWords API Forum
Thanks a lot for your reply! Unfortunately, it does not help us, as for example servlet 2.5 is dependency of it. We managed already to import the WSDLs and we try to figure out now, how we have to build our requests. We can set the soapHeader but something seems to be still missing:

            Holder<SoapResponseHeader> holder = new Holder();
            SoapHeader soapHeader = new SoapHeader();
            soapHeader.setValidateOnly(Boolean.TRUE);
            soapHeader.setDeveloperToken("my-dev-token");
            soapHeader.setClientCustomerId("my-client-id");
            Customer customer = customerService.getCustomerServiceInterfacePort().get(soapHeader, holder);

Is there a plain XML dump of a valid SOAP request available to compare, what we are still missing?

TIA,
Bert

Shwetha Vastrad (AdWords API Team)

unread,
Jun 29, 2016, 3:56:11 PM6/29/16
to AdWords API Forum
Hi Bert,

A sample SOAP request for an API call to add a Budget is provided here. I think you are missing the UserAgent field in the SOAP header. 
Reply all
Reply to author
Forward
0 new messages