Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > can't find class file

Reply
Thread Tools

can't find class file

 
 
Peter
Guest
Posts: n/a
 
      12-06-2004
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
 
Reply With Quote
 
 
 
 
Ryan Stewart
Guest
Posts: n/a
 
      12-06-2004
"Peter" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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?


 
Reply With Quote
 
 
 
 
zpetero
Guest
Posts: n/a
 
      12-06-2004
I knew it was deprecated,

http://www.porcupyne.org/docs/struts...ated-list.html

but I still use other deprecated methods and they work.

What replaced it?

Peter


Ryan Stewart wrote:
> "Peter" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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?

 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      12-06-2004
zpetero wrote:
> I knew it was deprecated,
>
> http://www.porcupyne.org/docs/struts...ated-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"

 
Reply With Quote
 
zpetero
Guest
Posts: n/a
 
      12-07-2004
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.Patt ernLayout

# 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

 
Reply With Quote
 
Ryan Stewart
Guest
Posts: n/a
 
      12-07-2004
"zpetero" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>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.Patt ernLayout
>
> # 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".


 
Reply With Quote
 
zpetero
Guest
Posts: n/a
 
      12-07-2004
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.Patt ernLayout

#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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> >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.Patt ernLayout
> >
> > # 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".


 
Reply With Quote
 
zpetero
Guest
Posts: n/a
 
      12-07-2004
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.Patt ernLayout

#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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> >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.Patt ernLayout
> >
> > # 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".


 
Reply With Quote
 
Ryan Stewart
Guest
Posts: n/a
 
      12-08-2004
"zpetero" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
*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.Patt ernLayout
>
> #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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
find a matching pattern in file and find it in another file too nani Perl Misc 2 03-14-2008 05:20 AM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM



Advertisments