Configure Eclipse for Log4j

2019-02-19 20:47发布

问题:

I am working on an application using apache jena, to access dbpedia using sparql. Well I am very new to DBPedia and apache jena, I did some research and started with some sample code to create VCARD.

public class DpPedia extends Object {

static String personURI   = "<!..http://def/JohnSmith..!>";
static String fullName    = "John Smith";
static String Fullname = "Pulkit Gupta";

  public static void main (String args[]) {
    // create an empty model
    Model model = ModelFactory.createDefaultModel();

   // create the resource
   Resource johnSmith = model.createResource(personURI);
   Resource pulkitgupta=model.createResource(personABC);

  // add the property
  johnSmith.addProperty(VCARD.FN, fullName);
  pulkitgupta.addProperty(VCARD.FN,Fullname);

  }

}

However when i tried to execute this code .. It end up with an error

log4j:WARN No appenders could be found for logger (org.apache.jena.riot.stream.JenaIOEnvironment). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

it seems my eclipse is not configured properly and I need to install Log4j. Well I downloaded the files, but not sure how up configure it with eclipse.

回答1:

jena use log4j as logging system, and the warning messages tell explicitly that you are lacking of a log4j.properties to initialize it.

"This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration."

Create log4j.properties file under src and retry. You can find some sample config files here



回答2:

use org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);



回答3:

The easiest way to do this is by going to the folder where you extracted apache jena.

  1. Find a properties file named : jena-log4j.properties. Copy this

  2. Navigate to your workspace folder where you have your source project.

  3. Go to bin folder and paste the file there. Make sure you rename the file to just log4j.properties

  4. Clean the project and run it.

The errors would now have gone.



标签: log4j jena