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 hello2.py) 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 hello1.py 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.