![]() |
|
|
|
#1 |
|
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.<clini t>(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! systems_newbie |
|
|
|
|
#2 |
|
Posts: n/a
|
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 "systems_newbie" <> wrote in message news: m... > 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.<clini t>(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! Jose Rubio |
|
|
|
#3 |
|
Posts: n/a
|
(systems_newbie) wrote in message news:< om>...
> 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.<clini t>(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 Paul Carey |
|