python - Unable to import Java classes from Jython module -



python - Unable to import Java classes from Jython module -

note: found solution , answered myself. though, have no thought why setting wrong , caused problem. i'm still interested in having explanation how jython import scheme works; if cares gain bounty please reply that.

i'm working on existing java ee project need computations in python. i'm @ first stages of integration tests i'm facing issue. read chapter 10 of jython book still can't find solution. read chapter 8 (modules , packages code reuse) me it'is unclear.

an explanation of how jython import scheme works , how configure appreciated.

the problem:

$ jython -v import: 'exceptions' org.python.core.exceptions in builtin modules jython 2.5.3 (2.5:c56500f08d34+, aug 13 2012, 14:54:35) [java hotspot(tm) server vm (oracle corporation)] on java1.7.0_10 import: import site # precompiled /home/me/jython/2.5.3/lib/site$py.class import: 'sys' sys in builtin modules import: import os # precompiled /home/me/jython/2.5.3/lib/os$py.class import: 'errno' org.python.modules.errno in builtin modules import: 'posix' org.python.modules.posix.posixmodule in builtin modules import: import posixpath # precompiled /home/me/jython/2.5.3/lib/posixpath$py.class import: import stat # precompiled /home/me/jython/2.5.3/lib/stat$py.class import: 'java' java bundle import: 'file' java class import: 'ioexception' java class import: 'org' java bundle import: 'py' java class type "help", "copyright", "credits" or "license" more information. >>> import pendulum.generator.buildingtype import: import pendulum # precompiled /path/to/project/build/classes/pendulum/__init__$py.class import: import pendulum.generator # precompiled /path/to/project/build/classes/pendulum/generator/__init__$py.class traceback (most recent phone call last): file "<stdin>", line 1, in <module> importerror: no module named buildingtype

my question is: doing wrong , how prepare things import buildingtype interface successfully? maybe problem stands in classpath, have no thought value appropriate.

code organization:

$ tree build/classes/pendulum/generator/ src/pendulum/generator/ build/classes/pendulum/generator/ ├── buildingtype.class ├── __init__.py └── __init__$py.class src/pendulum/generator/ ├── buildingtype.java └── __init__.py

import path defined private jython registry file:

$ cat ~/.jython python.path=\ /path/to/project/build/classes:\ /path/to/project/src:\ /home/me/jdevel/extras/2.5.3/lib:\ /home/me/jdevel/extras/2.5.3/lib/site-packages

i'm sure jython picks paths because checked sys.path @ jython prompt.

buildingtype.java

package pendulum.generator; public interface buildingtype { public string getbuildingname(); public string getbuildingaddress(); public string getbuildingid(); }

you need set classpath python.path.

with same directory layout, works me:

jython10$ classpath=build/classes/ jython -v building.py import: 'exceptions' org.python.core.exceptions in builtin modules import: import site # precompiled /usr/local/java/jython2.5.3/lib/site$py.class import: 'sys' sys in builtin modules import: import os # precompiled /usr/local/java/jython2.5.3/lib/os$py.class import: 'errno' org.python.modules.errno in builtin modules import: 'posix' org.python.modules.posix.posixmodule in builtin modules import: import posixpath # precompiled /usr/local/java/jython2.5.3/lib/posixpath$py.class import: import stat # precompiled /usr/local/java/jython2.5.3/lib/stat$py.class import: java bundle '/users/sdm7g/jaxp/jython10/build/classes/pendulum' import: 'pendulum' java bundle import: 'pendulum' java bundle import: java bundle '/users/sdm7g/jaxp/jython10/build/classes/pendulum/generator' import: 'pendulum.generator' java bundle import: 'buildingtype' java class

reference: working classpath (jython book).

java python import jython

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -