|
From: Josh J. <j.j...@mc...> - 2006-08-08 03:10:32
|
Robert- Sorry for the delay in response. The first issue I see with the Jython code is that you do not subclass a Java class. If you are not using anything which requires subclassing, just subclass java.lang.Object as such: from java.lang import Object class PyClass(Object): ... As far as the error goes, I haven't ever seen any issues using 1.5 in my own environment. I can bet you that the assertion error has something to do with the subclassing...but don't quote me on that. There are several good articles on this topic. Check this one out which I wrote last month: http://wiki.python.org/jython/JythonMonthly/Articles/July2006/1 , it may help you out. For the posting question, I think you are best to post to everyone...that way we all learn from the discussion. Best to you- Josh ----- Original Message ----- From: "Robert Wierschke" <wi...@gm...> To: <jyt...@li...> Sent: Monday, August 07, 2006 4:54 AM Subject: [Jython-users] how to: compiling jython class to java byte code(detailed) > 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 > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |