Calling Jython code from Java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raja

    Calling Jython code from Java

    I have a java class thats trying to call something in python. This
    works fine when i do a jythonc on the python script.
    When i call another python script from the __init__ of my called
    python script, things go bad.i get this message
    AttributeError: class 'configuration' has no attribute
    'configuration'
    when calling the constructor.
    This is my python script thats called by the java class
    testconfig.py
    =============
    import configuration
    import java.lang

    class testconfig(java .lang.Object):

    def __init__(self):
    """@sig public testconfig()"""
    self._cfg = configuration.c onfiguration("/sources/jmxproto")

    def getValue(self, whatVar):
    pass

    and the other script is configuration.p y
    class configuration:

    def __init__(self, runtimeDir=None ):
    """@sig public configuration(j ava.lang.String dir)"""
    """ Some code in here """

    When i call testconfig.py, i get the error mentioned above. Any clues?

    Thanks
    Raja
  • Derek Thomson

    #2
    Re: Calling Jython code from Java

    Raja wrote:[color=blue]
    > I have a java class thats trying to call something in python. This
    > works fine when i do a jythonc on the python script.[/color]

    [snip]
    [color=blue]
    >
    > class testconfig(java .lang.Object):
    >
    > def __init__(self):
    > """@sig public testconfig()"""
    > self._cfg = configuration.c onfiguration("/sources/jmxproto")[/color]

    [snip]
    [color=blue]
    > class configuration:
    >
    > def __init__(self, runtimeDir=None ):
    > """@sig public configuration(j ava.lang.String dir)"""
    > """ Some code in here """
    >
    > When i call testconfig.py, i get the error mentioned above. Any clues?[/color]

    In Python, you just use the class name to create instances.

    So I think that perhaps:

    self._cfg = configuration.c onfiguration("/sources/jmxproto")

    Should be:

    self._cfg = configuration("/sources/jmxproto")

    IIRC the "@sig" declaration only comes into play when attempting to use
    the class from *Java* code. That's why there is no "configurat ion"
    attribute.

    Regards,
    Derek.



    Comment

    Working...