From: Vincent G. <vin...@gm...> - 2008-11-12 04:29:59
|
I am a Python enthusiast with minimal exposure to Java. I need to collaborate on a project highly dependent on maven2+IntelliJ framework. Unfortunately, they also need to see results fast. Naturally, Jython comes to my mind. For example, I need to extend a class from java, implement my end of the code, jythonc it, which will then be called by the framework. I appreciate if someone could provide a quick how-to, or point me to docs to, or examples related to it,i need to kick-off and fast-track my development. In particular, how do you tell Jython where to find the class you want to derive? (thus, the --classpath equivalent). How do you integrate the output of jythonc back to the framework? TIA. |
From: <Amm...@su...> - 2008-11-12 08:25:19
|
I am also new to Python/Jython. You need to add the java classes to the PYTHONPATH. I use Eclipse with (PyDev/JyDT) and added the the respective java files into my External source folders. Look for it in Project Properties. Have no clue about your other issue Regards, Ammar ________________________________ From: Vincent Gulinao [mailto:vin...@gm...] Sent: den 12 november 2008 05:30 To: jyt...@li... Subject: [Jython-users] Integrating with maven2+IntelliJ framework I am a Python enthusiast with minimal exposure to Java. I need to collaborate on a project highly dependent on maven2+IntelliJ framework. Unfortunately, they also need to see results fast. Naturally, Jython comes to my mind. For example, I need to extend a class from java, implement my end of the code, jythonc it, which will then be called by the framework. I appreciate if someone could provide a quick how-to, or point me to docs to, or examples related to it,i need to kick-off and fast-track my development. In particular, how do you tell Jython where to find the class you want to derive? (thus, the --classpath equivalent). How do you integrate the output of jythonc back to the framework? TIA. |
From: Charlie G. <cha...@gm...> - 2008-11-14 17:40:28
|
On Tue, Nov 11, 2008 at 8:29 PM, Vincent Gulinao <vin...@gm...> wrote: > For example, I need to extend a class from java, implement my end of the > code, jythonc it, which will then be called by the framework. Do you need to jythonc it? You can extend Java classes without jythonc, and you can instantiate Python classes from Java without jythonc. I ask because jythonc is going away in 2.5, so it's not a good long term solution. > In particular, how do you tell Jython where to find the class you want to > derive? (thus, the --classpath equivalent). How do you integrate the output > of jythonc back to the framework? Jython finds code through the classpath, so if you have jython and your classes in your JVM, you can import your classes from Python and make subclasses of them. The same goes in reverse. The framework needs to be on the classpath at the same time, and you can use a technique along the lines of http://wiki.python.org/jython/JythonMonthly/Articles/October2006/3 to get your classes into it. Charlie |
From: Vincent G. <vin...@gm...> - 2008-11-19 11:41:01
|
Hi Charlie, I find your object factory solution very interesting. I tried it but I get the ff. error: Exception in thread "main" Traceback (innermost last): File "<string>", line 1, in ? ImportError: no module named Employee I tested inside Jython CLI it can properly import EmployeeType. What did I miss? On Sat, Nov 15, 2008 at 1:40 AM, Charlie Groves <cha...@gm...>wrote: > On Tue, Nov 11, 2008 at 8:29 PM, Vincent Gulinao > <vin...@gm...> wrote: > > For example, I need to extend a class from java, implement my end of the > > code, jythonc it, which will then be called by the framework. > > Do you need to jythonc it? You can extend Java classes without > jythonc, and you can instantiate Python classes from Java without > jythonc. I ask because jythonc is going away in 2.5, so it's not a > good long term solution. > > > In particular, how do you tell Jython where to find the class you want to > > derive? (thus, the --classpath equivalent). How do you integrate the > output > > of jythonc back to the framework? > > Jython finds code through the classpath, so if you have jython and > your classes in your JVM, you can import your classes from Python and > make subclasses of them. The same goes in reverse. The framework > needs to be on the classpath at the same time, and you can use a > technique along the lines of > http://wiki.python.org/jython/JythonMonthly/Articles/October2006/3 to > get your classes into it. > > Charlie > |
From: Vincent G. <vin...@gm...> - 2008-11-20 07:59:12
|
Looks like PythonInterpreter in the factory class is calling standard Python interpreter, not Jython. How do I make PythonInterpreter point to Jython instead then? On Wed, Nov 19, 2008 at 7:30 PM, Vincent Gulinao <vin...@gm...>wrote: > Hi Charlie, > > I find your object factory solution very interesting. I tried it but I get > the ff. error: > > Exception in thread "main" Traceback (innermost last): > File "<string>", line 1, in ? > ImportError: no module named Employee > > I tested inside Jython CLI it can properly import EmployeeType. > > What did I miss? > > On Sat, Nov 15, 2008 at 1:40 AM, Charlie Groves <cha...@gm...>wrote: > >> On Tue, Nov 11, 2008 at 8:29 PM, Vincent Gulinao >> <vin...@gm...> wrote: >> > For example, I need to extend a class from java, implement my end of the >> > code, jythonc it, which will then be called by the framework. >> >> Do you need to jythonc it? You can extend Java classes without >> jythonc, and you can instantiate Python classes from Java without >> jythonc. I ask because jythonc is going away in 2.5, so it's not a >> good long term solution. >> >> > In particular, how do you tell Jython where to find the class you want >> to >> > derive? (thus, the --classpath equivalent). How do you integrate the >> output >> > of jythonc back to the framework? >> >> Jython finds code through the classpath, so if you have jython and >> your classes in your JVM, you can import your classes from Python and >> make subclasses of them. The same goes in reverse. The framework >> needs to be on the classpath at the same time, and you can use a >> technique along the lines of >> http://wiki.python.org/jython/JythonMonthly/Articles/October2006/3 to >> get your classes into it. >> >> Charlie >> > > |
From: Vincent G. <vin...@gm...> - 2008-11-20 09:17:11
|
I figured it out, set python.path property. On Thu, Nov 20, 2008 at 3:59 PM, Vincent Gulinao <vin...@gm...>wrote: > Looks like PythonInterpreter in the factory class is calling standard > Python interpreter, not Jython. > > How do I make PythonInterpreter point to Jython instead then? > > > On Wed, Nov 19, 2008 at 7:30 PM, Vincent Gulinao < > vin...@gm...> wrote: > >> Hi Charlie, >> >> I find your object factory solution very interesting. I tried it but I get >> the ff. error: >> >> Exception in thread "main" Traceback (innermost last): >> File "<string>", line 1, in ? >> ImportError: no module named Employee >> >> I tested inside Jython CLI it can properly import EmployeeType. >> >> What did I miss? >> >> On Sat, Nov 15, 2008 at 1:40 AM, Charlie Groves <cha...@gm... >> > wrote: >> >>> On Tue, Nov 11, 2008 at 8:29 PM, Vincent Gulinao >>> <vin...@gm...> wrote: >>> > For example, I need to extend a class from java, implement my end of >>> the >>> > code, jythonc it, which will then be called by the framework. >>> >>> Do you need to jythonc it? You can extend Java classes without >>> jythonc, and you can instantiate Python classes from Java without >>> jythonc. I ask because jythonc is going away in 2.5, so it's not a >>> good long term solution. >>> >>> > In particular, how do you tell Jython where to find the class you want >>> to >>> > derive? (thus, the --classpath equivalent). How do you integrate the >>> output >>> > of jythonc back to the framework? >>> >>> Jython finds code through the classpath, so if you have jython and >>> your classes in your JVM, you can import your classes from Python and >>> make subclasses of them. The same goes in reverse. The framework >>> needs to be on the classpath at the same time, and you can use a >>> technique along the lines of >>> http://wiki.python.org/jython/JythonMonthly/Articles/October2006/3 to >>> get your classes into it. >>> >>> Charlie >>> >> >> > |
From: Vincent G. <vin...@gm...> - 2008-12-22 09:25:18
|
Moving on... In the factory class, I need to pass a Java class as parameter to the Python class constructor. In the example: {code}PyObject employeeObj = jyEmployeeClass.__call__(new PyString(first), new PyString(last), new PyString(id));{code} ... I need to pass a Java class instead of Python strings, something like: {code}PyObject employeeObj = jyEmployeeClass.__call__(new <???>(AJavaClass));{code} I tried PyJavaClass but it doesn't seem to work (can't find symbol). Please help. TIA. On Thu, Nov 20, 2008 at 5:17 PM, Vincent Gulinao <vin...@gm...>wrote: > I figured it out, set python.path property. > > > On Thu, Nov 20, 2008 at 3:59 PM, Vincent Gulinao < > vin...@gm...> wrote: > >> Looks like PythonInterpreter in the factory class is calling standard >> Python interpreter, not Jython. >> >> How do I make PythonInterpreter point to Jython instead then? >> >> >> On Wed, Nov 19, 2008 at 7:30 PM, Vincent Gulinao < >> vin...@gm...> wrote: >> >>> Hi Charlie, >>> >>> I find your object factory solution very interesting. I tried it but I >>> get the ff. error: >>> >>> Exception in thread "main" Traceback (innermost last): >>> File "<string>", line 1, in ? >>> ImportError: no module named Employee >>> >>> I tested inside Jython CLI it can properly import EmployeeType. >>> >>> What did I miss? >>> >>> On Sat, Nov 15, 2008 at 1:40 AM, Charlie Groves < >>> cha...@gm...> wrote: >>> >>>> On Tue, Nov 11, 2008 at 8:29 PM, Vincent Gulinao >>>> <vin...@gm...> wrote: >>>> > For example, I need to extend a class from java, implement my end of >>>> the >>>> > code, jythonc it, which will then be called by the framework. >>>> >>>> Do you need to jythonc it? You can extend Java classes without >>>> jythonc, and you can instantiate Python classes from Java without >>>> jythonc. I ask because jythonc is going away in 2.5, so it's not a >>>> good long term solution. >>>> >>>> > In particular, how do you tell Jython where to find the class you want >>>> to >>>> > derive? (thus, the --classpath equivalent). How do you integrate the >>>> output >>>> > of jythonc back to the framework? >>>> >>>> Jython finds code through the classpath, so if you have jython and >>>> your classes in your JVM, you can import your classes from Python and >>>> make subclasses of them. The same goes in reverse. The framework >>>> needs to be on the classpath at the same time, and you can use a >>>> technique along the lines of >>>> http://wiki.python.org/jython/JythonMonthly/Articles/October2006/3 to >>>> get your classes into it. >>>> >>>> Charlie >>>> >>> >>> >> > |
From: Charlie G. <cha...@gm...> - 2008-12-22 19:23:23
|
On Mon, Dec 22, 2008 at 1:25 AM, Vincent Gulinao <vin...@gm...> wrote: > ... I need to pass a Java class instead of Python strings, something like: > > {code}PyObject employeeObj = jyEmployeeClass.__call__(new > <???>(AJavaClass));{code} Try jyEmployeeClass.__call__(Py.java2py(AJavaClass)); Charlie |
From: Vincent G. <vin...@gm...> - 2008-12-23 02:40:05
|
Wow.. works like a charm. Are there more extensive tutorial/docs for Jython other than the User Guide and API doc floating around the web? Kindly point us to some of them. TIA. On Tue, Dec 23, 2008 at 3:23 AM, Charlie Groves <cha...@gm...>wrote: > On Mon, Dec 22, 2008 at 1:25 AM, Vincent Gulinao > <vin...@gm...> wrote: > > ... I need to pass a Java class instead of Python strings, something > like: > > > > {code}PyObject employeeObj = jyEmployeeClass.__call__(new > > <???>(AJavaClass));{code} > > Try jyEmployeeClass.__call__(Py.java2py(AJavaClass)); > > Charlie > |