0

I am using Stanford POSTagger in my project and imported the tagger .jar and it worked just fine but the problem i encountered when i tried to add Stanford NER_Recognizer .jar file to my project Both of the jars have the same namespace edu.stanford.nlp but there are classes in the NER .jar not present in the POStagger.jar

So I get this exception:

Exception in thread "main" java.lang.NoSuchFieldError: strictGoodCoNLL
    at edu.stanford.nlp.ie.NERFeatureFactory.featuresCpC(NERFeatureFactory.java:1710) " this is because the pos tagger .jar has edu.stanford.nlp.io.IOUtils class which is also present in the NER .jar

So, how can I choose that I want the second class not the first?

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Firas252
  • 73
  • 1
  • 9
  • possible duplicate of [Possible to use two java classes with same name and same package?](http://stackoverflow.com/questions/6879652/possible-to-use-two-java-classes-with-same-name-and-same-package) – Jonathon Anderson Sep 03 '14 at 22:29
  • there r no useful answer i can use in that question how could i call a classloader and not make the same conflict – Firas252 Sep 03 '14 at 22:38

1 Answers1

0

Assuming second jar should always override the first one something like this should suffice.

java -classpath  NER_Recognizer.jar;tagger.jar

from Java 8 Class Path page

Specification Order

The order in which you specify multiple class path entries is important. The Java interpreter will look for classes in the directories in the order they appear in the class path variable. In the previous example, the Java interpreter will first look for a needed class in the directory C:\java\MyClasses. Only when it does not find a class with the proper name in that directory will the interpreter look in the C:\java\OtherClasses directory.

Ajay George
  • 11,759
  • 1
  • 40
  • 48
  • The issue is not that the class cannot be found, it's that the class can be found twice. I don't think this addresses the issue because there will still be a namespace collision. – Jonathon Anderson Sep 03 '14 at 22:27
  • @NonSecwitter In case of collision the order in which dependencies are mentioned in the classpath will take precedence, which I think should solve the problem. – Ajay George Sep 03 '14 at 22:31
  • @AjayGeorge how could i add this insruction i am using Netbeans so where could i put it – Firas252 Sep 03 '14 at 22:48
  • @Firas252 You just need to make sure NER_Recognizer.jar is the first entry in the classpath after which tagger.jar is mentioned. [How to set classpaths in Netbeans](http://stackoverflow.com/questions/7598623/how-to-setup-classpath-in-netbeans) – Ajay George Sep 03 '14 at 22:49
  • 1
    you where right its by rearranging them as you said it works so i have to choose the priority of the .jars thanks @AjayGeorge – Firas252 Sep 03 '14 at 22:55