log4j, NoClassDefFoundError

G

Ghost

I am trying to test log4j in HelloWorld to see if I can use it for my
logging.

Here is what I have:
//HelloWorld.java
import org.apache.log4j.*;

public class HelloWorld {
public static Logger logger = Logger.getLogger("HelloWorld");

public static void main(String[] args) {
logger.info("Entering main().");
System.out.println("Hello World!");
}
}


// This is my build.xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="test" default="compile">
<property name="source.root" value="."/>
<property name="class.root" value="."/>
<property name="lib.dir" value="."/>
<property name="log4j.jar"
value="/export/home/bryan/dev/wui/WEB-INF/lib/log4j-1.2.9.jar"/>

<path id="project.class.path">
<pathelement location="${class.root}"/>
<pathelement location="${log4j.jar}"/>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="compile" depends="clean">
<javac srcdir="${source.root}"
destdir="${class.root}"
debug="on"
deprecation="on"
source="1.4">
<classpath refid="project.class.path"/>
</javac>
</target>

</project>


I can get this to compile, but when I try to run it I get an error:
NoClassDefFoundError: org/apache/log4j/Logger
or
NoClassDefFoundError: org/apache/log4j/Category

Does anyone have any idea? I can get log4j to work with tomcat, but it
won't work with HelloWorld. I am using j2sdk1.4.2_08.

Any information would help.

Thanks in advance.
 
R

Roland

I am trying to test log4j in HelloWorld to see if I can use it for my
logging.

Here is what I have:
//HelloWorld.java
import org.apache.log4j.*;

public class HelloWorld {
public static Logger logger = Logger.getLogger("HelloWorld");

public static void main(String[] args) {
logger.info("Entering main().");
System.out.println("Hello World!");
}
}


// This is my build.xml:
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="test" default="compile">
<property name="source.root" value="."/>
<property name="class.root" value="."/>
<property name="lib.dir" value="."/>
<property name="log4j.jar"
value="/export/home/bryan/dev/wui/WEB-INF/lib/log4j-1.2.9.jar"/>
[...]
</project>


I can get this to compile, but when I try to run it I get an error:
NoClassDefFoundError: org/apache/log4j/Logger
or
NoClassDefFoundError: org/apache/log4j/Category

Does anyone have any idea? I can get log4j to work with tomcat, but it
won't work with HelloWorld. I am using j2sdk1.4.2_08.

Any information would help.

Thanks in advance.

Probably the Log4 Jar is not in the classpath.

Add the jar to the classpath, either by adding it to the CLASSPATH
environment variable, or by specifying it at the commandline. For the
latter you can use the following commandline (all on one line, your
current directory should be the directory containing HelloWorld.class):

java -cp .:/export/home/bryan/dev/wui/WEB-INF/lib/log4j-1.2.9.jar HelloWorld
--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \
 
A

Andrew Thompson

Strictly speaking, ...

As you might in a technical article, directed to native English
speakers?
...Sun does not /recommend against/ the use of the
CLASSPATH environment variable, but they are saying that using the
-classpath option is the /preferred way/ of setting the class path.

'recommend against'/'not the preferred way'.. how many people
reading this forum would be able to clearly distinguish between
the two? ( I am a native English speaker, but could not immediately
spot the difference myself. )

In any case, whichever wording you feel more confortable with, it
makes sense to mention that is very *old* advice..
 
R

Roland

As you might in a technical article, directed to native English
speakers?




'recommend against'/'not the preferred way'.. how many people
reading this forum would be able to clearly distinguish between
the two? ( I am a native English speaker, but could not immediately
spot the difference myself. )

In any case, whichever wording you feel more confortable with, it
makes sense to mention that is very *old* advice..
IMO there is a difference if Sun would have said "we recommend not to
use the CLASSPATH environment variable", rather than they currently do
"the -classpath option is the preferred way". Especially in technical
discussions in groups like this one. Remember the W3C recommendations
for HTML, CSS, XML etc.: a recommendation is like a standard.

--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \
 
A

Andrew Thompson

IMO there is a difference if Sun would have said "we recommend not to
use the CLASSPATH environment variable", rather than they currently do
"the -classpath option is the preferred way". Especially in technical
discussions in groups like this one. Remember the W3C recommendations
for HTML, CSS, XML etc.: a recommendation is like a standard.

<http://groups.google.com.au/group/comp.infosystems.www.authoring.html/msg/4352246751c48b1e?hl=en>
(for one of many discussions where the differences between
'W3C recommendation' and 'standard' are examined in detail)
But ultimately, I am not especially interested in the fine
distinctions in words as ascertaining..

Do you intend to continue mentioning the classpath
environment variable without warning that Sun considers
it a 'suboptimal solution' (/insert whatever words here
make you most comfy) and has done so for a long time?
 
R

Roland

<http://groups.google.com.au/group/comp.infosystems.www.authoring.html/msg/4352246751c48b1e?hl=en>
(for one of many discussions where the differences between
'W3C recommendation' and 'standard' are examined in detail)
But ultimately, I am not especially interested in the fine
distinctions in words as ascertaining..

Hmm... strange. You have shown on a number of occasions to weigh someone
else's words. To give one example (from
No, you are using two of them.
Do you intend to continue mentioning the classpath
environment variable without warning that Sun considers
it a 'suboptimal solution' (/insert whatever words here
make you most comfy) and has done so for a long time?
Maybe. You are here to correct me, aren't you?
--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \
 
A

Andrew Thompson

On 17-6-2005 14:52, Andrew Thompson wrote: ...

...in this instance..
Hmm... strange. You have shown on a number of occasions to weigh someone
else's words. To give one example (from
<http://groups-beta.google.com/group..._frm/thread/5f8a7f2337f5baa0/9395c824461fe05a>):

In that case I am referring to malfunctioning code.
That is a very different situation.
Maybe. You are here to correct me, aren't you?

Not always, and it worries me that it seems you are
prepared to give 'incorrect' (based on your reference
to me correcting you) information to all comers.

But then - I am still not entirely clear.

...Do you even agree that mentioning the environment
variable without further warning is not the best
course of action?

(shrugs) If I am unable to convince you, it hardly seems
worth continuing the discussion, as your course of action
becomes clear.
 
R

Roland

...in this instance..




In that case I am referring to malfunctioning code.
That is a very different situation.
Maybe it's a different situation for you, but to me it appeared to be
quite a nitpicky response to --in this case-- the general use of an
indefinite article in speech/writing.
Not always, and it worries me that it seems you are
prepared to give 'incorrect' (based on your reference
to me correcting you) information to all comers.
If I write anything incorrect, please feel free to correct me, like I do
when I think someone is posting something inappropriate or untrue. Maybe
unlike you're thinking, I still don't consider using (or mentioning the
use of) the CLASSPATH environment variable as /incorrect/.
But then - I am still not entirely clear.

...Do you even agree that mentioning the environment
variable without further warning is not the best
course of action?
To me it seems that the only answer you want to hear is "Yes".
(shrugs) If I am unable to convince you, it hardly seems
worth continuing the discussion, as your course of action
becomes clear.
It's not clear (sic) to me what you're implying. I could start guessing,
but please elaborate, so I can react to something concrete.

I'm not sure why you feel the need to convince me, or that you want me
to agree with you, for that matter.

Coming back to your question. Whenever appropriate, I'll refer to the
CLASSPATH environment variable and/or the -classpath option to specify
the class path. Depending on the situation, I may or may not mention the
fact that the -classpath option is the preferred way.
--
Regards,

Roland de Ruiter
` ___ ___
`/__/ w_/ /__/
/ \ /_/ / \
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top