Configure Eclipse for Log4j

烂漫一生 提交于 2019-12-01 07:31:50

问题


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:


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.




回答3:


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



来源:https://stackoverflow.com/questions/20365204/configure-eclipse-for-log4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!