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

Discussion in 'Python' started by eric_bellard, Oct 5, 2004.

  1. eric_bellard

    eric_bellard Guest

    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
     
    eric_bellard, Oct 5, 2004
    #1
    1. Advertising

  2. eric_bellard

    CarlosRivera Guest

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

    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.

    eric_bellard wrote:
    > 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
     
    CarlosRivera, Oct 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bedford
    Replies:
    6
    Views:
    2,245
  2. David McNab
    Replies:
    0
    Views:
    499
    David McNab
    Apr 9, 2004
  3. Maurice LING

    Using Jython in Ant Build Process

    Maurice LING, Apr 21, 2005, in forum: Python
    Replies:
    2
    Views:
    535
    Kent Johnson
    Apr 21, 2005
  4. Divya Prakash
    Replies:
    0
    Views:
    442
    Divya Prakash
    Dec 19, 2006
  5. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    355
    Pinegar, Kent T
    Jul 24, 2008
Loading...

Share This Page