Java JSON Jar NoClassDefFound Caused by ClassNotFoundException - java

I have a simple java file packaged as a Jar on a server called by a PHP script. I have the "json-simple-1.1.1" library included in my java program. However, when I run it gives me the below error. I've added the json-simple jar to my project and import the correct classes. From what I've read it doesn't seem to be adding the json-simple library to my manifest file. Any ideas on how to fix this. I'm using eclipse if that helps.
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getMethod0(Class.java:2813)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

Your library is probably not been loaded by classloader, so, if it is not in WEB-INF/lib, right click it and Add to build Path.

Related

Thrift server/client with Eclipse NoClassDefFoundError

http://wiki.apache.org/thrift/Thrift%20%26%20Eclipse%20%26%20JUnit%20with%20TServlet
I followed this tutorial step by step until the part where they execute the client and the server. For the serverExample.java I added these imports.
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
For the clientExample.java I added these imports:
import org.apache.thrift.TException;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.protocol.TBinaryProtocol;
When I run the server I get these errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.thrift.transport.TServerSocket.<clinit>(TServerSocket.java:37)
at example.ServerExample.run(ServerExample.java:14)
at java.lang.Thread.run(Thread.java:745)
at example.ServerExample.main(ServerExample.java:25)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 4 more
When I run the client I get these errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.thrift.transport.TIOStreamTransport.<clinit>(TIOStreamTransport.java:38)
at example.ClientExample.main(ClientExample.java:15)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Just in case, I already added the eclipse thrift plugin. If someone could help me that would be awesome.
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
explains everything I guess.. Just add slf4j dependency
You re missing the slf4j.jar library or the library is mot in the classpath.
download the lastest jar from maven and update it to your class path
Adding the library did not solve the problem. I installed Linux, Thrift and Eclipse all over again and it solved it. Thanks for your answers!

ClassNotFoundException error in running Hadoop jar file

I am getting the following error running a hadoop jar file
Exception in thread "main" java.lang.ClassNotFoundException: hdfs:
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at org.apache.hadoop.util.RunJar.main(RunJar.java:205)
The jar file that you want to run must be the actual path in your OS.
Add the hdfs jar file in your build path or pom.xml file

hibernate java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer

When I tried to build my first hibernate application the following error occurs NoClassDefFoundError
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/analysis/standard/StandardAnalyzer
at org.hibernate.search.impl.ConfigContext.initAnalyzer(ConfigContext.java:168)
at org.hibernate.search.impl.ConfigContext.<init>(ConfigContext.java:104)
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:312)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:218)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:143)
at org.hibernate.search.hcore.impl.HibernateSearchSessionFactoryObserver.sessionFactoryCreated(HibernateSearchSessionFactoryObserver.java:74)
at org.hibernate.internal.SessionFactoryObserverChain.sessionFactoryCreated(SessionFactoryObserverChain.java:52)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:587)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at com.TestHibrnt.main(TestHibrnt.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.analysis.standard.StandardAnalyzer
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 11 more
Required jar containing org/apache/lucene/analysis/standard/StandardAnalyzer is missing so you have to download jar(lucene-1.2.jar) and then set your classpath
I had the same problem today. When I check the error, I found org.hibernate.search on several lines, even though I'm just using the Hibernate ORM. Then I removed the build path of Hibernate Search and no more error. Check if you have the same path and if you don't need it, just remove it.

Creating a server using QuickServer

I am following this tutorial:
https://code.google.com/p/quickserver/wiki/QuickStartTutor
but when I execute java -jar QuickServer.jar -load HelloWorld.xml
I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool/PoolableObjectFactory at
java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2531) at
java.lang.Class.getMethod0(Class.java:2774) at
java.lang.Class.getMethod(Class.java:1663) at
sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at
sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException:
org.apache.commons.pool.PoolableObjectFactory at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 6 more
How can I solve that?
The exception exactly says your problem: that class cannot be found on the application classpath, hence the ClassNotFoundException.
You need to put all the dependent jars onto the application classpath. In this exact exception, the commons-pool.jar Apache library is missing.
The developers guide states, that the Digester and Pool Jakarta Commons Components are dependencies of QuickServer.
It sounds like you are executing this from a folder that does not also have the supporting jars. Ie, the following files must be in the same folder as QuickServer.jar as well:
commons-digester.jar
commons-collections.jar
commons-beanutils.jar
commons-logging.jar
commons-pool.jar

Adding multiple jar files into classpath

I am trying to add all the jar files in the directory below but I get
Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException error.
I am sure there is TwitterException class inside the .jar file. Is there any error in my classpath syntax ?
mahmut#ubuntu:~/Desktop/Java/TwitterDeneme/bin$ java -classpath "~/twitter4j-2.2.6/lib/*.jar:." GetHashtag
Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/TwitterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
I am using ubuntu and jdk 1.7. I tried the same command in windows and it works flawlessly. Is there anything special to do related to Ubuntu OS?
The * syntax for classpaths is rather limited. Try:
java -classpath "~/twitter4j-2.2.6/lib/*:." GetHashtag

Categories