Spring project getting exceptions - java

I have tried a spring(3.1.0) project for the first time,but it gives me runtime errors.I have added log4j but still error occurs.and the org.springframework.beans.factory.xml.XmlBeanFactory is deprecated too.
please help me
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.<init>(DefaultSingletonBeanRegistry.java:83)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.<init>(FactoryBeanRegistrySupport.java:43)
at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:175)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:168)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:158)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:77)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66)
at com.vehicle.SpringDemoApp.main(SpringDemoApp.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 9 more<br/>
this is what i got

You need apache commons-logging in the classpath. Log4j is not commons-logging.

download commons logging jar from
http://commons.apache.org/logging/download_logging.cgi

You can check which class is in which Opensource (OSS) library here.
If you are using Maven, you can try adding the following dependency:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<classifier>api</classifier>
</dependency>

Related

Intellij Dependency Issue - java.lang.NoClassDefFoundError

I have started using IntelliJ for my projects recently. I was trying to develop a simple maven project and got stuck into issue. I was trying to play around with kakfa-clients. Here is my dependencies
<dependencies>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
I tried doing maven clean and install. I see the following error after I execute the code.
C:\KB\SDA>java -cp target/SDA-1.0-SNAPSHOT.jar org.example.code.Demo
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/clients/producer/Producer
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.clients.producer.Producer
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
However I could see the kafka-clients:2.5.0 is available in the External Libraries folder
I would like to know what could have gone wrong. Any hint would definitely help.
Java version 8
IntellJ 2020.1
Kafka-Client itself is dependent on other dependencies. Have a look here https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients/2.5.0
Give a shot by including other jars in the classpath.
java -cp target/*.jar:. org.example.code.Demo

Getting error in JCommander, java.lang.NoClassDefFoundError in java

Hey I am getting following complete error on my console, while trying to run my project.
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/JCommander
at ro.uaic.info.VRPRunner.main(VRPRunner.java:42)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.JCommander
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
I have added jcommander dependency in pom.xml file
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
</dependencies>
Can you help me what should i do to resolve this error?

Read a xlsx file using apache poi in java? not working

I have used all poi jars but still i ame getting this error
Exception in thread "main" org.apache.poi.POIXMLException:
java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:271)
at ReadExcel.readXLSXFile(ReadExcel.java:38)
at ReadExcel.main(ReadExcel.java:69)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/POIXMLTypeLoader
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown
Source)
at org.apache.poi.xssf.model.ThemesTable.(ThemesTable.java:46)
... 10 more
Caused by: java.lang.ClassNotFoundException: org.apache.poi.POIXMLTypeLoader
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more
Sounds like you do not have the correct dependencies in you project.
POIXMLTypeLoader comes with POI 3.14-Beta1 and the ooxml-schemas:1.3 reference that class.You have the following options, you can add any of this dependency in your project:
use poi 3.14 beta1
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
use ooxml-schemas 1.2
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.14</version>
</dependency>

How to resolve this JNI error when trying to run LWJGL "Hello World"?

I'm trying to run the sample "Hello World" from the LWJGL website
From this link: LWJGL "Getting Started"
I'm trying to do this via the command line, just so I understand the "behind the scenes" a bit better.
I've managed to compile without any errors, but when I try to run the program I'm getting this error:
C:\JavaProjects\LearningLWJGL>java -classpath .;./lib/*.jar -Djava.library.path=C:\Windows\System32 HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/glfw/GLFWKeyCallback
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetMethodRecursive(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.lwjgl.glfw.GLFWKeyCallback
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
Any ideas?
A CLASSPATH entry is either a directory at the head of a package hierarchy of .class files, or a .jar file. If you're expecting ./lib to include all the .jar files in that directory, it won't. You have to name them explicitly.
I had same issue using different dependancy what helped me is to set scope to compile.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>

NoClassDefFoundError: com/google/appengine/api/urlfetch/ResponseTooLargeException

I am using Google + API to search for people using the following statement.
Plus plus = new Plus.Builder(httpTransport, jsonFactory, null).
setApplicationName("AppName").setGoogleClientRequestInitializer(new
PlusRequestInitializer(API_KEY)).build();
Plus.People.Search searchPeople = plus.people().search(personName).setMaxResults(1L);
PeopleFeed peopleFeed = searchPeople.execute();
I put the dependencies for the library in pom.xml so that it can be build when maven executed
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-plus</artifactId>
<version>v1-rev64-1.13.2-beta</version>
</dependency>
But I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/appengine/api/urlfetch/ResponseTooLargeException
at com.google.api.client.extensions.appengine.http.urlfetch.UrlFetchTransport.buildGetRequest(UrlFetchTransport.java:61)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:867)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:399)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:328)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:449)
at com.google.PeopleSearch.googleAccountSearch(PeopleSearch.java:52)
at com.google.Search.main(Search.java:128)
Caused by: java.lang.ClassNotFoundException: com.google.appengine.api.urlfetch.ResponseTooLargeException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Any suggestions?
I had a similar error NoClassDefFoundError: com/google/appengine/api/urlfetch/HTTPMethod , for me it was resolved by copying the App Engine SDK jar file from SDK/lib/user/appengine-api-1.0-sdk-1.9.27.jar into my project's WEB-INF/lib folder (I was not using Maven).

Categories

Resources