I am currently trying to download and use the Gephi Toolkit on a .Net 4 C # website.
I have a version of the jar file of a toolkit compiled against an IKVM virtual machine that works as expected from a command line application using the following code:
var controller = (ProjectController)Lookup.getDefault().lookup(typeof(ProjectController)); controller.closeCurrentProject(); controller.newProject(); var project = controller.getCurrentProject(); var workspace = controller.getCurrentWorkspace();
Three instances are correctly created in a form similar to org.gephi.project.impl.ProjectControllerImpl@8ddb93 .
If, however, I run the same code, with the same use of operators and references, the very first line loading the instance of ProjectController returns null.
I tried a couple of solutions
First, I tried to ignore the call to Lookup.getDefault (). lookup (type), instead tried to create its own instances:
var controller = new ProjectControllerImpl(); controller.closeCurrentProject(); controller.newProject(); var project = controller.getCurrentProject(); var workspace = controller.getCurrentWorkspace();
This does not work in the line controller.newProject (); I think because internally (using a reflector) the same Lookup.getDefault (). lookup (type) is used in the constructor, returns null and then throws an exception.
Secondly, from here: Search in Jython (and Gephi) I tried to set% CLASSPATH% to the location of both the JAR tool files and the DLL.
Is there any reason Lookup.getDefault () is. Will lookup (type) not work in a web environment? I'm not a Java developer, so I'm a bit out of the depths of my Java side.
I would have thought that you could create all instances yourself, but could not find a way to do this.
I also cannot find a way to see why load ProjectController returned null. No exception is thrown, and if I'm not very stupid, there seems to be no way to see the result of a download attempt.
Update - Answer
Based on the answer from Jeroen Frijters, I solved the problem as follows:
public class Global : System.Web.HttpApplication { public Global() { var assembly = Assembly.LoadFrom(Path.Combine(root, "gephi-toolkit.dll")); var acl = new AssemblyClassLoader(assembly); java.lang.Thread.currentThread().setContextClassLoader(new MySystemClassLoader(acl)); } } internal class MySystemClassLoader : ClassLoader { public MySystemClassLoader(ClassLoader parent) : base(new AppDomainAssemblyClassLoader(typeof(MySystemClassLoader).Assembly)) { } }
The code ikvm.runtime.Startup.addBootClassPathAssemby() did not seem to work for me, but from the provided link I managed to find a solution that seems to work in all cases.