From: Sébastien B. <seb...@te...> - 2016-05-14 09:16:43
|
Hi all, Replying to my own question, it seems that I was kinda tired yesterday afternoon, because this morning I could easily find some ressources explaining the phenomenon, indeed. So far, I've found a thread from 2008 http://python.6.x6.nabble.com/Problem-importing-Java-packages-td1773276.html and as long as I import classes instead of packages, everythong is fine (using the standalone mode). I have also found some information in the Jython Book[1] which led me to use 'jython' (not the standalone version), with the '-Djava.ext.dirs="/dir/with/my/jar(s)/inside/" I guess this is sufficient for me starting to use jython. I have also seen that it is possible to repack the .jar to provide the necessary classes inside a single jar, for distribution [2], so I keep that under the pillow. In any case, if I forgot an obvious solution with the standalone jython in particular, I'd be glad to here from it; especially because it is simpler to use. And I say something wrong, I'd be grateful that someone points them --I'm just starting to use jython. Best regards, __ Sébastien. [1] http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html#how-jython-finds-the-jars-and-classes-to-scan [2] https://wiki.python.org/jython/LearningJython#id62 On Fri, 13 May 2016 17:59:23 +0200 Sébastien Bigaret <seb...@te...> wrote: > Hi all, > > I have currently a problem with imports I do not understand. > This is what happens (Jython 2.7.0, java 1.8.0u66, on debian 8): > > ----8< ---- 8< ---- > ./jython.sh > Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11) > [Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_66 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys; sys.path > ['', '/path/to/XMCDA-java.jar', '/home/bigaret/lang/python/Lib', '/home/bigaret/lang/python/jython-standalone-2.7.0.jar/Lib', '__classpath__', '__pyclasspath__/'] > >>> import org.xmcda.parsers.xml # this one fails here.... > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > ImportError: No module named xmcda > >>> from org.xmcda.parsers.xml.xmcda_3_0 import XMCDAParser > >>> import org.xmcda.parsers.xml # ...but now it succeeds > >>> org.xmcda.parsers.xml > <java package org.xmcda.parsers.xml 0x2> > >>> sys.path > ['', '/path/to/XMCDA-java.jar', '/home/bigaret/lang/python/Lib', '/home/bigaret/lang/python/jython-standalone-2.7.0.jar/Lib', '__classpath__', '__pyclasspath__/'] > ----8< ---- 8< ---- > > > Note that the first import fails, while the last (which is the same statement) succeeds --and sys.path was untouched, there is just an import between the two identical imports) > > Does someone has any hint why I get such a strange behaviour, or can point me to the right documentation to read? I could unfortunately not find any hint on such peculiarities when searching in jython's doc or on the web in general. > > Thanks in advance, > > __ Sébastien. > > > NB: The jython.sh is a simple bash script: > > ----8< ---- 8< ---- > #! /bin/bash > JAVA=/usr/local/java8/bin/java > JYTHON_STANDALONE_JAR=/home/bigaret/lang/python/jython-standalone-2.7.0.jar > XMCDA_LIB="/path/to/XMCDA-java.jar" > > export JYTHONPATH="${XMCDA_LIB}" > > "${JAVA}" -cp "${JYTHON_STANDALONE_JAR}" org.python.util.jython > ----8< ---- 8< ---- > > (and I have the same behaviour when adding XMCDA_LIB to the java '-cp' argument. > |