Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jython use in a web-app  RSS feed

 
Roger Studner
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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("JobRunner.py"));
pyi.execfile(EngineUtil.class.getResourceAsStream("StepFactory.py"));
pyi.exec(job.getExecutionScript());
}

The 'execution script' starts with that line:
from com.company.blah.blah 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(Py.java:193)
at org.python.core.imp.import_first(imp.java:523)
at org.python.core.imp.import_name(imp.java:592)
at org.python.core.imp.importName(imp.java:625)
at org.python.core.ImportFunction.load(__builtin__.java:1006)
at org.python.core.ImportFunction.__call__(__builtin__.java:999)
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?

Thanks,
Roger
oreoferret@gmail.com
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!