4

I'm running jEdit with the JythonInterprete and I have a .jar file called JavaTest.jar.

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

From my .py file, I want to do:

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 the JythonInterpreter, I have already tried clicking "Edit Jython Path" and adding the .jar file then running the interpreter again, but it still gives me ImportError: cannot import name SampleJavaClass

2
  • Isn't it supposed to be the package name, not the .jar name? Commented May 25, 2010 at 15:33
  • My Java package's name is javatest (I apologize for the poor choice of names). When I change it to from javatest import SampleJavaClass, I now get "ImportError: cannot import name SampleJavaClass" I'll add my java code to the question. Commented May 25, 2010 at 15:38

1 Answer 1

2

You need to add the JavaTest.jar to the Java classpath used by jEdit. The Jython path is used to tell Jython where the Python modules are, the Java classpath is used to tell the JVM where the Java jars are. In order to access javatest.SampleJavaClass in Jython the JVM must first be able to find it. It will then make it available to the Jython interpreter and your code should run.

I'm not that familiar with how to set the JVM classpath in jEdit but I did find this wiki page which may hold the answer.

Sign up to request clarification or add additional context in comments.

1 Comment

I confirm that putting the jar in jars directory makes it visible to Jython.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.