From: Marko Luukkainen Date: Thu, 14 Nov 2019 15:38:15 +0000 (+0200) Subject: Loading VTK dlls with plug-in activator. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=3523a218827de60e1aa4ce7be126342418ddb054;p=simantics%2F3d.git Loading VTK dlls with plug-in activator. gitlab #50 Change-Id: Iae39a7d1e38e48156a532b5002b7c88edfa1d709 --- diff --git a/vtk/META-INF/MANIFEST.MF b/vtk/META-INF/MANIFEST.MF index 641b1d16..ac7adfe2 100644 --- a/vtk/META-INF/MANIFEST.MF +++ b/vtk/META-INF/MANIFEST.MF @@ -6,3 +6,6 @@ Bundle-Version: 8.2.0.qualifier Automatic-Module-Name: vtk Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Export-Package: vtk +Bundle-ActivationPolicy: lazy +Bundle-Activator: vtk.Activator +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.13.0" diff --git a/vtk/src/vtk/Activator.java b/vtk/src/vtk/Activator.java new file mode 100644 index 00000000..98031ca8 --- /dev/null +++ b/vtk/src/vtk/Activator.java @@ -0,0 +1,19 @@ +package vtk; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + @Override + public void start(BundleContext context) throws Exception { + vtkJavaDep.load(); + + } + + @Override + public void stop(BundleContext context) throws Exception { + + } + +} diff --git a/vtk/src/vtk/vtkJavaDep.java b/vtk/src/vtk/vtkJavaDep.java index c482235a..0377199e 100644 --- a/vtk/src/vtk/vtkJavaDep.java +++ b/vtk/src/vtk/vtkJavaDep.java @@ -8,7 +8,6 @@ package vtk; */ public class vtkJavaDep { static String[] libs = new String[] { - "jawt", "vtksys", "vtkCommonCore", "vtkWrappingJava", @@ -121,20 +120,28 @@ public class vtkJavaDep { "vtkIOImportJava", }; + + private static boolean loaded = false; + static void load() { + if (!loaded) { - static { - try { - Class.forName("java.awt.Toolkit"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException(e); - } + try { + Class.forName("java.awt.Toolkit"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException(e); + } + try { + System.loadLibrary("jawt"); + } catch (UnsatisfiedLinkError e) { + // bypass potential load error. If jawt is not really loaded, we will get errors + // with VTK dlls. + } - for (String lib : libs) - System.loadLibrary(lib); - } - - static void load() { + for (String lib : libs) + System.loadLibrary(lib); + loaded = true; + } } } diff --git a/vtk/src/vtk/vtkObjectBase.java b/vtk/src/vtk/vtkObjectBase.java index 5b88cd51..539aa966 100644 --- a/vtk/src/vtk/vtkObjectBase.java +++ b/vtk/src/vtk/vtkObjectBase.java @@ -44,7 +44,6 @@ public class vtkObjectBase public static vtk.vtkJavaMemoryManager JAVA_OBJECT_MANAGER = new vtk.vtkJavaMemoryManagerImpl(); public vtkObjectBase() { - vtkJavaDep.load(); this.vtkId = this.VTKInit(); vtkObjectBase.JAVA_OBJECT_MANAGER.registerJavaObject(this.vtkId, this); }