1

I'm new to GATE, ANNIE & Info Extraction(IE). I'm trying to use ANNIE to do some IE. I installed GATE on Ubuntu 14.*, GATE Developer 8 worked perfectly. I'm trying to use GATE Embedded from my Java (JDK 1.8) project in Eclipse (Luna). I created a user library to add necessary GATE Jars (gate.jar & all jars in Lib) to build path. I added gate.home system property using

System.setProperty("gate.home", "/home/haree/GATE_Developer_8.0");

I tried the examples provided on GATE link, but I'm stuck with the following Null Pointer Exception which I couldn't fix.

Output:

Initialising GATE...
log4j:WARN No appenders could be found for logger (gate.Gate).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NullPointerException
    at gate.util.Files.getResource(Files.java:399)
    at gate.util.Files.getGateResource(Files.java:419)
    at gate.Gate.init(Gate.java:178)
    at sheffield.examples.TestGate.main(TestGate.java:16)

I noticed that the Exception is caused by - Gate.init() method call. I wrote a simple class with a call to the above method and played with that system property(gate.home) etc but of no use. I somehow feel that the exception is caused when the GATE API is trying to read the gate.xml file which is in the installation directory. I copy that here as well along with code I wrote. Any help in fixing this is appreciated.

Code:

package sheffield.examples;

import gate.Gate;
import gate.util.GateException;
import gate.util.Out;

public class TestGate {

    public static void main(String[] args) {

          // initialise the GATE library
        Out.prln("Initialising GATE...");
        System.setProperty("gate.home", "/home/haree/GATE_Developer_8.0");

        try {
            Gate.init();
        } catch (GateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Out.prln("...GATE initialised");
    }
}

gate.xml file:

<?xml version="1.0"?>
<!-- gate.xml -->
<!-- $Id: gate.xml 17080 2013-11-12 19:29:34Z markagreenwood $ -->

<!-- any entries in this file will be processed at Gate.init()
     time - i.e. will appear in every GATE invocation -->

<GATE>

<GATECONFIG Save_options_on_exit="true" Save_session_on_exit="true"/>


</GATE>

Note: I googled and found this link which discusses the same problem but it didn't help me

More Info:

I configured log4j which I ignored before and logs look like this:

Initialising GATE...
18:49:37  INFO [main] - gate.Gate.initLocalPaths - Using /home/haree/GATE_Developer_8.0 as GATE home
18:49:37  INFO [main] - gate.Gate.initLocalPaths - Using /home/haree/GATE_Developer_8.0/plugins as installed plug-ins directory.
18:49:37  INFO [main] - gate.Gate.initLocalPaths - Using /home/haree/GATE_Developer_8.0/gate.xml as site configuration file.
18:49:37  INFO [main] - gate.Gate.initLocalPaths - Using /home/haree/.gate.xml as user configuration file
18:49:37  INFO [main] - gate.Gate.initLocalPaths - Using /home/haree/.gate.session as user session file
Exception in thread "main" java.lang.NullPointerException
    at gate.util.Files.getResource(Files.java:399)
    at gate.util.Files.getGateResource(Files.java:419)
    at gate.Gate.init(Gate.java:178)
    at sheffield.examples.TestGate.main(TestGate.java:16)

I have read that GATE creates/ uses two configuration files in the user home directory namely: 1)gate.xml & 2)gate.session

I couldn't find both these files in the home directory for some reason (I'm new to Ubuntu file system), not sure if they are hidden files.

Hari Gudigundla
  • 812
  • 10
  • 20

1 Answers1

3

The issue has to do with the class loading in Eclipse, and I suspect it wouldn't be happening if you did it in IntelliJ or via the CLI (I tried it in IntelliJ Idea, and it worked fine.)

When you call

Gate.init();

It's stepping through a bunch of code that initializes it's state, and one of them tries to load a resource using the custom Gate class loader (in Files.getResource()). The class loader hasn't been initialized yet though, so it falls back to trying to load the resource using this:

  return Files.class.getClassLoader().getResource(resourceName);

Which, in some cases (the Eclipse case, specifically), will return a null classloader. This is (I suppose) a bug in Gate, as they should fall back to the system classloader in this case.

This is the same issue as here: getClass().getClassLoader() is null, why?

Community
  • 1
  • 1
Kylar
  • 8,876
  • 8
  • 41
  • 75