Jython ImportError when embedding into Java on 'xml.dom.minidom'

767 Views Asked by At

I have a python script which is processing XML using xml.dom.minidom. When I executed it with Jython by command line (jython myfile.py), everything was fine. But when I tried to do the same thing embedding it into a java application, (I mean reading it as an java string then passing this string for evaluation) I got:

import xml.dom.minidom ImportError: No module named xml

Which is driving me crazy. I tried to use different jython version (2.2, 2.5), to clear the cache, but nothing works!

Jython's Documentation tells me that we can use this module without any particular remarks.

Some people had the same problem on the internet but never got any replies. Except this: here but still nothing work. I think I have the correct values in my jython registry, because it's working using the command line! It's just the embedding which fails everything.

I'm using a full install of Jython.

Why so much trouble, so?

Thanks in advance.

2

There are 2 best solutions below

0
On

i've never done this before, but are you trying to embed jython like they did here or here? do you know where you got the jython.jar in your java classpath from? if you know where your jython module is located on disc then you might be able to just add that path as they did at the bottom of this page. To find the location of your module, load up jython and look in sys.path for a path that ends in Lib. that location should have a directory named xml (the xml package) which contains a directory named dom (the dom package), which contains a file minidom.py (the minidom module).

0
On

The xml module (jython) isn't on the the python-path of your embedded jython.

This may help:

  • use a jython-jar which contains the Lib (and all the Batteries :-)
  • put the Libs on the classpath of your java app

to help debug:

log "sys.path" in your embedded jython