Search code examples
javagate

GATE Embedded sample Example NoClassFound Error


I am new to GATE Embedded , i tried simple example and getting NoClassDefFoundError. First i will explain what i tried

  1. Donwload and Extract Gate 7.0 in D:\project\gate-7.0
  2. Netbean create new project --> added library gate.jar and lib folder
  3. Tried to execute simple java code
public static void main(String args[]) throws GateException, IOException 
 {
  // initialise the GATE library
  Out.prln("Initialising GATE...");
  Gate.init();
  Out.prln("...GATE initialised");
}

Run time getting error

Initialising GATE...
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
        at gate.Gate.<clinit>(Gate.java:83)
        at gatedemo.StandaloneDemo.main(StandaloneDemo.java:84)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger

I think error is related to classpath.


Solution

  • Netbean create new project --> added library gate.jar and lib folder

    You need your application's classpath to contain all of the JAR files that are inside the lib folder, not the folder itself.

    Note that once you fix this you will probably get a warning saying GATE "could not initialize Log4J" - to avoid this either add GATE's bin directory to your application's classpath as well, create your own log4j.properties in your project's top level src directory, or add

    org.apache.log4j.BasicConfigurator.configure();
    

    at the top of your main method.

    P.S. I also recommend you use a more recent GATE (7.1 or a current snapshot) unless you have a specific reason why you must use an old release.