This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Jython installation with Tomcat 4.1.12

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Willson, it's good to find someone like you who gives such information without being asked to.
Willson Wong
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!