How to fix ClassNotFoundException: org.apache.commons.logging.LogFactory? - java

When i run the app it getting exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.hibernate.dialect.Dialect.<clinit>(Dialect.java:58)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 1 more
I have put all the jar files in lib folder.
I don't know how to solve this, where is my mistake.

Add this in your pom file:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>

It works for me after adding this jar file
commons-logging-1.2.jar
You can download it from here.

Include hibernate jar files (especially the required jars) in your lib folder
antlr-2.7.7.jar
commons-collections-3.2.1.jar
dom4j-1.6.1.jar
javassist-3.12.1.GA.jar
hibernate-core-4.0.1.Final.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
jboss-logging-3.1.0.CR2.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar

I had a similar problem: In my project the solution was to add the following jars of org.apache.commons:
commons-logging-1.2
commons-dbcp2-2.1.1
commons-pool2-2.4.2

For me problem solved post download & adding jar "commons-logging-1.2.jar"

Related

java.lang.NoClassDefFoundError while using SourceAFIS in my Java Application using Maven [duplicate]

I am trying simple Maven app with Log4J ver 2-beta 9. In my pom.xml file I have these two dependencies (as is mentioned in Log4J Maven webpage):
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0-beta9</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0-beta9</version>
</dependency>
Eclipse sees Log4J library:
But when I package the app and run it this Exception is thrown:
java -cp target/notification-1.0.0.jar com.example.Sandbox
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/LogManager
at com.example.Sandbox.<clinit>(Sandbox.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.LogManager
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)
... 1 more
I searched for this Exception and it seems to be related to CLASSPATH variable.
How should be CLASSPATH set for Maven project?
Maven is a build tool. It doesn't help you much running the final application.
You can use mvn exec:java -Dexec.mainClass="com.example.Sandbox" to run your app (see the question Maven Run Project) but this gets tedious when you have to pass arguments to it.
You can get the classpath that Maven used to compile your application with mvn dependency:build-classpath
That will print the classpath to the console. Note that it will be missing target/notification-1.0.0.jar
Another useful tool in this area is the assembly plugin; it will create one very big JAR with all the dependencies rolled into a single file when you specify the descriptor jar-with-dependencies.

Axiom throwing error for Axis2 generated WSDL

I have auto generated classes from a WSDL file using Axis2 wsdl2java script. After adding the generated Java files to a Maven project the dependencies were only axis2-adb and axis2-kernel. However during runtime it is throwing the following:
Caused by: java.lang.ClassNotFoundException: org.apache.axiom.util.UIDGenerator
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
and
Caused by: java.lang.NoClassDefFoundError: org/apache/axiom/util/UIDGenerator
at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:90)
at org.apache.axis2.description.AxisOperation.<init>(AxisOperation.java:95)
at org.apache.axis2.description.TwoChannelAxisOperation.<init>(TwoChannelAxisOperation.java:52)
at org.apache.axis2.description.OutInAxisOperation.<init>(OutInAxisOperation.java:65)
at org.apache.axis2.description.RobustOutOnlyAxisOperation.<init>(RobustOutOnlyAxisOperation.java:47)
at org.apache.axis2.client.Stub.addAnonymousOperations(Stub.java:233)
at com.tobeprecise.sms.webservices.HttpReceiverStub.populateAxisService(HttpReceiverStub.java:42)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:184)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:173)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:222)
at com.tobeprecise.sms.webservices.HttpReceiverStub.<init>(HttpReceiverStub.java:214)
at in.capillary.nsadmin.gateway.tobeprecisebulk.TobepreciseBulkGatewayChannel.sendMessages(TobepreciseBulkGatewayChannel.java:122)
at in.capillary.nsadmin.gateway.BufferedGatewayChannelProcessor.process(BufferedGatewayChannelProcessor.java:150)
at in.capillary.nsadmin.gateway.BaseGateway.process(BaseGateway.java:207)
at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
... 18 more
While looking at the dependencies I have found the axiom-api-1.2.11 as a dependency and it very well contains the UIDGenerator class. Is this due to version mismatch?
Found a similar issue ClassNotFoundException axiom-api-1.2.7.jar but I coudn't make much sense out of it(my manifest file: http://pastebin.com/n4jKWPck). Any help?

How to use Goose in Java Project

How can i use Goose on a java project? I tested the online version of both boilerpipe and goose, and the last one it's way better but now it's developed in Scala.
I searched for the jar of previous version but can't find it (neither api). The last .jar i tried it's: goose-2.1.22. I imported it in my Ecplise project and tried with this code:
String url = "http://www.cnn.com/2010/POLITICS/08/13/democrats.social.security/index.html";
Goose goose = new Goose(new Configuration());
Article article = goose.extractContent(url);
System.out.println(article.cleanedArticleText());
But i get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at daweb.main(daweb.java:212)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 13 more
Is it possible to use Goose without Scala?
You should add Scala Library to your buildpath
There is a link provided in the issues page where you can find a .jar compiled for java use.
https://github.com/GravityLabs/goose/issues
import com.gravity.goose.*;
String url = "http://www.straitstimes.com/little-india-riot";
Goose goose = new Goose(new Configuration());
Article article = goose.extractContent(url);
System.out.println(article.cleanedArticleText());
This code works as a start.
If you're managing your dependencies with Maven, you can just add Goose to the dependencies section of your pom.xml and all of it's transitive dependencies will end up on the class path.
<dependency>
<groupId>com.gravity</groupId>
<artifactId>goose</artifactId>
<version>2.1.22</version>
</dependency>
You should add scala-library jar to your classpath. If you are using Maven, add this dependency to your project:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.4</version>
</dependency>

Can't Export runnable jar from eclipse

i'm trying to export a runnable jar from eclipse, but this is the result:
Exception in thread "main" java.lang.NoClassDefFoundError: neg1
Caused by: java.lang.ClassNotFoundException: neg1
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
This is the manifest:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ itextpdf-5.4.3.jar itext-pdfa-5.4.3.jar itext-xtra
-5.4.3.jar
Class-Path: .
Rsrc-Main-Class: Negozio.Start
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
And this is how the files are packed into the jar:
http://i.stack.imgur.com/uXEaQ.png
Where Operazioni and Negozio are the my packages and the itext are the external library
Did you forget to include an external jar file?
You must have external jars that you did not include when you exported or were not put in your class path. Right click on your project Properties->Java Build Path and then ensure the "Libraries" tab is selected. Ensure the jars are added here.

Java Errors starting from ClassNotFoundException

I have the following errors when i try to run my Netbeans aplication of a map reduce algorithm:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
at org.apache.hadoop.mapred.JobConf.<clinit>(JobConf.java:349)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1121)
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:88)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:72)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:125)
at org.apache.hadoop.security.Groups.<init>(Groups.java:54)
at org.apache.hadoop.security.Groups.getUserToGroupsMappingService(Groups.java:142)
at
org.apache.hadoop.security.UserGroupInformation.initUGI(UserGroupInformation.java:243)
at
org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation
.java:216)
at
org.apache.hadoop.security.UserGroupInformation.ensureInitialized(UserGroupInformation
.java:207)
at
org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled(UserGroup
Information.java:286)
at org.apache.hadoop.security.UserGroupInformation.getLoginUser(UserGroup
Information.java:500)
at org.apache.hadoop.security.UserGroupInformation.getCurrentUser(UserGroup
Information.java:483)
at org.apache.hadoop.mapreduce.Cluster.<init>(Cluster.java:73)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:133)
at org.apache.hadoop.mapreduce.Job.<init>(Job.java:138)
at cloudex.CloudEx.main(CloudEx.java:33)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
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)
... 19 more
Could you please give me a hint on how to get rid of it? i do not know what it generates it
You need to add the log4j jar to your classpath.
Either add the log4j class to your classpath as #smcg has stated, or add the following into your project pom.xml if you're using maven.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
Download Apache log4j *.jar file at log4j. Import external *.jar file to your project.

Categories

Resources