Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis.utils.XMLUtils

Tags:

java

tomcat

java.lang.NoClassDefFoundError: Could not initialize class org.apache.axis.utils.XMLUtils

I am getting this error. How to avoid this exception. Please suggest me a solution.

like image 543
akshay Avatar asked Oct 20 '22 17:10

akshay


1 Answers

According to Oracle:

NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

In simple language, it means "At compile-time class was there but at run-time, it failed to find/load the class

Question comes : How come my code compile?

Answer maybe because you added jars using Eclipse. But Eclipse does not actually move those jars into you classpath.It just uses those referenced jars while compilation. So your code compiles fine.
After, you move your project to tomcat, when it tries to load some class inside those 'jars', it fails to find the class,because you never moved those jars to the classpath.

Solution:
Move all the libraries(jars) into your project's /WEB-INF/lib. Now all the libraries/jars under /WEB-INF/lib will come under classpath.

You can read more on Oracle's Docs & this article

like image 139
Aman Arora Avatar answered Oct 23 '22 10:10

Aman Arora