Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Jython/Python and the fly likes Jython use in a web-app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Jython use in a web-app" Watch "Jython use in a web-app" New topic

Jython use in a web-app

Roger Studner

Joined: Aug 26, 2005
Posts: 6
I have the following piece of code:
public static void executeJob(Job job) throws Exception {
PythonInterpreter pyi = new PythonInterpreter();
pyi.set("job", job);pyi.execfile(EngineUtil.class.getResourceAsStream(""));

The 'execution script' starts with that line:
from import *

When I run it from the command line in a java app with a main (with all relevant stuff on the classpath) everything works.

When I try to run the exact same piece of code inside a web-app (therefore all class files and jars are deployed to /project/WEB-INF (jython.jar in lib, classes in WEB-INF/classes of course).

I got the error:
Traceback (innermost last):
File "<iostream>", line 2, in ?
ImportError: no module named com

at org.python.core.Py.ImportError(
at org.python.core.imp.import_first(
at org.python.core.imp.import_name(
at org.python.core.imp.importName(
at org.python.core.ImportFunction.load(
at org.python.core.ImportFunction.__call__(
at org.python.core.PyObject.__cal

etc etc.

Why, in a web-app deployment, can the python interpreter not find any of the classes to import?

Any ideas?

I agree. Here's the link:
subject: Jython use in a web-app
It's not a secret anymore!