Re: Problem with imports

Sébastien Bigaret <[email protected]> Sat, 14 May 2016 11:16:22 +0200
Newsgroups gmane.comp.lang.jython.user
Organization Télécom Bretagne
Message-ID <[email protected]>
    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 <[email protected]> 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.
>

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users
signature.asc (application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQIcBAEBAgAGBQJXNuzmAAoJEHU8D0nY/H+mQ44P/0Clft/4/Ad0DPL6QM4mfk3u
gu2rjlO55jFG1O+bl+Yc3hLVwNeKCUNAw/ukxY26JSKxYEjD49E/E4AE70dRAB+E
9YKdYyfxCX/YZ+MidhDJFMQ3IoS+n0dq2Qfblfecxh66KQ8oo9EWSiUoXkTtcmaO
npa9xvLKtKrwHev2K8pyHnJEjG/5kRJnEEGF6WVY4Zh785DYWji7ey4UuzEslMxL
GEjJdx68H0JrJ5kiLelCp5o9YxJGpERA7NaUH8WprxPfN+k7InpwBmH/U7NL7yTL
MUpvHANoW1D+bf0QeHGMPISE5pjuDqn0YbSuhugC/PJIjia8QJNmsIpBSZkUm39D
qK71n7sU6yoR0UCWo9xJXKlj35rD77DdteDp4yB5rSOBzcVHynaPfrYVLomhDtvO
g1VSL5yAe/kIwKgBPqCokOhtPKuRrmiv6bT9pKVa1dwV8uIFwks8E6rq9g8oIt2i
EfvJ3NKTsbAfD+EiQjD7Tp+bkp/HSzc7AsSQyu19+1gn51Xpq60LftQKb8NRjlzG
bUCedAn1eSo7+1/Vt14Q93ncFYHMTR5q7pMEu4C3fRrJ9PWQGhT7si+b9Xmds3BY
1DHzk3if3bO9EmasYNu0ppEl76HUTbIGNymv6XJc4H1YAISf1Ra/S08OCtm20Oz7
P6w8DUWgVLbVSlyJCrxa
=Vw5b
-----END PGP SIGNATURE-----