Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
David Pardo
Messagelistener: java.lang.NoClassDefFoundError
March 3, 2012 8:37 AM
Answer

David Pardo

Rank: New Member

Posts: 5

Join Date: December 7, 2011

Recent Posts

Hi all I am trying to create a cron that will retrieve a certain twitter feed. Im counting on twitter4j to pull the data from twitter with the appropiate config. However im running in a strange problem.

Executing the following code in a simple java app works:

1  Twitter instance = new TwitterFactory().getInstance();
2        Iterator<Status> tweets = instance.getUserTimeline("liferay").iterator();
3        for (Iterator it = tweets; it.hasNext();) {
4            Status status = (Status) it.next();
5            System.out.println(status.getUser().getName() + " " + status.getText());
6        }


However when you place the above code in a message listener you receive a stacktrace:

 1public class TwitterJob implements MessageListener {
 2   
 3    private Log log = LogFactoryUtil.getLog("TwitterJob");
 4   
 5    @Override
 6    public void receive(Message message) throws MessageListenerException {
 7        Twitter instance = new TwitterFactory().getInstance();
 8        Iterator<Status> tweets;
 9        try {
10            tweets = instance.getUserTimeline("liferay").iterator();
11            for (Iterator it = tweets; it.hasNext();) {
12                Status status = (Status) it.next();
13                log.info(status.getUser().getName() + " " + status.getText());
14            }
15            //TODO Delegate to service builder
16        } catch (TwitterException ex) {
17            log.warn(ex);
18        }
19       
20    }
21}


  1Exception in thread "liferay/scheduler_dispatch-151" java.lang.NoClassDefFoundError: org/slf4j/spi/LoggerFactoryBinder
  2    at java.lang.ClassLoader.defineClass1(Native Method)
  3    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
  4    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
  5    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
  6    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2823)
  7    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1160)
  8    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1655)
  9    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
 10    at java.lang.Class.forName0(Native Method)
 11    at java.lang.Class.forName(Class.java:169)
 12    at twitter4j.internal.logging.Logger.<clinit>(Logger.java:48)
 13    at twitter4j.internal.http.HttpClientFactory.<clinit>(HttpClientFactory.java:30)
 14    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48)
 15    at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:87)
 16    at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:66)
 17    at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51)
 18    at twitter4j.TwitterFactory.getInstance(TwitterFactory.java:72)
 19    at com.liferay.aiao.twitter.cronjob.TwitterJob.receive(TwitterJob.java:30)
 20    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 21    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 22    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 23    at java.lang.reflect.Method.invoke(Method.java:597)
 24    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
 25    at $Proxy541.receive(Unknown Source)
 26    at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:75)
 27    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
 28    at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:106)
 29    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
 30    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
 31    at java.lang.Thread.run(Thread.java:619)
 32Caused by: java.lang.ClassNotFoundException: org.slf4j.spi.LoggerFactoryBinder
 33    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
 34    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
 35    ... 30 more
 36Exception in thread "liferay/scheduler_dispatch-150" java.lang.NoClassDefFoundError: Could not initialize class twitter4j.internal.http.HttpClientFactory
 37    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48)
 38    at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:87)
 39    at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:66)
 40    at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51)
 41    at twitter4j.TwitterFactory.getInstance(TwitterFactory.java:72)
 42    at com.liferay.aiao.twitter.cronjob.TwitterJob.receive(TwitterJob.java:30)
 43    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 44    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 45    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 46    at java.lang.reflect.Method.invoke(Method.java:597)
 47    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
 48    at $Proxy541.receive(Unknown Source)
 49    at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:75)
 50    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
 51    at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:106)
 52    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
 53    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
 54    at java.lang.Thread.run(Thread.java:619)
 55Exception in thread "liferay/scheduler_dispatch-155" java.lang.NoClassDefFoundError: Could not initialize class twitter4j.internal.http.HttpClientFactory
 56    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48)
 57    at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:87)
 58    at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:66)
 59    at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51)
 60    at twitter4j.TwitterFactory.getInstance(TwitterFactory.java:72)
 61    at com.liferay.aiao.twitter.cronjob.TwitterJob.receive(TwitterJob.java:30)
 62    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 63    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 64    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 65    at java.lang.reflect.Method.invoke(Method.java:597)
 66    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
 67    at $Proxy541.receive(Unknown Source)
 68    at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:75)
 69    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
 70    at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:106)
 71    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
 72    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
 73    at java.lang.Thread.run(Thread.java:619)
 74Exception in thread "liferay/scheduler_dispatch-157" java.lang.NoClassDefFoundError: Could not initialize class twitter4j.internal.http.HttpClientFactory
 75    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48)
 76    at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:87)
 77    at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:66)
 78    at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51)
 79    at twitter4j.TwitterFactory.getInstance(TwitterFactory.java:72)
 80    at com.liferay.aiao.twitter.cronjob.TwitterJob.receive(TwitterJob.java:30)
 81    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 82    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 83    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 84    at java.lang.reflect.Method.invoke(Method.java:597)
 85    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
 86    at $Proxy541.receive(Unknown Source)
 87    at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:75)
 88    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
 89    at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:106)
 90    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
 91    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
 92    at java.lang.Thread.run(Thread.java:619)
 93Exception in thread "liferay/scheduler_dispatch-158" java.lang.NoClassDefFoundError: Could not initialize class twitter4j.internal.http.HttpClientFactory
 94    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:48)
 95    at twitter4j.TwitterBaseImpl.init(TwitterBaseImpl.java:87)
 96    at twitter4j.TwitterBaseImpl.<init>(TwitterBaseImpl.java:66)
 97    at twitter4j.TwitterImpl.<init>(TwitterImpl.java:51)
 98    at twitter4j.TwitterFactory.getInstance(TwitterFactory.java:72)
 99    at com.liferay.aiao.twitter.cronjob.TwitterJob.receive(TwitterJob.java:30)
100    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
101    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
102    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
103    at java.lang.reflect.Method.invoke(Method.java:597)
104    at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:54)
105    at $Proxy541.receive(Unknown Source)
106    at com.liferay.portal.kernel.scheduler.messaging.SchedulerEventMessageListenerWrapper.receive(SchedulerEventMessageListenerWrapper.java:75)
107    at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
108    at com.liferay.portal.kernel.messaging.ParallelDestination$1.run(ParallelDestination.java:106)
109    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
110    at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
111    at java.lang.Thread.run(Thread.java:619)


I have tried adding the SLF4J lib to the path but this results in a multiple binding error conflict with the java-taglib.jar .

Anyone have an idea why this library is not found? Is there a conventions I am missing?
Jan Geißler
RE: Messagelistener: java.lang.NoClassDefFoundError
March 4, 2012 2:25 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

Have you tried switching the log.info(status.getUser().getName() + " " + status.getText());
to a system out and remove the logger?

Does this solve the Problem? If so, try to use

com.liferay.portal.kernel.log.Log;
com.liferay.portal.kernel.log.LogFactoryUtil;
instead of
org.slf4j.log

Another question:
Is twitter4j depending on slf4j?
David Pardo
RE: Messagelistener: java.lang.NoClassDefFoundError
March 4, 2012 2:05 PM
Answer

David Pardo

Rank: New Member

Posts: 5

Join Date: December 7, 2011

Recent Posts

Thanks Jan for answering.

After doing some research I concluded the error is not Liferay related.
It appeared that (I am using maven for this project) the librairies where available at compile time but not at run time.
This followed by the fact that twitter4j did not play nice with Java 1.5-1.7. So replaced twitter4j with Spring Social and all just works now emoticon
Smilelws2010 lwz
RE: Messagelistener: java.lang.NoClassDefFoundError
July 16, 2012 9:40 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

HI David,

So how did you get rid of the classnotfound exception or what is the normal way to get rid of it.

I have a twitter4j portlet which works fine in 6.0 and 5.2 but it just throws out an exception when trying to do on 6.1

17:37:00,687 ERROR [PortletServlet:97] javax.portlet.PortletException: org.apache.jasper.JasperException: An exception occurred processing JSP page /view.jsp at line 22

19:
20: <!-- <ol> -->
21: <%
22: List<String> tweets = twitterPortlet.getRecentTweet();
23: if (tweets.isEmpty()==false) {
24: for(String nextTweet : tweets){
25: %>


... 214 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.spi.LoggerFactoryBinder

Help needed

Smile
David H Nebinger
RE: Messagelistener: java.lang.NoClassDefFoundError
July 16, 2012 9:41 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11060

Join Date: September 1, 2006

Recent Posts

Add the slf4j jars to the liferay-plugin-package.properties file as dependent jars.
Smilelws2010 lwz
RE: Messagelistener: java.lang.NoClassDefFoundError
July 16, 2012 11:57 AM
Answer

Smilelws2010 lwz

Rank: Regular Member

Posts: 160

Join Date: December 16, 2010

Recent Posts

Thanks David.

It did resolve the issue. emoticon