[opencms-dev] J-Python integration

Scott Newham scott at wranglers.com.au
Fri Jul 18 03:20:02 CEST 2003


Paul

>Scott,
>
>         Thanks for posting this email. I have a few questions (see below).
>
>At Thursday 7/17/03 03:34 PM, Scott Newham wrote:
>>As part of my investigations I've integrated Python scripting into a JSP 
>>so that I can interactively call OpenCMS internals to learn how they work 
>>and automate some development tasks.
>>
>>Jython is an implementation of Python on a JVM.
>
>         Actually, Jython is a compiler. It compiles Python source code to 
>Java byte code that can be executed in a Java virtual machine (JVM).

It's more than a compiler because there's runtime support (written in Java) to support Python semantics and to bridge the gaps between the languages. But this is really getting off the point...

>>  The Python code compiles down to Java byte code and allows a virtually 
>> seamless mix of Java and Python. You can subclass Java classes in Python 
>> and lots more. I find I always use it when doing Java work because it 
>> allows rapid investigation without needing a compile/debug cycle.
>
>         I am not certain that I understand this phrase, "allows rapid 
>investigation without [requiring] a compile-debug cycle." Could you please 
>explain?

I use Jython at the command shell to create some java objects and call their methods with various arguments - the sort of thing you might write a test app to find out how things work. 
This would normally require opening an editor, writing a class, compiling and running but because you can run Jython interactively (and because it has other short cuts) I find it more productive.

>>  I'm finding this [ practice (i.e., use of Jython) to be] of greater 
>> benefit in OpenCMS because of the latency in editing and publishing JSPs.
>
>         Does your use of Jython save you time? If so, how much? How much 
>faster is it to develop in Jython than JSP? Would the answer to that 
>question change if OpenCMS could be integrated with a powerful web 
>application development framework (WADF) such as Struts, Barracuda, or Web 
>Works? I suspect that, if OpenCMS could be integrated with a powerful WADF, 
>developement time could be considerably reduced. Recently, on 
>JavaLobby.org, there was a discussion of WADF's and the extent to which 
>they could be combined.

I'm not using it as a replacement to JSP but that's possible though it would be slower. My point was related to the earlier one about using Jython to investigate methods. I find this helpful in OpenCMS and other systems that don't have much documentation about the interfaces. For example  I wanted to find out how a "web user" differed to a regular user and in fact whether this stuff still worked at all. So I quickly scripted up some calls to create a user and ran it from my python JSP within OpenCMS. What makes it quick is not having to edit a JSP within OpenCMS which is a slow process compared to changing a line of python and resubmitting my web form in seconds.

I could imagine using some scripts to populate an environment with users and resources for testing purposes. The scripts execute within a running opencms.

I hadn't seriously thought about the issues you raise about Struts etc.

>         I presume that there are WADF's for Jython, too. Do you know of 
>any? Do you use one?

No, sorry but you've got me thinking about it.

>>    <snip>
>>
>>Jython is available from <http://www.jython.org/>http://www.jython.org/
>>
>>1. Install Jython.
>>2. Put a copy of jython.jar in your opencms\WEB-INF\lib directory.
>>3. Add -Dpython.home=C:\jython21 to the java startup of opencms. (Using 
>>the path where your jython is installed).
>>4. Add the following JSP. I call it "py". It's very basic - I just knocked 
>>it up to get it working. It could be improved vastly but I really just 
>>wanted it to work so I could get on with other stuff.
>
>         Scott, I thank you for outlining how to integrate Jython with 
>OpenCMS. I used to be a "server-side Java bigot" until I discovered that 
>many smart programmers think that Python is a better designed language than 
>Java. Most of my initial OpenCMS programming will probably be done in JSP, 
>but I will probably switch to Jython unless third party tools improve 
>considerably. One such tool is OpenCMSstruts, which is meant to integrate 
>Struts into OpenCMS. See 
>http://sourceForge.net/projects/opencmsStruts  .  If you learn of similar 
>tools for those who program for OpenCMS using the Jython compiler, please 
>post that information to the list.
>
>Sincerely,
>Paul Bain

I don't look at it as Java versus Python as each has its benefits and suitability to different things. Note that Python (the original C based one) has been used to write some decent sized systems such as Zope. I use them for different things and in this case Jython complements Java. It's also handy for adding scripting to Java apps.

Thanks for your questions and comments. I hope it's of use to some people.

Scott

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20030718/57b2ecd3/attachment.htm>


More information about the opencms-dev mailing list