[Nesstar-api-dev] Using Nesstar API from .Net. Dependency resolution.

Ørnulf Risnes ornulf.risnes at nsd.uib.no
Tue Feb 19 15:13:28 CET 2013

Hi, Nesstar-API-dev mailing list.

We have received some questions from communities using .Net, but who still wants to be able to use the Java based Nesstar API.

There are two main issues: 1) Developing with Java libraries in a .Net environment

2) Resolving dependencies (since .Net doesn't have/integrate Maven which is the preferred way of resolving dependencies in Java)

The guide below will resolve both issues in one. We recommend that you use a throwaway Maven-based setup in the middle there, to avoid having to manage dependencies manually. In a follow-up to this email, we will share the *current* (but soon probably outdated) dependency tree.

Guide: ============

*Step by step guide for creating a ready to use nesstar-api.dll*

This guide contains example commands typed in a bash shell. Converting them to cmd.com should be trivial, but is beyond the scope of this guide.

* Download and install the tool for creating .dll files from java classes, IKVM (http://www.ikvm.net/).

* Set a system variable pointing to where you installed IKVM:

$ IKVM_HOME=/usr/lib/ikvm

* Download a simple java project that use the nesstar-api, just to get its maven config:

$ git clone https://github.com/nesstar/nesstar-api-demo.git

(If you do not have git installed, you can download the project as a zip file from github: https://github.com/nesstar/nesstar-api-demo/archive/master.zip)

* Since the nesstar-api has several dependencies (about 40 versioned jars), resolving them manually is a daunting task. Let Maven do the job for you:

* Download and install maven (http://maven.apache.org/download.cgi)

* Standing at the root of the nesstar-api-demo project you just downloaded, issue the following maven command:

$ mvn dependency:copy-dependencies

This will download all the needed jars into the target/dependency folder. This concludes our maven usage.

* Now cd into target/dependency and run the ikvm command to assemble the .dll:

$ cd target/dependency $ $IKVM_HOME/ikvmc.exe -target:library *.jar -r:$IKVM_HOME/IKVM.OpenJDK.Core.dll -r:$IKVM_HOME/IKVM.Runtime.dll -out:nesstar-api-0.6.3.dll

This command should output lots of noise in the console, and end up producing a nesstar-api-0.6.3.dll file

* Import the nesstar-api-0.6.3.dll into your IDE and start coding. If you want, you can delete the nesstar-api-demo project folder. Remember that some datastructures in java libraries are not compatible with datastructures in .Net, so try to stick to conservative techniques for dealing with datastructures.

The following C# code will list all studies on the nesstar-demo server (note the awkward iterator technique):

using System; using com.nesstar.api; using java.net;

namespace NesstarStudyLister {

class MainClass {

public static void Main (string[] args) {

NesstarDB nesstarDB = NesstarDBFactory.getInstance();

Server server = nesstarDB.getServer(new URI("http://nesstar-demo.nsd.uib.no"));

NesstarList allStudies = server.getBank(java.lang.Class.forName("com.nesstar.api.Study")).getAll();

java.util.Iterator iter = allStudies.iterator();

while (iter.hasNext()) {

com.nesstar.api.Study study = (com.nesstar.api.Study)iter.next();




} }

Hope this makes sense. Please feed back if you have comments.

-- Best regards Ørnulf Risnes Head of Software Development Section Norwegian Social Science Data Services (NSD) Tel.: +47 55 58 89 16

More information about the Nesstar-api-dev mailing list