0

i am using a local .jar file in my eclipse project which loads a .dll itself:

private static void ForceReloadLibraryPath() {
/*      */       try {
/*  731 */          Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
/*  732 */          fieldSysPath.setAccessible(true);
/*  733 */          fieldSysPath.set((Object)null, (Object)null);
/*      */ 
/*  735 */       } catch (NoSuchFieldException var1) {
/*      */ 
/*  737 */          System.out.println("Failed to adapt the java library path!");
/*      */ 
/*  739 */       } catch (IllegalAccessException var2) {
/*      */ 
/*  741 */          System.out.println("Failed to adapt the java library path!");
/*      */       }
/*      */ 
/*  744 */    }
/*      */ 
/*      */    static {
/*  752 */       String bitness = System.getProperty("sun.arch.data.model");
/*  753 */       String libpath = System.getProperty("java.library.path");
/*  763 */       boolean retry = false;
/*      */ 
/*      */       do {
/*  766 */          retry = false;
/*      */ 
/*      */ 
/*      */          try {
/*  770 */             System.setProperty("java.library.path", libpath);
/*  771 */             ForceReloadLibraryPath();
/*  772 */             System.loadLibrary("AdsToJava");
/*      */ 
/*  774 */          } catch (UnsatisfiedLinkError var6) {
/*      */ 
/*      */ 
/*  777 */             if (var6.getMessage().equals("no AdsToJava in java.library.path")) {
/*      */ 
/*  779 */                System.out.println("AdsToJava.dll not found. Check your PATH environment variable!");
/*      */ 

I am adding the AdsToJava.dll like properties -> build path -> Libraries -> JRE System Library -> Native Library Location but get the error messages

Failed to adapt the java library path!

no AdsToJava in java.library.path:...

The first message seem to be rather insignificant - i tried the same project on another laptop where I get the first message but not the second one and everything works properly. The second line I do not understand - I am adding the correct dll to the library path it should be there. Thank you for any suggestions!

umpapa
  • 55
  • 1
  • 8
  • In newer versions of Java ClassLoader doesn't have a field called `sys_path` and even if it did Java will no longer let you change it like that. – greg-449 Oct 20 '21 at 12:27
  • Do you understand how it was possible to load that library nonetheless?(from the other laptop, which uses a new version too) – umpapa Oct 20 '21 at 12:51
  • You can always try `System.load` which lets you specify the full path directly. – greg-449 Oct 20 '21 at 14:13

0 Answers0