Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:26:43+00:00 2026-06-08T09:26:43+00:00

This is my Student class that used to test log4j. public class Student{ private

  • 0

This is my Student class that used to test log4j.

public class Student{    
    private static final Logger logger = Logger.getLogger(Student.class.getName());   

    public Student() {  
         PropertyConfigurator.configure("log4j.properties");  
    }

    public static void main(String args[]){  
        logger.log(Level.INFO, "My log4j Test");    
    } 
}

This is my log4j.properties file

log4j.rootLogger=INFO,Appender1,Appender2
log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender2=org.apache.log4j.RollingFileAppender
log4j.appender.Appender2.File=C:/Log4j/MyLogExample.log

log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout`  
log4j.appender.Appender1.Target=System.out`   
log4j.appender.Appender1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n`  

log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout`  
log4j.appender.Appender2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n`  

log4j.appender.Appender2.MaxFileSize=50KB`  
log4j.appender.Appender2.MaxBackupIndex=10` 

When I run this program using Eclipse MyLogExample.log file gets created. But after I have created a jar file and run it using the command prompt, the log file is not created.

in console i can see this error.

log4j:ERROR Could not read configuration file [log4j.properties]. 
java.io.FileNotFoundException: log4j.properties (The system cannot find the file specified) 

After I add the following code example, the log file is created even when the jar file run with command prompt.

PropertyConfigurator.configure("C:\\eclipeworkspace\\Log4jTest\\log4j.properties");

How I can give relative path instead of exact path?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:26:46+00:00Added an answer on June 8, 2026 at 9:26 am

    log4j.properties should be in your classpath. Add it to the classpath when running from command line.

    A better alternative is to specify the property file using

    -Dlog4j.configuration=relative path/log4j.properties

    from the command line.
    In this case you can remove the line PropertyConfigurator.configure("log4j.properties"); from your code – you don’t need to do anything in the code to specify the property file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that looks like this class Student { public String str;
A student in my class brought this to my attention, and I didn't have
This part of my code is used to award a grade to a student
I have some class like this <div class = student> <div class = name>Adam
I'm a student in Java class and learned something about Java today that made
I am getting error while diclaring collName as static variable in Student class. Could
I have following form: class EmailPreferences(forms.ModelForm): Base form used for fields that are always
Take this mapping file <class name=com.data.StudentData table=gr_student> <id name=id> <generator class=identity /> </id> <property
I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
I have student.xml file and am parsing this file using SAX Parser and now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.