×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Log4j issue

Log4j issue

Log4j issue

(OP)
I am new to Java programming.
I have J2SDK1.5.0 in my machine
I was able find C:\Program Files\Java\j2re1.5.0  and C:\Program Files\Java\j2sdk1.5.0 and their respective folders with file.
I was trying to compile some java file which has log4j calling
The file Log4jDemo.java contains the following:

import org.apache.log4j.Logger;

public class Log4jDemo {

      static Logger log = Logger.getLogger("Log4jDemo");

      public static void main(String args[]) {

            log.debug("This is my debug message.");
            log.info("This is my info message.");
            log.warn("This is my warn message.");
            log.error("This is my error message.");
            log.fatal("This is my fatal message.");
      }
}

Before compiling i have extrated the log4j.jar from apache site file and kept at "C:\Program Files\Java\j2sdk1.5.0\lib" folder
I am able to compile file by
C:\Program Files\Java\test>javac -classpath "C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar" Log4jDemo.java

But when i do

C:\Program Files\Java\test>java Log4jDemo
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
        at Log4jDemo.<clinit>(Log4jDemo.java:5)

Why this error is coming?
please do help in resolving this ....
Regards,
Rk

RE: Log4j issue

Because you need to place the log4j.jar into the classpath when running your program (just like you did when you compiled it).

CODE

java -cp "C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar" Log4jDemo.java

Tim

RE: Log4j issue

(OP)
I tried the following options:

1).
C:\Program Files\Java\test>java -classpath C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar Log4jDemo
Exception in thread "main" java.lang.NoClassDefFoundError: Files\Java\j2sdk1/5/0\lib\log4j/jar
Problem still persists

2).
Set the Classpath first
C:\Program Files\Java\test>set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar

C:\Program Files\Java\test>java Log4jDemo
Exception in thread "main" java.lang.NoClassDefFoundError: Log4jDemo
Problem still persists

3).
C:\Program Files\Java\test>java -classpath=.;C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar;%CLASSPATH Log4jDemo
Unrecognized option: -classpath=.;C:\Program
Could not create the Java virtual machine.
Problem still persists

4).
Copy the log4j.jar under C:\Program Files\Java\j2sdk1.5.0\ext\ (I have created an  ext folder)
C:\Program Files\Java\test>java -classpath=. Log4jDemo
Unrecognized option: -classpath=.
Could not create the Java virtual machine.
Problem still persists
I have pasted Important env vars from set below:

C:\Program Files\Java\test>set
CLASSPATH=C:\Program Files\Java\j2sdk1.5.0\lib\log4j.jar
HOMEPATH=\
HOMESHARE=\\pun-home-01\rkondapa$
INCLUDE=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\
JAVA_HOME=C:\Program Files\Java\j2sdk1.5.0
JDK_DIR=C:\Program Files\Java\j2sdk1.5.0
LIB=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32
;C:\WINDOWS;C:\PROGRA~1\VANTIV~1.5;C:\Program Files\Microsoft SQL Server\80\Tool
s\BINN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system
32;C:\WINDOWS;C:\PROGRA~1\VANTIV~1.5;C:\Program Files\Microsoft SQL Server\80\To
ols\BINN;C:\Program Files\Java\j2sdk1.5.0\bin;C:\Program Files\Java\j2sdk1.5.0\l
ib

Please do suggest the other ways

RE: Log4j issue

The first of the above would probably have worked had you placed the quotes around the path as in my suggestion.

Tim

RE: Log4j issue

(OP)
Thanks a lot...
It is working with quotes.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close