]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Loading VTK dlls with plug-in activator. 21/3521/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 14 Nov 2019 15:38:15 +0000 (17:38 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 14 Nov 2019 15:38:15 +0000 (17:38 +0200)
gitlab #50

Change-Id: Iae39a7d1e38e48156a532b5002b7c88edfa1d709

vtk/META-INF/MANIFEST.MF
vtk/src/vtk/Activator.java [new file with mode: 0644]
vtk/src/vtk/vtkJavaDep.java
vtk/src/vtk/vtkObjectBase.java

index 641b1d16d7946ea312ad22092378bf279c28a3ce..ac7adfe2a57725019236c4702d11eda9d01e2893 100644 (file)
@@ -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 (file)
index 0000000..98031ca
--- /dev/null
@@ -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 {
+        
+    }
+
+}
index c482235a307ae3bb561359f7ba29380b195ea7f0..0377199e106ffde0ed74802a5f147a5d45d9f936 100644 (file)
@@ -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;
+           }
        }
 }
index 5b88cd51664da62ab34e87904cff2e983601aecd..539aa966be433b597de6a4648fa08e2b99349494 100644 (file)
@@ -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);
 }