can't find class file

Discussion in 'Java' started by Peter, Dec 6, 2004.

  1. Peter

    Peter Guest

    Hi all,

    I am trying to log servlet messages but can't get this code to
    compile,

    package app.web;
    import java.io.*;
    import java.io.IOException;
    import java.util.Hashtable;
    import java.util.Locale;
    import javax.servlet.*;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpSession;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionServlet;
    import org.apache.struts.util.MessageResources;

    public final class LogonAction extends Action {

    public ActionForward perform(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

    String username = ((LogonForm) form).getUsername();
    String password = ((LogonForm) form).getPassword();

    HttpSession session = request.getSession();
    session.setAttribute(Constants.USER_KEY, form);

    if (servlet.getDebug() >= 1)
    servlet.log("LogonAction: User '" + username +
    "' logged on in session " + session.getId());

    // Forward control to the success URI specified in struts-config.xml
    return (mapping.findForward("success"));
    }
    }


    This is the line I use to compile,
    javac -verbose -classpath
    $CATALINA_HOME/common/lib/servlet-api.jar:classes:. LogonAction.java
    -d $CATALINA_HOME/webapps/Ey/WEB-INF/classes

    I also tried,
    javac -verbose -classpath opt/struts/lib/struts.jar:classes:.
    LogonAction.java -d $CATALINA_HOME/webapps/Ey/WEB-INF/classes

    The error is,
    LogonAction.java:67: cannot find symbol
    symbol : method getDebug()
    location: class org.apache.struts.action.ActionServlet
    If (servlet.getDebug () <=1)

    I even tried unzipping the struts.jar file in the directory I am
    compiling from.

    I am at wits end and really appreciate your help..


    Thank you greatly,
    Jim
    Peter, Dec 6, 2004
    #1
    1. Advertising

  2. Peter

    Ryan Stewart Guest

    "Peter" <> wrote in message
    news:...
    > Hi all,
    >
    > I am trying to log servlet messages but can't get this code to
    > compile,

    [...]
    > The error is,
    > LogonAction.java:67: cannot find symbol
    > symbol : method getDebug()
    > location: class org.apache.struts.action.ActionServlet
    > If (servlet.getDebug () <=1)
    >
    > I even tried unzipping the struts.jar file in the directory I am
    > compiling from.
    >
    > I am at wits end and really appreciate your help..
    >

    The problem has nothing to do with not finding the class. On the contrary,
    it's finding that just fine. The problem is that there's no "getDebug()"
    method in Struts' ActionServlet. What led you to believe that there was?
    Ryan Stewart, Dec 6, 2004
    #2
    1. Advertising

  3. Peter

    zpetero Guest

    I knew it was deprecated,

    http://www.porcupyne.org/docs/struts1.1/deprecated-list.html

    but I still use other deprecated methods and they work.

    What replaced it?

    Peter


    Ryan Stewart wrote:
    > "Peter" <> wrote in message
    > news:...
    > > Hi all,
    > >
    > > I am trying to log servlet messages but can't get this code to
    > > compile,

    > [...]
    > > The error is,
    > > LogonAction.java:67: cannot find symbol
    > > symbol : method getDebug()
    > > location: class org.apache.struts.action.ActionServlet
    > > If (servlet.getDebug () <=1)
    > >
    > > I even tried unzipping the struts.jar file in the directory I am
    > > compiling from.
    > >
    > > I am at wits end and really appreciate your help..
    > >

    > The problem has nothing to do with not finding the class. On the

    contrary,
    > it's finding that just fine. The problem is that there's no

    "getDebug()"
    > method in Struts' ActionServlet. What led you to believe that there

    was?
    zpetero, Dec 6, 2004
    #3
  4. zpetero wrote:
    > I knew it was deprecated,
    >
    > http://www.porcupyne.org/docs/struts1.1/deprecated-list.html
    >
    > but I still use other deprecated methods and they work.


    Well, you shouldn't. "Deprecated" really does mean that the element
    in question might be removed entirely in the next version. The Sun people
    are extremely reluctant about doing that in the standard API (I think it
    has never actually happened), the Struts team apparently not.

    > What replaced it?


    It says right there in the URL you cited:

    "Deprecated. Configure the logging detail level in your underlying logging implementation"
    Michael Borgwardt, Dec 6, 2004
    #4
  5. Peter

    zpetero Guest

    I got that and have since set up and tested Log4j,

    The tricky part is getting it to output to the file I want.

    Would you by chance know to set it up to send logging info to a file?

    I have this class as part of a web app,

    package app.model;

    //import java.util.*;
    import org.apache.log4j.Logger;
    import org.apache.log4j.BasicConfigurator;

    public class Log4j {

    static Logger logger = Logger.getLogger(Log4j.class);

    // debug, info, warn, error, fatal

    public String logMessage(String sText, String level) {

    BasicConfigurator.configure();

    if (level.equals("debug")) {
    logger.debug(sText);
    }

    if (level.equals("info")) {
    logger.info(sText);
    }


    return("yes") ;
    }
    }

    ....and I modified the original LogonAction.java file with this(instead
    of getDegug())

    String sText ="LogonAction: User " + username + " logged on in
    session " + session.getId();

    Log4j log = new Log4j();
    log.logMessage(sText, "debug");

    This code compiles and runs but I can't figure out where the output is
    going. This is the log4j.properties file, which is located in the same
    directory as the class file.

    log4j.rootCategory=DEBUG, dest1
    log4j.appender.dest1=org.apache.log4j.FileAppender
    #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

    # Appender dest1 writes to the file "test" in user's home.
    log4j.appender.dest1.File=${CATALINA_HOME}/webapps/EP/WEB-INF/classes/app/log

    # Truncate 'test' if it aleady exists.
    log4j.appender.dest1.Append=false

    Thanks,
    Peter
    zpetero, Dec 7, 2004
    #5
  6. Peter

    Ryan Stewart Guest

    "zpetero" <> wrote in message
    news:...
    >I got that and have since set up and tested Log4j,
    >
    > The tricky part is getting it to output to the file I want.
    >
    > Would you by chance know to set it up to send logging info to a file?

    [...]
    > This code compiles and runs but I can't figure out where the output is
    > going. This is the log4j.properties file, which is located in the same
    > directory as the class file.
    >
    > log4j.rootCategory=DEBUG, dest1
    > log4j.appender.dest1=org.apache.log4j.FileAppender
    > #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
    >
    > # Appender dest1 writes to the file "test" in user's home.
    > log4j.appender.dest1.File=${CATALINA_HOME}/webapps/EP/WEB-INF/classes/app/log
    >
    > # Truncate 'test' if it aleady exists.
    > log4j.appender.dest1.Append=false
    >

    If you haven't already, you can find log4j documentation at
    http://logging.apache.org/log4j/docs/

    As for the properties file, you don't often have to set them up, so it's
    hard to remember without looking it up. One thing I do notice is the first
    line should be "log4j.rootLogger=..." and not "rootCategory". Did someone do
    a global find and replace? Those are very dangerous. The ".File" tells it
    what file to write to, which should be in the specified directory within
    your Tomcat installation directory (assuming it is expanded properly; I
    don't think I've tried EL in here). Finally, I don't recognize that last
    line with the ".Append".
    Ryan Stewart, Dec 7, 2004
    #6
  7. Peter

    zpetero Guest

    Ryan,

    How can I stop logging altogether? I only want to write what I
    specify to the log file.

    This line deletes the file if its already there when initialized.
    log4j.appender.dest1.Append=false

    What's the difference beteween,
    log4j.rootCategory=DEBUG, dest1 VS. log4j.rootLogger=DEBUG, dest1
    ??


    Peter

    Here's the porperties file,

    # debug, info, warn, error, fatal
    log4j.rootCategory=DEBUG, dest1
    #log4j.rootLogger=DEBUG, dest1
    log4j.appender.dest1=org.apache.log4j.FileAppender
    #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

    #log4j.logger.com.web=FATAL

    # Appender dest1 writes to the file "test" in user's home.
    log4j.appender.dest1.File=${CATALINA_HOME}/webapps/Epiphany/WEB-INF/classes/app/log

    # Truncate 'test' if it aleady exists.
    log4j.appender.dest1.Append=false

    Ryan Stewart wrote:
    > "zpetero" <> wrote in message
    > news:...
    > >I got that and have since set up and tested Log4j,
    > >
    > > The tricky part is getting it to output to the file I want.
    > >
    > > Would you by chance know to set it up to send logging info to a

    file?
    > [...]
    > > This code compiles and runs but I can't figure out where the output

    is
    > > going. This is the log4j.properties file, which is located in the

    same
    > > directory as the class file.
    > >
    > > log4j.rootCategory=DEBUG, dest1
    > > log4j.appender.dest1=org.apache.log4j.FileAppender
    > > #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
    > >
    > > # Appender dest1 writes to the file "test" in user's home.
    > >

    log4j.appender.dest1.File=${CATALINA_HOME}/webapps/EP/WEB-INF/classes/app/log
    > >
    > > # Truncate 'test' if it aleady exists.
    > > log4j.appender.dest1.Append=false
    > >

    > If you haven't already, you can find log4j documentation at
    > http://logging.apache.org/log4j/docs/
    >
    > As for the properties file, you don't often have to set them up, so

    it's
    > hard to remember without looking it up. One thing I do notice is the

    first
    > line should be "log4j.rootLogger=..." and not "rootCategory". Did

    someone do
    > a global find and replace? Those are very dangerous. The ".File"

    tells it
    > what file to write to, which should be in the specified directory

    within
    > your Tomcat installation directory (assuming it is expanded properly;

    I
    > don't think I've tried EL in here). Finally, I don't recognize that

    last
    > line with the ".Append".
    zpetero, Dec 7, 2004
    #7
  8. Peter

    zpetero Guest

    Ryan,

    How can I stop logging altogether? I only want to write what I
    specify to the log file.

    This line deletes the file if its already there when initialized.
    log4j.appender.dest1.Append=false

    What's the difference beteween,
    log4j.rootCategory=DEBUG, dest1 VS. log4j.rootLogger=DEBUG, dest1
    ??


    Peter

    Here's the porperties file,

    # debug, info, warn, error, fatal
    log4j.rootCategory=DEBUG, dest1
    #log4j.rootLogger=DEBUG, dest1
    log4j.appender.dest1=org.apache.log4j.FileAppender
    #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout

    #log4j.logger.com.web=FATAL

    # Appender dest1 writes to the file "test" in user's home.
    log4j.appender.dest1.File=${CATALINA_HOME}/webapps/Epiphany/WEB-INF/classes/app/log

    # Truncate 'test' if it aleady exists.
    log4j.appender.dest1.Append=false

    Ryan Stewart wrote:
    > "zpetero" <> wrote in message
    > news:...
    > >I got that and have since set up and tested Log4j,
    > >
    > > The tricky part is getting it to output to the file I want.
    > >
    > > Would you by chance know to set it up to send logging info to a

    file?
    > [...]
    > > This code compiles and runs but I can't figure out where the output

    is
    > > going. This is the log4j.properties file, which is located in the

    same
    > > directory as the class file.
    > >
    > > log4j.rootCategory=DEBUG, dest1
    > > log4j.appender.dest1=org.apache.log4j.FileAppender
    > > #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
    > >
    > > # Appender dest1 writes to the file "test" in user's home.
    > >

    log4j.appender.dest1.File=${CATALINA_HOME}/webapps/EP/WEB-INF/classes/app/log
    > >
    > > # Truncate 'test' if it aleady exists.
    > > log4j.appender.dest1.Append=false
    > >

    > If you haven't already, you can find log4j documentation at
    > http://logging.apache.org/log4j/docs/
    >
    > As for the properties file, you don't often have to set them up, so

    it's
    > hard to remember without looking it up. One thing I do notice is the

    first
    > line should be "log4j.rootLogger=..." and not "rootCategory". Did

    someone do
    > a global find and replace? Those are very dangerous. The ".File"

    tells it
    > what file to write to, which should be in the specified directory

    within
    > your Tomcat installation directory (assuming it is expanded properly;

    I
    > don't think I've tried EL in here). Finally, I don't recognize that

    last
    > line with the ".Append".
    zpetero, Dec 7, 2004
    #8
  9. Peter

    Ryan Stewart Guest

    "zpetero" <> wrote in message
    news:...
    *fixed top post*
    > Ryan,
    >
    > How can I stop logging altogether? I only want to write what I
    > specify to the log file.
    >
    > This line deletes the file if its already there when initialized.
    > log4j.appender.dest1.Append=false
    >
    > What's the difference beteween,
    > log4j.rootCategory=DEBUG, dest1 VS. log4j.rootLogger=DEBUG, dest1
    > ??
    >
    >
    > Peter
    >
    > Here's the porperties file,
    >
    > # debug, info, warn, error, fatal
    > log4j.rootCategory=DEBUG, dest1
    > #log4j.rootLogger=DEBUG, dest1
    > log4j.appender.dest1=org.apache.log4j.FileAppender
    > #log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
    >
    > #log4j.logger.com.web=FATAL
    >
    > # Appender dest1 writes to the file "test" in user's home.
    > log4j.appender.dest1.File=${CATALINA_HOME}/webapps/Epiphany/WEB-INF/classes/app/log
    >
    > # Truncate 'test' if it aleady exists.
    > log4j.appender.dest1.Append=false
    >

    Did you look at the documentation at all? Look through the "Short Manual"
    here:
    http://logging.apache.org/log4j/docs/manual.html

    It provides a decent explanation of what a "logger" is and how the whole
    thing works. Basically, loggers are what take your input and write it to
    whatever log/logs you set up with the properties file. There can be, and
    normally are, multiple loggers in any application. Each logger is named when
    created, and you can retrieve loggers by name. In your code, you have
    something like:
    Log log = LogFactory.getLog(XXX.class);

    That gets or creates a logger and assigns it the fully qualified name of the
    XXX class. In other words, if XXX.class is in package zzz.yyy, then the
    loggers name is zzz.yyy.XXX. Okay so far? Now every call to
    LogFactory.getLog(XXX.class) or to LogFactory.getLog("zzz.yyy.XXX") (I think
    this is correct syntax) will return that same logger, which means you will
    be writing to the same destination. Also, loggers are hierarchical. The
    "base" logger is rootLogger (to answer your question about that). You get
    that one with LogFactory.getRootLogger(). All other loggers "extend" the
    root logger. By default, *everything* that is logged gets written to the
    rootLogger. You configure the root logger by first assigning it a logging
    level and Appender:
    log4j.rootLogger=DEBUG, dest1

    DEBUG is the level of messages you want to log (there are multiple levels...
    five I think). dest1 is the name of the Appender. That is configured later
    in your properties file. An Appender is what does the actual output. You've
    told log4j that you want the dest1 Appender to be a FileAppender and given
    it a destination file to write to. Finally, the tricky part (to explain
    anyway)... Back to the hierarchical thing. Assume that for our zzz package
    that we were using, we only want to log FATAL level and above. Like the line
    in your properties file, we'd write:
    log4j.logger.zzz=FATAL

    That sets the logger named zzz to log only FATAL messages. If you wanted to
    log it to a different place, you'd specify and configure another Appender:
    log4j.logger.zzz=FATAL, dest2
    log4j.appender.dest2=org.apache.log4j.FileAppender
    ....

    Now here's the thing. Our zzz.yyy.XXX logger is considered a child of the
    zzz logger because of the name. Logger names determine relationships. A
    logger named zzz.yyy would be a direct child of zzz. zzz.yyy.XXX is a direct
    child of zzz.yyy. Therefore, when you configure the zzz logger, you're also
    configuring the zzz.yyy logger and the zzz.yyy.XXX logger. Now assume that
    you configure an Appender for each one of zzz, zzz.yyy, and zzz.yyy.XXX:
    log4j.logger.zzz=FATAL, dest2
    log4j.logger.zzz.yyy=FATAL, dest3
    log4j.logger.zzz.yyy.XXX=FATAL, dest4

    Then you call LogFactory.getLog(XXX.class). You've now got the zzz.yyy.XXX
    logger. What happens when you write something to it? Assuming you write a
    FATAL message, of course, it will be written to the dest4 Appender. And the
    dest3 Appender. And dest2 and dest1 as well. Logged messages by default
    travel up the hierarchy and are logged by every configured Appender, and
    remember that I said the root logger is the base of every logger hierarchy.
    To stop the message from traveling up the hierarchy, there is an additivity
    flag. Assume we want to write to the zzz.yyy.XXX logger, but not have it go
    to any of the others. You would set additivity to false on zzz.yyy.XXX, like
    so (I think):
    log4j.additivity.zzz.yyy.XXX=false

    By setting the additivity to false on zzz.yyy instead, you'd get messages
    logged to dest4 and dest3 but not the others.

    *whew*, that was longer than I'd planned. Hope it gets you going in the
    right direction.
    Ryan Stewart, Dec 8, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    2
    Views:
    855
  2. E11
    Replies:
    1
    Views:
    4,755
    Thomas Weidenfeller
    Oct 12, 2005
  3. Wybo Dekker
    Replies:
    1
    Views:
    353
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    403
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    811
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page