habe versucht aus Java aus ein JAR Archiv welches mit Jython erzeugt wurde aufzurufen.
Code: Alles auswählen
//CallJython.java
import java.lang.reflect.Method;
public class CallJython {
private static Method[] methods;
public static void main(String[] args) {
MyClass my = new MyClass();
methods = my.getClass().getMethods();
for(Method m: methods)
System.out.println(m);
my.method1();
}
}
Code: Alles auswählen
#MyClass.py
class MyClass:
attr1 = 10 # class attributes
attr2 = "hello"
def method1(self):
print MyClass.attr1 # reference the class attribute
def method2(self, p1, p2):
print MyClass.attr2 # reference the class attribute
def method3(self, text):
self.text = text # instance attribute
print text, self.text # print my argument and my attribute
Code: Alles auswählen
jythonc -c -j myjar.jar MyClass.py
Ohne my.method1() bekomme ich diese Ausgabe:
Code: Alles auswählen
public static void MyClass.moduleDictInit(org.python.core.PyObject)
public static void MyClass.main(java.lang.String[]) throws java.lang.Exception
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public native int java.lang.Object.hashCode()
public final native java.lang.Class java.lang.Object.getClass()
public boolean java.lang.Object.equals(java.lang.Object)
public java.lang.String java.lang.Object.toString()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
Code: Alles auswählen
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method method1() is undefined for the type MyClass
at CallJython.main(CallJython.java:11)
Aber leider wird my.method1() nicht gefunden. Woran kann es liegen?
Viele Gruesse