Desperately Seeking Classpaths

Poster Content
nk4um Moderator
Posts: 901
April 13, 2008 08:02Superstack ClassLoader
By the way - a default classloader will load from the module, lib, and then imported modules (public exported classes).  You can also construct a superstack classloader that will also find classes in the request address space hierarchy *above* the currently requested module.  here is what mod-db does to load the JDBC driver...

// initialise JDBC driver
URRequest request = context.getKernelHelper().getThisKernelRequest();
SuperStackClassLoader cl = new SuperStackClassLoader(request);
Class c = cl.loadClass(jdbcDriver);


A superstack classloader lets a library service use classes from the context of the calling application.  All the scripting languages do this (even  languages like XQuery - thanks Menzo ;-))

P
Like · Post Reply
nk4um Moderator
Posts: 901
April 13, 2008 07:40ClassPath Trace Tool
Carlos,

The NK java classpath is dynamically constructed and follows your module relationship graph.  We provide a classpath trace tool that lets you probe the dynamic classpath...

http://localhost:1060/ep+name@app_ext_introspect_classtrace

Also you are probably using the base JVM classloader when doing Class.forName() - this is the lowest common denominator and due to the Java classloader model can only know about the initial boot classpath of the JVM.  To be safe you should use the context classloader Thread.currentThread.getContextClassLoader()

Peter
Like · Post Reply
nk4um User
Posts: 54
April 13, 2008 00:47
From the docs for the SQL module:

The mod_db module includes JDBC JAR files for the HSQLDB and the MySQL database management systems. If you wish to connect to another database management system you must place the appropriate JDBC JAR file into the /lib directory within your application module.


I have the MySQL jar file, mysql-connector-java-5.1.6-bin.jar, in the /lib folder of my module. When I run my accessor, which is doing a Class.forName("com.mysql.jdbc.Driver"), the class is not found. The JDBC_readme.txt file located in modules/mod-db/lib says to place the JAR files in the says:

Place your JDBC driver jar in this directory to be automatically picked up by the classloader.


So, is it the mod-db/lib folder or the module''s /lib folder? Or should either work?

And following Menzo''s advice, I added <class>com\\.mysql\\.jdbc.\\..*</class> to  <export>, but the driver was still not found.
Like · Post Reply
nk4um Administrator
Posts: 158
April 12, 2008 11:15JDBC tests
Carlos,

Access to relational databases is supported by mod_db which provides services such as active:sqlQuery. This gets its configuration from the resource ffcpl:/etc/ConfigRDBMS.xml. The configuration resource specifies the specific JDBC driver class to be used in the connection (along with other information).

I have not tested this but I would think you could devise your existence test by simply making a request to active:sqlQuery and provide it with a configuration that specifies a class from the JDBC driver JAR you are looking for. If it succeeds, then you know the JAR is there, if it fails (throws an exception) then you can presume that the JAR is not found on the resolution path.

Randy



Like · Post Reply
nk4um User
Posts: 111
April 12, 2008 07:45use <class/> in <export/>
Hi,

In the module.xml file of the module containing the classes you add a <class/> child to the export section, e.g.


    <export>
        <uri/>
        <class>
            <match>the\\.exported\\.package\\..*</match>
        </class>
    </export>


Hope this helps,

Menzo
Like · Post Reply
nk4um User
Posts: 54
April 12, 2008 03:37Desperately Seeking Classpaths
I have an accessor in a module. I have a uri that uses this accessor in another module. The accessor executes a Class.forName(). Whose ClassLoader is being used? The accessor''s or the module using the accessor?

I have a JDBC driver whose existence I would like to check. My accessor, in module #1, does not contain the JDBC driver. Module #2 has a lib folder which contains the jar file that contains the driver. When I run the accessor from module #1 in module #2 the accessor does not find the driver.

How would I get this to work? Hints, please.
Like · Post Reply