JEdit + JythonInterpreter: how to import a java class?

I am running jEdit with JythonInterprete and I have a .jar file called JavaTest.jar.

JavaTest has a SampleJavaClass class, which has a printerCount method.

From my .py file I want to make:

from javatest import SampleJavaClass class SampleClass(SampleJavaClass): def pymain(self): SampleJavaClass.printerCount(4) 

Java Code:

 package javatest; public class SampleJavaClass { public static void printerCount(int i){ for(int j=0; j< i; j++){ System.out.println("hello world"); } } (etc...) 

In JythonInterpreter, I already tried clicking "Change Jython path" and add the .jar file, and then run the interpreter again, but it still gives me ImportError: cannot import name SampleJavaClass

+4
source share
1 answer

You need to add JavaTest.jar to the Java path used by jEdit. The Jython path is used to indicate to Jython where the Python modules are located, the Java classpath is used to indicate to the JVM where the Java banks are located. To access javatest.SampleJavaClass in Jython, the JVM must first find it. It will then be available to the Jython interpreter and your code should work.

I don't know how to install the JVM classpath in jEdit, but I found this wiki page that may contain an answer.

+2
source

Source: https://habr.com/ru/post/1310871/


All Articles