From 733096baa3e355fd6942fb7d9b6a90a90b913971 Mon Sep 17 00:00:00 2001 From: Kenneth Lausdahl Date: Wed, 4 Nov 2020 11:49:50 +0100 Subject: [PATCH] fixed #14 --- .../java/org/intocps/fmi/jnifmuapi/DirectoryFmu.java | 9 +++++---- .../main/java/org/intocps/fmi/jnifmuapi/NativeFmu.java | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/DirectoryFmu.java b/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/DirectoryFmu.java index a3bd370..85e5ee0 100644 --- a/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/DirectoryFmu.java +++ b/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/DirectoryFmu.java @@ -65,10 +65,10 @@ public DirectoryFmu(File path, String name) throws FmuInvocationException this.dir = path; this.name = name; - if (!NativeFmu.isNativeApiLoaded()) - { - throw new FmuInvocationException("Native fmuapi library not loaded. Check log for more information."); - } +// if (!NativeFmu.isNativeApiLoaded()) +// { +// throw new FmuInvocationException("Native fmuapi library not loaded. Check log for more information."); +// } } @@ -151,6 +151,7 @@ public void internalLoad(File libraryPath) throws FmuInvocationException, FmuMis } logger.debug("Loading FMU library: {}", libraryPath); + NativeFmu.loadNativeApi(); // load dll synchronized (lock) { diff --git a/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/NativeFmu.java b/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/NativeFmu.java index e77bfbf..14ea288 100644 --- a/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/NativeFmu.java +++ b/jnifmuapi/src/main/java/org/intocps/fmi/jnifmuapi/NativeFmu.java @@ -52,8 +52,12 @@ interface ICallback static private boolean isLoaded; - static + public static void loadNativeApi() { + if(isLoaded) + { + return; + } String libPath = NativeFmuApi.getPlatformSpecificLibaryPath("fmuapi"); logger.debug("Loading library: " + libPath); File lib; @@ -64,9 +68,9 @@ interface ICallback isLoaded = true; } catch (Exception e) { - logger.error("Faild to load native Library file: " + libPath, e); - // throw new RuntimeException( "Unable to load native library fmuapi",e); + logger.error("Failed to load native Library file: " + libPath, e); isLoaded = false; + throw new RuntimeException("Failed to load native Library file: " + libPath, e); } }