Log4J - NoClassDefFoundError

S

systems_newbie

I'm trying to get Log4J up and working. My tomcat log says:

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.blah.db.xlsschemaparser.XlsSchemaParser.<clinit>(XlsSchemaParser.java:21)



The line of code that it's crapping out on (java:21) is as follows:

static Logger log =
Logger.getLogger(XlsSchemaParser.class.getName());



I understand that for some reason, it's not finding the Logger class
(I initially tried with Category class, but I found in the
documentation that this class is being deprecated in favor of the
Logger class), but I don't understand why. I have the log4j-1.2.8.jar
file in my classpath and I'm importing org.apache.log4j.*, but it's
still not recognizing the class. My IDE (eclipse) has no problem
recognizing the methods that are written for the Logger or the
Category class.

From reading the documentation, I believe that I have to include some
kind of PropertyConfigurator bit of code somewhere, but I'm unsure
where. I think it might have to go in the web.xml file under an
<init> param, but again, I'm unclear. Is that correct, or is it
something else? If this is correct, where in the file is it supposed
to go? What's the syntax supposed to look like?

If anybody could offer any suggestions, I would really appreciate it.
I've spent most this afternoon and part of last night trying different
ideas and reading documentation to no avail. Thanks in advance to all
who help!
 
J

Jose Rubio

Is the log4j.jar in the classpath of the webapp? Not the build path for
Eclipse, I mean when you deploy. It could go in the WEB-INF/lib of your
webapp or in Tomcat in the common/lib folder.

Jose
 
P

Paul Carey

I'm trying to get Log4J up and working. My tomcat log says:

java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.blah.db.xlsschemaparser.XlsSchemaParser.<clinit>(XlsSchemaParser.java:21)


From reading the documentation, I believe that I have to include some
kind of PropertyConfigurator bit of code somewhere, but I'm unsure
where.

A couple of things could be going wrong for you, but taking these
steps should help you out.

1. Ensure that the log4j.jar file is in $TOMCAT_HOME$/common/lib
For good measure you could also place the jar file in the WEB-INF/lib
directory of your own web app
(Just becuase Eclipse can find the jar file doesn't mean that Tomcat
can)
This much should get rid of the NoClassDefFoundError

2. Like you said, log4j does expect to do some PropertyConfiguration
based on a config file, but you can ignore that for the moment by
calling BasicConfigurator.configure();

public class TestLogger extends HttpServlet
{
public void doGet(...)
{
Logger logger = Logger.getLogger( TestLogger.class );
BasicConfigurator.configure();
logger.info( "logger works" );
}
}

3. Once you're happy that your app is logging correctly, take a look
at the section entitled Example Configurations on
http://jakarta.apache.org/log4j/docs/manual.html for examples on how
to specify the location of the log4j config file.

Good luck
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top