Hello. I'm new to python / jython.

There was a problem: you need to download files from a specific directory.
Local, no problem

for name in glob.glob("%s/*.json" % some_path): log.debug(name) definition = json.loads(file(name).read()) 

The problem is this: the main application to java is distributed as jar (s), and all resources are also located in jar'e.

The path to the resource folder is defined in jave:

 URL resourceURL = CommonMethods.class.getClassLoader().getResource(resourceName); String resourcePath = resourceURL.getPath(); String dirPath = resourcePath.substring(0, resourcePath.lastIndexOf("/")+1); 

If the resource is in jar'e, then we get

 dirPath="file:/opt/lib/core-lib-1.0.jar!/rulz/" 

And glob.glob() doesn't work, I think file(name).read() too. :(

Tell me how to read python files from jar'a?

    1 answer 1

    But this will not work?

     def show_jar_classes(jar_file): """prints out .class files from jar_file""" zf = zipfile.ZipFile(jar_file, 'r') try: lst = zf.infolist() for zi in lst: fn = zi.filename if fn.endswith('.class'): print(fn) finally: zf.close() 

    That is, we act as if jar is equivalent to zip (picked up here ).

    • one
      jar this is a zip-archive, everything is correct - etki
    • thanks a lot, it works !!! - Igorku