Hi Richard,

Without seeing your java code, it's hard to state what exactly might be wrong.

But there is a simple conversion process that you need to go through to obtain a java object equivalent of a class implemented in jython.

The best way to illustrate this is with code that does it. Modjy is one example in the code base, that uses a servlet implemented in jython to provide WSGI capability to servlet containers.

The key piece of code is here.

http://hg.python.org/jython/file/45b3007473f9/src/com/xhaus/modjy/ModjyJServlet.java#l116

You should try that approach.

Alan.



On Tue, Apr 8, 2014 at 9:58 AM, Richard Eckart de Castilho <richard.eckart@gmail.com> wrote:
Hi all,

I want to define a class in Jython and instantiate it in Java.

I am using a Java framework which allows users to create custom
components (classes implementing specific interfaces). The framework
is built in such a way that it instantiates these components itself
based on a description containing a class name and a set of parameters.

My goal is to define a new component within Jython and to use it with
the framework. Here some pseudocode:

class MyComponent(Component):
 def run(self, *args):
   // do something

run(createComponent(MyComponent))

(btw. in Java I would have written: run(createComponent(MyComponent.class))

That gives me an error along the lines of

InitializationException: Component class "org.python.proxies.__main__$MyComponent$1" was not found.

Reading a bit in [1], I now believe that what I want to do is not really
possible without modifying the framework that I am using because classes
defined in Jython do not actually have a java.lang.Class instance
associated with them and there is actually no classloader which would be able
to return such an instance when Class.forName("org.python.proxies.__main__$MyComponent$1")
is called.

Is this correct, or is there a way to do what I want to do?

Cheers,

-- Richard

[1] http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users