Can I use Gephi compiled with IKVM on a website?

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.

+4
source share
1 answer

This is a Java classloader issue. In a command line application, your main executable acts as a system class loader and knows how to load assembly failures, but there is no main executable in the web process, so the system class loader does not know how to load anything useful.

One solution is to call ikvm.runtime.Startup.addBootClassPathAssemby () to add the appropriate assemblies to the bootloader loader.

For more information about IKVM class loading issues, see http://sourceforge.net/apps/mediawiki/ikvm/index.php?title=ClassLoader

0
source

Source: https://habr.com/ru/post/1447592/


All Articles