0

I have a public class Stm:

    package stm;

    import zemberek.morphology.apps.TurkishMorphParser;
    import zemberek.morphology.parser.MorphParse;

    import java.io.IOException;
    import java.util.List;

    public class Stm {
        TurkishMorphParser parser;


        public Stm(TurkishMorphParser parser) {
            this.parser = parser;
        }


        public void do_stm(String word) {
            System.out.println("Word = " + word);

            List<MorphParse> parses = parser.parse(word);
            for (MorphParse parse : parses) {

                System.out.println(parse.getStems());

            }
        }



        public static void main(String[] args) throws IOException {

            TurkishMorphParser parser = TurkishMorphParser.createWithDefaults();
            new Stm(parser).do_stm("ankaraya");

        }
    }

and aa.py as below :

    import jpype
    from jpype import *

    import os

    classpath = "/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/antlr-4.2.2-complete.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/guava-15.0.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/zemberek-core-0.9.0.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/zemberek-lm-0.9.0.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/zemberek-morphology-0.9.0.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/zemberek-tokenization-0.9.0-2.jar:/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/build/classes/stm/"

    startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=%s" % classpath)

    A = JClass('Stm')

    a = A()
    jpype.shutdownJVM()

running aa.py , I get this error:

    Traceback (most recent call last):

     File "aa.py", line 15, in <module>

    A = JClass('Stm')

    File "/usr/lib/python2.7/dist-packages/jpype/_jclass.py", line 54, in JClass

     raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)

    jpype._jexception.ExceptionPyRaisable: java.lang.Exception: Class Stm not found

I can call normal class in python but have problem in the project I have written in netbeans with imported some jar files. jar files are located

    /home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/jars/

I know problem is with classpath ! considering the jar files I used, how should I fill classpath part ????????????

Jeren
  • 153
  • 2
  • 4
  • 11

1 Answers1

0

The last entry on your classpath should be /home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/build/classes and you need to create class like A = JClass('stm.Stm'). Perhaps take a look how classes are arranged into packages. For example http://docs.oracle.com/javase/tutorial/java/package/packages.html

Radim
  • 4,721
  • 1
  • 22
  • 25
  • thanks for the answer but I still have same error: Traceback (most recent call last): File "aa.py", line 14, in A = JClass('stm.Stm') File "/usr/lib/python2.7/dist-packages/jpype/_jclass.py", line 54, in JClass raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) jpype._jexception.ExceptionPyRaisable: java.lang.Exception: Class stm.Stm not found – Jeren May 12 '14 at 13:17
  • Make sure the class is built (`/home/jeren/Desktop/Project/TweetParse/Parse_Tweets/stm/build/classes/stm/Stm.class` exists). Check Java version using by your Python library and by your Java compiler. Also when you resolve that you will need to add default (no-arg) constructor to instantiate `a = A()`. – Radim May 12 '14 at 13:50
  • Stm.class exists! how can I use constructor with arguments??? is it possible anyway??????? – Jeren May 12 '14 at 14:08
  • Check Java version using by your Python library and by your Java compiler ===> both use java 1.7 – Jeren May 12 '14 at 15:46
  • I solved it by changing the JDK I used from 1.6 to 1.7 .. thanks to Radim for comments :) – Jeren May 12 '14 at 17:46