File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Jython/Python and the fly likes Jython installation with Tomcat 4.1.12 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Jython installation with Tomcat 4.1.12" Watch "Jython installation with Tomcat 4.1.12" New topic

Jython installation with Tomcat 4.1.12

Willson Wong

Joined: Jun 11, 2003
Posts: 3
Just wanted to post my recent experiences installing Jython on my Mandrake 8.2 server so I could run servlets written in Jython. I found that I could not import the standard java modules other than sys in my servlets. The error I kept encountering was "ImportError: Could not import module java" or something to that effect.
Interestingly, when I ran Jython on the console, import java went without a hitch. I think I know what happened now, because I got it fixed finally (after 2 days).
My script (in file is as follows:

I followed essentially the guide provided here: Jywiki
I downloaded the jython-21.class file from sourceforge and then ran the following:

Possible Problem 1 :
I installed the jython files into the /home/Jython-2.1 directory. This made it inaccessible to tomcat; maybe it was the directory name or maybe it was outside of the search tree.
Possible Problem 2 :
The classpath to the java libraries may have been undefined.
Solution :
In any case, the problems listed above were solved when I installed it into /usr/local/jython as follows:

Then I changed the appropriate entry in web.xml for python.home to point to /usr/local/jython
This fixed everything and now tomcat is happy to serve the file as a servlet.
I read thru some of the mailing lists and I see some people having the same problem. I followed the fixes recommended in those mailing lists but it didn't help me. So I had to come out with my own solution. Hope this helps anyone who has encountered a similar problem with Jython. Jython is really nice to use.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Thanks Willson, it's good to find someone like you who gives such information without being asked to.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Willson Wong

Joined: Jun 11, 2003
Posts: 3
Thanks for the encouragement. I have learnt a lot from the documented difficulties of others and now that I have a solution, it is only fair I contribute my share.
New discovery over the weekend: I can do page forwarding from a Jython servlet.
Been reading Jython Essentials and Jython for Java Programmers which are very informative, but have not been able to find documentation on how to do this (needed for a Controller in the MVC paradigm). It seems that all the methods available to a normal Java Servlet is also available to a Jython Servlet.
The following snippet worked for me:
I agree. Here's the link:
subject: Jython installation with Tomcat 4.1.12
It's not a secret anymore!