From: Anatoly A. <ana...@gm...> - 2004-12-22 16:28:10
|
Hello everybody again, As a new user of Jython a new difficult came up to me again. Now I am trying to compile a class defined in a Python script to Java class and use it from Java as a Java class. The class defined in Python doesn't inherit from any Java class or interface. So what I do is: byte[] byteCode = imp.compileSource("test.HelloTest", someFileWithPythonClas); Class clazz = BytecodeLoader.makeClass("test.HelloTest$py", null, byteCode); this call is failed with NullPointerException: java.lang.NullPointerException at org.python.core.SyspathJavaLoader.loadClass(SyspathJavaLoader.java) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at org.python.core.BytecodeLoader.findParentClass(BytecodeLoader.java) at org.python.core.BytecodeLoader2.loadClass(BytecodeLoader2.java) at java.lang.ClassLoader.loadClass(ClassLoader.java:235) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537) at org.python.core.BytecodeLoader2.loadClassFromBytes(BytecodeLoader2.java) at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java) ............... ............... Can any help me? Or tell another way to do that. Thank you! Anatoly |
From: Jeff E. <jem...@fr...> - 2004-12-22 16:47:21
|
I think to make the Python class accessible like a Java class, you need to run jythonc. Jythonc understands @sig declarations. I helped someone on the list to run jythonc programmatically about a year ago or so. See http://article.gmane.org/gmane.comp.lang.jython.user/2130 Anatoly Atanasov wrote: > Hello everybody again, > >As a new user of Jython a new difficult came up to me again. Now I am >trying to compile a class defined in a Python script to Java class and >use it from Java as a Java class. The class defined in Python doesn't >inherit from any Java class or interface. >So what I do is: >byte[] byteCode = imp.compileSource("test.HelloTest", someFileWithPythonClas); >Class clazz = BytecodeLoader.makeClass("test.HelloTest$py", null, byteCode); > >this call is failed with NullPointerException: >java.lang.NullPointerException > at org.python.core.SyspathJavaLoader.loadClass(SyspathJavaLoader.java) > at java.lang.ClassLoader.loadClass(ClassLoader.java:235) > at org.python.core.BytecodeLoader.findParentClass(BytecodeLoader.java) > at org.python.core.BytecodeLoader2.loadClass(BytecodeLoader2.java) > at java.lang.ClassLoader.loadClass(ClassLoader.java:235) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) > at java.lang.ClassLoader.defineClass0(Native Method) > at java.lang.ClassLoader.defineClass(ClassLoader.java:537) > at org.python.core.BytecodeLoader2.loadClassFromBytes(BytecodeLoader2.java) > at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java) > >............... >............... > >Can any help me? Or tell another way to do that. > >Thank you! >Anatoly > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://productguide.itmanagersjournal.com/ >_______________________________________________ >Jython-users mailing list >Jyt...@li... >https://lists.sourceforge.net/lists/listinfo/jython-users > > |
From: Jim A. <ji...@tr...> - 2004-12-22 18:57:23
|
I'm not sure if this is the same as what you're asking, but can you use '__builtin__.compile' ? Maybe something along these lines would work for you : compiledCode = __builtin__.compile(PythonCode, showFile, "exec"); jython.exec( compiledCode ); PyJavaInstance pyJavaInstance = (PyJavaInstance)jython.get("MyObjectInstance"); ... (at this point poke around in your debugger and look at 'jython' to see what's in there ...) On Dec 22, 2004, at 8:28 AM, Anatoly Atanasov wrote: > Hello everybody again, > > As a new user of Jython a new difficult came up to me again. Now I am > trying to compile a class defined in a Python script to Java class and > use it from Java as a Java class. The class defined in Python doesn't > inherit from any Java class or interface. > So what I do is: > byte[] byteCode = imp.compileSource("test.HelloTest", > someFileWithPythonClas); > Class clazz = BytecodeLoader.makeClass("test.HelloTest$py", null, > byteCode); > > this call is failed with NullPointerException: > java.lang.NullPointerException > at > org.python.core.SyspathJavaLoader.loadClass(SyspathJavaLoader.java) > at java.lang.ClassLoader.loadClass(ClassLoader.java:235) > at > org.python.core.BytecodeLoader.findParentClass(BytecodeLoader.java) > at > org.python.core.BytecodeLoader2.loadClass(BytecodeLoader2.java) > at java.lang.ClassLoader.loadClass(ClassLoader.java:235) > at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) > at java.lang.ClassLoader.defineClass0(Native Method) > at java.lang.ClassLoader.defineClass(ClassLoader.java:537) > at > org.python.core.BytecodeLoader2.loadClassFromBytes(BytecodeLoader2.java > ) > at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java) > > ............... > ............... > > Can any help me? Or tell another way to do that. > > Thank you! > Anatoly > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real > users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |