Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

log4j, NoClassDefFoundError

Thread view: 
Ghost - 16 Jun 2005 15:44 GMT
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.
Roland - 16 Jun 2005 18:00 GMT
> I am trying to test log4j in HelloWorld to see if I can use it for my
> logging.
[quoted text clipped - 20 lines]
>     <property name="log4j.jar"
> value="/export/home/bryan/dev/wui/WEB-INF/lib/log4j-1.2.9.jar"/>

[...]
> </project>
>
[quoted text clipped - 9 lines]
>
> 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
Signature

Regards,

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

Andrew Thompson - 16 Jun 2005 18:06 GMT
> Add the jar to the classpath, either by adding it to the CLASSPATH
> environment variable, ...

Note that Sun has recommended against that since at least Java 1.3.
<http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html>

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Roland - 16 Jun 2005 20:28 GMT
>>Add the jar to the classpath, either by adding it to the CLASSPATH
>>environment variable, ...
>
> Note that Sun has recommended against that since at least Java 1.3.
> <http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html>

Strictly speaking, 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.
Signature

Regards,

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

Andrew Thompson - 17 Jun 2005 05:46 GMT
>>>Add the jar to the classpath, either by adding it to the CLASSPATH
>>>environment variable, ...
[quoted text clipped - 3 lines]
>>
> 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..

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Roland - 17 Jun 2005 10:48 GMT
>>>>Add the jar to the classpath, either by adding it to the CLASSPATH
>>>>environment variable, ...
[quoted text clipped - 18 lines]
> 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.

Signature

Regards,

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

Andrew Thompson - 17 Jun 2005 13:52 GMT
>>>>>Add the jar to the classpath, either by adding it to the CLASSPATH
>>>>>environment variable, ...
[quoted text clipped - 24 lines]
> 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/435224
6751c48b1e?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?

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Roland - 24 Jun 2005 13:13 GMT
>>>>>>Add the jar to the classpath, either by adding it to the CLASSPATH
>>>>>>environment variable, ...
[quoted text clipped - 30 lines]
> 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
<http://groups-beta.google.com/group/comp.lang.java.programmer/browse_frm/thread/
5f8a7f2337f5baa0/9395c824461fe05a
>):
<quote>
>> Hi,
>> I am using a Date selector component that allows the user to visually
>> select a date (day-month-year).
>
> No, you are using two of them.
</quote>

> 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?
Signature

Regards,

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

Andrew Thompson - 24 Jun 2005 13:37 GMT
..
>> But ultimately, I am not especially interested in the fine
>> distinctions in words

..in this instance..

>>..as ascertaining..  
>
> 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/comp.lang.java.programmer/browse_frm/thread/
5f8a7f2337f5baa0/9395c824461fe05a
>):

In that case I am referring to malfunctioning code.
That is a very different situation.

>> 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?

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.

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane

Roland - 26 Jun 2005 15:20 GMT
> ...
>
[quoted text clipped - 11 lines]
> 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.

>>>Do you intend to continue mentioning the classpath
>>>environment variable without warning that Sun considers
[quoted text clipped - 6 lines]
> 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.
Signature

Regards,

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.