1

I am using Eclipse and Java. I've setup the jena library and done my first RDF statement using this library, but I get a warning and I don't know exactly what it means. This is the code:

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class Main {

    public static void main(String[] args) {
        Model m = ModelFactory.createDefaultModel();
        String NS = "http://www.example.org/rdf/";
        Resource r = m.createResource(NS + "r");
        Property p = m.createProperty(NS + "p");
        r.addProperty(p, "hello world", XSDDatatype.XSDstring);
        m.write(System.out, "Turtle");
    }

}

And this is the output:

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.
<http://www.example.org/rdf/r>
        <http://www.example.org/rdf/p>  "hello world"^^<http://www.w3.org/2001/XMLSchema#string> .

So the code does compile and work but I don't know what to do about this warning. How can I get rid of it?

Ariel
  • 1,222
  • 2
  • 14
  • 25
  • 1
    Did you read http://logging.apache.org/log4j/1.2/faq.html#noconfig ? – Jon Skeet Dec 31 '13 at 16:24
  • So how do I load the log4j.properties file in eclipse? This is how Jena looks like: https://dl.dropboxusercontent.com/u/27349592/jena_snapshot.png – Ariel Jan 01 '14 at 16:57
  • If you make it a resource to be copied into the `bin` directory, it should be fine. – Jon Skeet Jan 01 '14 at 19:41
  • I have found the file needed. It's called "jena-log4j.properties". What do I have to do with it? Can you please explain to me step by step? – Ariel Jan 02 '14 at 15:51
  • No, I've never even used Jena - but I suspect you just want a log4j.properties file rather than jena-log4j.properties – Jon Skeet Jan 02 '14 at 15:55
  • 1
    This is not specific to Jena; it's log4j setup. Put "log4j.properties" into src/ which will do as Jon suggests. Or add static { Log.setCmdLogging() ; } to your file which loads Jena command line log4j setup. Or ignore the warning. – AndyS Jan 03 '14 at 08:40

3 Answers3

1

The answer that has been provided by Ariel has a problem. Actually when we write the code Log.setLog4j("jena-log4j.properties"); it arises the following error:

The method setLog4j(String) is undefined for the type Log

But you can find a better answer here:

Configure Eclipse for Log4j

You just need to copy the file jena-log4j.properties in the folder that your main class is placed. i.e. the class that has the main function.

Then you need to rename the file to log4j.properties.

I did it in Eclipse and worked for me.

Community
  • 1
  • 1
MJBZA
  • 4,796
  • 8
  • 48
  • 97
0

I finally managed to solve the problem. Thanks to AndyS for the solution.

Copy the "jena-log4j.properties" file inside the folder of the application and add the following line of code at the start of the main:

Log.setLog4j("jena-log4j.properties");
Community
  • 1
  • 1
Ariel
  • 1,222
  • 2
  • 14
  • 25
0

Copy jena-log4j.properties file inside the jena folder and paste it to resource folder (in case of eclipse how to guide to add resource folder is here). Then rename it as log4j.properties.

Community
  • 1
  • 1
Ruwanka De Silva
  • 3,555
  • 6
  • 35
  • 51