Hacking Jena and Mono/C#

After a short discussion with AndyS on #jena I reengaged on writing a C# application (using Mono) that uses Jena. Compiling all the ARQ-1.2 .jars to CIL using ikvmc was an easy job:

ikvmc commons-logging.jar log4j-1.2.12.jar  -out:log4j.dll -target:library
ikvmc stax-api-1.0.jar wstx-asl-2.8.jar xercesImpl.jar xml-apis.jar \
 resolver.jar -out:xml.dll -target:library
ikvmc antlr-2.7.5.jar arq.jar concurrent.jar icu4j_3_4.jar \
jakarta-oro-2.0.8.jar jena.jar -reference:xml.dll -reference:log4j.dll \
 -out:arq.dll -target:library

A short test if the Jena classes are working was derived from an example of the Jena documentatio and worked out just fine… replacing import with using and omitting the trailing .* gave quick working results.

The hard part starts if it comes to persistent Jena Models. I am using MySQL, so I ikvmced the Java MySQL 3.2alpha driver and used the following code segment as learned from the docs:

  System.Activator.CreateInstance("mysql32alpha", 
     "com.mysql.jdbc.Driver");

  IDBConnection idbcon = new  DBConnection("jdbc:mysql://db-server-2/jena23", 
     "jdbc", "password", "MySQL");

mysql32alpha is the name of the assembly where the class com.mysql.jdbc.Driver is to be found. Compiling the code went well, running it resulted in Exception: Failure to instantiate DB Driver:MySQL java.lang.NullPointerException. So, I droppt the ikvm developers a line… awaiting an answer. Hang on for updates

UPDATE 1: With the devine intervention of “reinstall and configure your tool chain” I did that, currently running:

goern@node-236:~/src/mono/ARQ-1.2$ ikvm -version
CLR version: 1.1.4322.2032 (32 bit)
System: 1.0.5000.0
IKVM.Runtime: 0.22.0.0
IKVM.GNU.Classpath: 0.22.0.0
ikvm: 0.22.0.0
mscorlib: 1.0.5000.0
GNU Classpath version: 0.19
goern@node-236:~/src/mono/ARQ-1.2$ mono --version
Mono JIT compiler version 1.1.13.1, (C) 2002-2005 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV      : normal

Redoing the build process I got the ARQ and MySql .dlls and my binary, compiled just fine and runs fine. JDBC Connection is opned up, Jena Model gets opened and all the content dumped to Console. Having all the good tools in place two point araise:

  1. Determining the Language you use is hard! C# just looks like Java to me at the moment:

    using System; using com.hp.hpl.jena.rdf.model; using com.hp.hpl.jena.db;

    public class hodge { public static void Main() { IDBConnection idbcon = null; ModelMaker maker = null; Model model = null;

           System.Activator.CreateInstance("mysql32alpha",
            "com.mysql.jdbc.Driver");
    
    
           idbcon = new  DBConnection("jdbc:mysql://server/jena23", 
            "user", "pass", "MySQL");
           if (idbcon == null)
                   Console.WriteLine("no IDBConnection");
    
    
           try {
                   maker = ModelFactory.createModelRDBMaker(idbcon);
                   model = maker.openModel("pim");
           } catch (Exception e) {
                   Console.WriteLine("Exception: " + e.Message);
           }
    
    
           Console.WriteLine(model); // model.write(System.out);
    

    } }

  2. C# and Mono world seems to be open for Jena.

PS: I have attached a [distribution][6] that contains a nant build file for the tasks above and the source code, just configure at top of build.build.

PPS: I have not tested this under some MS Windows.

[6]: http://b4mad.net/2006/01/20/jena-sharp.tar.gz