Bootstrap FreeKB - Tomcat - Resolve "ClassNotFoundException"
Tomcat - Resolve "ClassNotFoundException"

Updated:   |  Tomcat articles

ClassNotFoundException occurs, as you may have guessed, when a class cannot be found. For example, something like this may be returned.

java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference

 


JAR files |  Search for the class

If an application is getting ClassNotFoundException, you will first need to determine how the classes in the JAR file are being made available to the Java application. The classes in a JAR file can be made available to a Java application running in a Tomcat application server in the following ways.

  • The JAR file can be placed in the applications WEB-INF/lib folder
  • The JAR file can be placed in the <base Tomcat directory/lib directory

 

Search for the class

On a Linux system, the following command can be used to find all of the files ending in .jar below the applications WEB-INF/lib directory, and to then use the Java jar command to check each JAR file for the class that is not found, and to print the results to files.txt.

files=$(find </path/to/WEB-INF/lib directory> | grep -i [A-Za-z0-9].jar$); for file in $files; do echo $file | tee -a files.txt; jar -tf $file | grep -i 'your class name here' | tee -a files.txt; done;

 

And you will probably want to also search the <base Tomcat directory/lib directory.

 

files=$(find <base Tomcat directory>/lib | grep -i [A-Za-z0-9].jar$); for file in $files; do echo $file | tee -a files.txt; jar -tf $file | grep -i 'your class name here' | tee -a files.txt; done;



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 54345c in the box below so that we can be sure you are a human.