Hi again,

so in the meantime I've tried to implement all the various examples as shown in the book under section "Using Jython within Java Applications". Unfortunately none of them works within eclipse, which is quite a pity. Also, sadly under chapter " Using Jython in an IDE"  it is nowhere mentioned how to actually invoke python from Java in eclipse via Jython, only the other way round showing how to use Java in Python/Jython, which unfortunately is not what I'm looking for. Any hints?



-------- Original Message --------
Subject: Re: [Jython-users] Eclipse + Jython = Call Python from Java does not work
Date: Wed, 09 Nov 2011 11:40:00 +0100
From: Philipp Zech <zech.ph@gmail.com>
Reply-To: zech.ph@gmail.com
To: jython-users@lists.sourceforge.net

On 11/08/2011 10:48 PM, Pierre Thibault wrote:
2011/11/8 Philipp Zech <zech.ph@gmail.com>
so now, if trying to get an instance of a python class via the object
factory, as done according to the above mentioned book, i get the error
that one of my modules, namely building (building.py) is not found,
however the package itself (base) is found. I kinda assume this is due
to the java interface implemented by the python class and that it's not
found, however, up to now, i couldn't figure a way out on how to resolve
this issue. Maybe someone can give me a hint on what I'm doing wrong.
Any help will be appreciated!
Thanks in advance!



As I see, are you importing "building"? I think you need to import "from base import building". building is inside the package base.


Pierre Thibault

Python Developer/Développeur Python
Montréal, QC

RSA(R) Conference 2012
Save $700 by Nov 18
Register now

Jython-users mailing list
Hi Pierre,

thanks for your answer, however, there should be anything wrong with my importing statements (see below):

        public JythonObjectFactory (Class<?> interfaceType, String moduleName, String className)
            this.interfaceType = interfaceType;
            final PyObject importer = state.builtins.__getitem__(Py.newString("__import__"));
            final PyObject module = importer.__call__(Py.newString(moduleName));
            clazz = module.__getattr__(className);sepp

so the above method is ued to get the module and based on it get an instancen of the pythonclass Building (defined inside building .py). In the main method of this small program i create a buildiongFactory and try to get an isntance of building via the following code:

        JythonObjectFactory buildingFactory = new JythonObjectFactory(BuildingType.class, "base.building", "Building");
        BuildingType building = (BuildingType) buildingFactory.createObject();

as can be seen from those two code excerpts, i actually try to import the module "building" from the package "base", however, no success so far. Interestingly, if I start to mess around with the package name, i.e.: replacing it by "foo", the python interpreter claims that this very module named "foo" cannot be found, which is true, as it is non-existent (see below):

        JythonObjectFactory buildingFactory = new JythonObjectFactory(BuildingType.class, "foo.building", "Building");

leads to

        Exception in thread "main" Traceback (innermost last):
          (no code object) at line 0
        ImportError: no module named foo

yet, changing the package name back to "base" leads to the previous error:

        Exception in thread "main" Traceback (innermost last):
          (no code object) at line 0
        ImportError: No module named building

This kinda looks like the package can be found, yet the module cannot be created, yet I have no clue why this happens...again, maybe someone out there can give me the needed hint!

thanks again in advance!