Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level - java

I am trying to run RestClient .From this code I deleted all Loggers related code.But I kept classpath for log4j same. Then run the application ,it gives following two exceptions
java.lang.NoClassDefFoundError: org/apache/log4j/Level
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Level
Please give reason for those exceptions.

Other jars that you use most likely will use log4j. Also, make sure you remove imports of log4j, not just the code that uses it.

Related

ESAPI - Getting Configuration exception in unit tests

We have upgraded the esapi version from 2.2.0.0 to 2.3.0.0 While we tried upgrading the same we are getting errors in the test cases
Exception: org.owasp.esapi.errors.configurationException at CanvasDAoUnitTest. java:90 Caused by: java.lang-reflect.InvocationTargetException at AdminGenericsDAOUnitTest. java: 90 Caused by: java.lang.ExceptionInInitializerError at AdminGenericCanvasDAOUnitTest. java:90 Caused by: org.owasp.asapi.errors.configurationException at AdminGenericUnitTest.java:90
And below are the properties which are maintained in the ESAPI.properties file please let us know if something needs to be added or removed in this file
ESAPI.printProperties,Encryptor.CipherTransformation,ESAPI.Encoder,Logger.LogApplicationName,Logger.LogServerIP,Logger.ApplicationName

NoClassDefFoundError error message in eclipse

I am running a program on eclipse and I keep getting this error:
Unable to initialize main class com.logic.AddProduct
Caused by: java.lang.NoClassDefFoundError: org/hibernate/Session
Any explainations?
Hibernate JAR (hibernate-core i suppose) or onr of its dependencies is probably not in your runtime classpath.

Why am I getting this error with JavaMail in IntelliJ?

I've been trying to send an email using the JavaMail API and Gmail SMTP. I am using IntelliJ IDEA Community Edition 2020.3.3. After following this tutorial and using this code (the one about Gmail SMTP with TLS), I keep getting the same error:
1st link - error
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
at mainPackage.JavaMailUtil.prepareMessage(JavaMailUtil.java:40)
at mainPackage.JavaMailUtil.sendMail(JavaMailUtil.java:28)
at mainPackage.JavaMail.main(JavaMail.java:5)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 3 more
2nd link - error
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
at lukemaster06.emailPackage.SendEmailTLS.main(SendEmailTLS.java:30)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
Since I'm fairly new to Java programming, I don't understand what I'm doing wrong. Thank you in advance for the help.
To see the IntelliJ IDEA projects, visit this GitHub page. If anything does wrong with them, let me know. You can also email me for more discussion-based conversations: public.lukemaster06#gmail.com
Which version of Java are you using? It's possible that since the DataHandler comes from JavaBeans Activation Framework you may not have it, since the last version of Java that included it was Java 1.8.
If that's the case you need to include this library in your project:
https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

MongoDB with java Exception in thread "main" java.lang.NoClassDefFoundError: org/bson/conversions/Bson

When I execute mycode from intelliJ Idea it works fine but when I run the jar on my server it throws the below error. I am using 'org.mongodb:mongodb-driver:3.4.1' version.
Exception in thread "main" java.lang.NoClassDefFoundError: org/bson/conversions/Bson
at com.myapp.server.mongo.MongoDbHandler.prepareMongoDb(MongoDbHandler.java:68)
at com.myapp.server.mongo.MongoDbHandler.<init>(MongoDbHandler.java:22)
at com.myapp.server.Client.main(Client.java:167)
Caused by: java.lang.ClassNotFoundException: org.bson.conversions.Bson
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
I know its an old thread and its just for those who have the similar issues. Few days back I was also facing the same issue with same error trace while running the jar by command line.After rechecking the code found that
It was not a problem of the jar version but its problem of the packaging of the
jar
After packing the jar with all proper dependencies will solve this issue.
I have used
maven-assembly-plugin
for packaging and its works.
.
If I had to guess you need to get yourself whatever BSON library you're using; I wouldn't say that Mongo is your problem.
key line here is:
"Caused by: java.lang.ClassNotFoundException: org.bson.conversions.Bson"
So it's saying that it's not finding that particular class, I would look in IntelliJ and see what BSON library it is, then put it in your build directory (or java lib) on your server.

Error in executing JAX-RPC

Help me on this exception , Occurs during calling wcf webservice
Log by netbeans
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:107)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy32.logon(Unknown Source)
at newtestclient.NewTestClient.main(NewTestClient.java:92)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.<clinit>(SOAPFaultBuilder.java:533)
... 5 more
Java Result: 1
The exception says :
java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext.
It's a common error that appears when there is a conflict between libraries and its dependencies. You should try to execute your code in a test project with only the libraries from JAX-RPC, and then add one by one the rest of your app libraries.
Also, you should check your server libraries to discard any kind of conflict for having the same library (or its dependencies) in your app and in your server with different versions.

Categories

Resources