Using JYTHON inside ANT : access os module -> "ImportError: no module named javaos"

E

eric_bellard

Using JYTHO inside ANT : access os module

Hi,

I like to use JYTHON inside ANT task.

I'm using:
- WSAD 5.1.1
- jython.jar inside WTE5.1
- bsf.jar inside WTE5.1

I've referenced jython.jar and bsf.jar into the ant classpath
(Windows>Preferences>Ant>Runtime>Classpath)

Here's a working script:

<project name="helloWorld" default="jython-hello-world" basedir=".">

<property name="test.path.dir" location="D:/tmp/jyton"/>
<target name="jython-hello-world">
<script language="jython">
<![CDATA[
import sys


print 'Hello Jytho World'
path = project.getProperty("test.path.dir")
print path

]]>
</script>
</target>
</project>


The problem is when I want to access to the ptyhon 'os' module.
The following target don't work:
<target name="jython-hello-world2">
<script language="jython">
<![CDATA[
import sys, os


print 'Hello Jytho World'
path = project.getProperty("test.path.dir")
print path
os.listdir(path)
]]>
</script>
</target>


The returned error is:

jython-hello-world:
[script] Hello Jytho World
[script] D:\tmp\jyton
[script] BUILD FAILED:
file:D:/cc_views/dinb_comp_java_jraf_v2_0_act_E391485/dinb_comp_java_jraf/livraison/jython/build.xml:63:
Traceback (innermost last):
File "<string>", line 8, in ?
ImportError: no module named javaos


Does someone has any clue?

Thanks by advance.

Eric
 
C

CarlosRivera

I ran into that one as well. I think that you have to have the PYTHON
path or classpath properly setup to reference them. I did not really
need anything from python, so I just used java routines for everything
as I was generating a manifest file.

Tip: Due to the forced indent from python, I moved the script to a
separate file. This way the code can look like a normal jython/python
script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top