Using JAR File distributions in Jython

Ype Kingma ykingma at accessforall.nl
Sat Jan 11 09:43:51 CET 2003


Ype Kingma wrote:

> VLP wrote:
> 
>> I have an API distributed in JAR form, that is currently being used by
>> some Java programs. I would like to use this API from Jython. I read
>> in an earlier post, that I must set CLASSPATH to include the JAR file
>> itself, not just the directory it is in, so I did accordingly. This
>> seems to have some effect, as the next time Jython started up, it
>> recognized the JAR file, and did some processing (notably adding it to
>> the cachedir package cache, and changing package.idx)
> 
> When jython does not repeat such indexing the next time you call jython
> with the jar on the class path you have the expected behaviour.
>  
>> However, I still cannot "import" any classes from the JAR file. I
>> tried following forms:
>> 
>> import com.company.product.api.class
>> and
>> from com.company.product.api import class
>> and
>> from com.company.product.api import *
>> 
>> I get the error:  No module named company
> 
> You might try this interactively:
> 
> Jython 2.1 on java1.3.1_04 (JIT: null)
> Type "copyright", "credits" or "license" for more information.
>>>> import com
>>>> dir(com)
> ['__name__', 'sun', 'ziclix']
> 
> to see what things are available in com. In this case there
> is nothing but the minimum on the class path (jython.jar).
> When there is a package com.company in a jar on the class path
> you should also see company mentioned.
> Note that 'company' should be a public java package.

Oops. I'm confusing java packages and classes here. Sorry.
Ype





More information about the Python-list mailing list