I use -Djava.ext.dirs=WHATEVER to load in all the jar files in the directory WHATEVER. The key line of my startup script looks like the following:

exec "${JAVA}" -Dpython.home="${JYTHON_HOME}" -Dpython.path="${PYTHONPATH}" -Djava.ext.dirs="${EXT_DIRS}"  org.python.util.jython "$@"

- David



Date: Wed, 03 Dec 2008 11:31:36 -0600
From: David Niergarth <dn@hddesign.com>
Subject: [Jython-users] How best to deal with a bunch of .jar files?
To: jython-users@lists.sourceforge.net
Message-ID: <4936C278.8050000@hddesign.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,

I need some basic help understanding how best to manage Jython scripts
that need access to lots of jar files (CLASSPATH, sys.path, registry).
I'm using Debian Lenny with Jython 2.2.1 on java1.6.0_0 (installed as
the standard packages).

I'm using Jython to script Jasper Reports (an open-source Java reporting
library), which has a lot of dependencies (it's /lib subdirectory
contains 45 jar files).

To get things working, I have added the full paths to all 45 jar files
to my CLASSPATH environment variable (2,690 characters). It also works
if I add the jar paths to the registry's python.path property and unset
CLASSPATH (or jython -Dpython.path=/long/path1:/long/path2:..., although
that's pretty unwieldy).

My questions are:

  1. Is there a less-verbose way to load so many jars? (Like a way to
point to just the directory containing the jars?)

  2. I had a lot of problems and confusion that went away once I
started clearing out cachedir before running my scripts. For example, my
CLASSPATH went subtly wrong at one point and fixing it didn't seem to
help until I cleared the cachedir. What is the cachedir doing?

In case it helps clarify what I'm doing, here's a brief example script:

    import glob

    from java.util import HashMap
    from java.io import File

    from net.sf.jasperreports.engine import JasperFillManager
    from net.sf.jasperreports.engine.data import JRXmlDataSource

    reports = glob.glob('*.jasper')

    for report in reports:
        f = File('report_description.xml')
        xmlDataSource = JRXmlDataSource(f)
        JasperFillManager.fillReportToFile(report, HashMap(),
                                           xmlDataSource)

Thanks,

--David