From: Robert W. <wi...@gm...> - 2006-08-07 09:53:46
|
Sorry for posting twice but my fist mail wasn't detailed enough. I want to use a Jython class in a Java class, so here is the source code of the classes. The classes a not really useful they are only for testing and get familiar with Jython. =========== PyClass.py ============== class PyClass: def echo(self, msg): "@sig public java.lang.String echo(java.lang.String msg)" ret = "selber: " + msg return ret ========= JyUser.java ================= public class JyUser { public static void main(String[] args) { PyClass py = new PyClass(); System.out.println(py.echo("echo")); } } The command jythonc PyClass.py produces the following error message: ========================================================= Compiling .java to .class... Compiling with args: ['C:\\Programme\\Java\\jdk1.5.0_01\\bin\\javac.exe', '-classpath', 'D:\\jython-2.1\\jython.jar;;.\\jpywork;;D:\\jython-2.1\\Tools\\jythonc;C:\\Dokumente und Einstellungen\\Robert\\Desktop\\jyc\\.;D:\\jython-2.1\\Lib;D:\\jython-2.1', '.\\jpywork\\PyClass.java'] 1 D:\jython-2.1\org\python\core\Py.java:989: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier (try -source 1.3 or lower to use 'assert' as an identifier) public static void assert(PyObject test, PyObject message) { ^ D:\jython-2.1\org\python\core\Py.java:995: as of release 1.4, 'assert' is a keyword, and may not be used as an identifier (try -source 1.3 or lower to use 'assert' as an identifier) public static void assert(PyObject test) { ^ D:\jython-2.1\org\python\core\Py.java:996: ')' expected assert(test, Py.None); ^ D:\jython-2.1\org\python\parser\PythonGrammar.java:6739: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier (try -source 1.4 or lower to use 'enum' as an identifier) for (java.util.Enumeration enum = jj_expentries.elements(); enum.hasMoreElements();) { ^ D:\jython-2.1\org\python\parser\PythonGrammar.java:6739: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier (try -source 1.4 or lower to use 'enum' as an identifier) for (java.util.Enumeration enum = jj_expentries.elements(); enum.hasMoreElements();) { ^ D:\jython-2.1\org\python\parser\PythonGrammar.java:6740: as of release 1.5, 'enum' is a keyword, and may not be used as an identifier (try -source 1.4 or lower to use 'enum' as an identifier) int[] oldentry = (int[])(enum.nextElement()); ^ D:\jython-2.1\org\python\core\Py.java:996: incompatible types found : org.python.core.PyObject required: boolean assert(test, Py.None); ^ D:\jython-2.1\org\python\core\PyBeanProperty.java:36: warning: non-varargs call of varargs method with inexact argument type for last parameter; cast to java.lang.Object for a varargs call cast to java.lang.Object[] for a non-varargs call and to suppress this warning Object value = getMethod.invoke(iself, Py.EmptyObjects); ^ ========================================================= Question 1: I get it compiled with the command jythonc -J "-source 1.3" PyClass.py but I still get warnings. The 1.3 option is necessary because jythonc generates methodes named assert, which is a keyword since java 1.4 an I'm using jdk 1.5. So I wander if I made something wrong or Jython is only compatible with Java 1.3??? If I try to compile the java class file I get the following error message. ========================================================= JyUser.java:4: cannot find symbol symbol : method echo(java.lang.String) location: class PyClass System.out.println(py.echo("echo")); ^ 1 error ========================================================= Note that I already fixed the problem of finding the class (only a wrong classpath) but now I can't access the method of the Jython class also I used the @sig-docstring. Question 2: How to use Jython classes/methods from Java? A general question on using this mailing list: How to answer on mails? Replay to the sender or post a new message to the mailing list? thanks robert |