You can see that it is going to use the ClassLoader of the calling class, which in this case is the class of the third-party library. So to solve this you need to align the ClassLoader of the third-party lib with the ClassLoader of what tries to load the native library first. You could try enabling class loading trace and look for when that third-party class is loaded, and back up from there to find the ClassLoader.
Native Library Already Loaded In Another Classloader Tomcat
Download
https://0tiara-0tracko.blogspot.com/?sktt=2wWmyg
Usually a class that uses a native library will have a static initializer that loads the library. This way the class and the native library will always be loaded in the same class loader. With OpenCV the application code loads the native library.
Now there's the restriction that a native library can only be loaded in one class loader. Web applications use their own class loader so if one web application has loaded a native library, another web application cannot do the same. Therefore code loading native libraries cannot be put in a webapp directory but must be put in the container's (Tomcat) shared directory. When you have a class written with the usual pattern above (loadLibrary in static initializer of using class) it's enough to put the jar containing the class in the shared directory. With OpenCV and the loadLibrary call in the web application code however, the native library will still be loaded in the "wrong" class loader and you will get the UnsatisfiedLinkError.
I need to have a separate instance of the native library for each of mywebapps as each instance needs to contain data that is unique to thatparticular webapp. I have searched through the mail archives and reademails by Craig McLanahan explaining the classloader hierarchy. But Ihavenot been able to find anything specific to loading a unique instance of anative library for each webapp.
The problem is due to some configurations of your application server which cause to create more than one war or ear files and consequently it creates more than one deployed files. These deployed files attempt to have a concurrent access to your native library which loaded in a static block.
The problem got resolved after the Command 2 got executed leading to another situation wherein I am able to access the SQL Server Camunda Database successfully but unable to use the sqljdbc_auth dll for my Custom Application database with the error - Native Library sqljdbc_auth.dll already loaded in another classloader.
I have added the sqljdbc jar to the $TOMCAT_HOME lib folder and the DLL extension to the $TOMCAT_HOME bin folder and I am using the Camunda Tomcat Distribution for my Custom Application as well.
com.zebra.sdk.comm.UsbNativeCodeConnectionException: The native code dll is not loaded. at com.zebra.sdk.printer.discovery.UsbDiscoverer.getZebraUsbPrinters(Unknown Source) [ZSDK_API.jar]
And I cannot use LinkOs anymore.
The only solution for me is to restart tomcat service, after this the linkOS libraries work again.
java.lang.UnsatisfiedLinkError: Native Library ZebraNativeUsbAdapter_32.dll already loaded in another classloader
I should avoid the server reload because I have to stop all my applications instead of just the updated one.
Upon further research, the java.lang.UnsatisfiedLinkError: Native Library [...]\sqljdbc_auth.dll already loaded in another classloader, is caused when Java is attempting to load a native library after already loading it once.
If you have that code in multiple apps, one solution might be to move the code that calls System.loadLibrary() from the applications to a shared library, and associate the library with the applications using a commonLibraryRef. The commonLibraryRef creates a separate class loader for the shared library that the application class loaders would delegate to, and since the library would only be defined from that shared library class loader, the "already loaded in another classloader" situation would not occur.
You cannot share sessions directly across web apps, as that would be a violation of the Servlet Specification. There are workarounds, including using a singleton class loaded from the common classloader repository to hold shared information, or putting some of this shared information in a database or another data store. Some of these approaches have been discussed on the tomcat-user mailing list, whose archives you should search for more information.
The important thing to know about using JNI under Tomcat is that one cannot place the native libraries OR their JNI interfaces under the WEB-INF/lib or WEB-INF/classes directories of a web application and expect to be able to reload the webapp without restarting the server. The class that calls System.loadLibrary(String) must be loaded by a classloader that is not affected by reloading the web application itself.
The JDBC jar you have for sqlserver should be moved from being bundled with your wars, to the tomcat 7.0/lib folder and copy the sqljdbc_auth.dll to tomcat/bin folder - this way it will be in the tomcat parent classloader, and the class will only be loaded once.
Library Search Paths A search for a given library will scan the following locations: jna.library.path User-customizable path jna.platform.library.path Platform-specific paths On OSX, /Library/Frameworks, /Library/Frameworks, and /System/Library/Frameworks will be searched for a framework with a name corresponding to that requested. Absolute paths to frameworks are also accepted, either ending at the framework name (sans ".framework") or the full path to the framework shared library (e.g. CoreServices.framework/CoreServices). Context class loader classpath. Deployed native libraries may be installed on the classpath under $os-prefix/LIBRARY_FILENAME, where $os-prefix is the OS/Arch prefix returned by Platform.getNativeLibraryResourcePrefix(). If bundled in a jar file, the resource will be extracted to jna.tmpdir for loading, and later removed (but only if jna.nounpack is false or not set). You may set the system property jna.debug_load=true to make JNA print the steps of its library search to the console.Author:Wayne Meissner, split library loading from Function.java, twallField SummaryFields Modifier and TypeField and Description(package private) intcallFlags (package private) Mapoptions Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and TypeMethod and Descriptionstatic voidaddSearchPath(String libraryName, String path)Add a path to search for the specified library, ahead of any system paths.voiddispose()Close the native library we're mapped to.(package private) static voiddisposeAll()Close all open native libraries.protected voidfinalize()Close the library when it is no longer referenced.FilegetFile()Returns the file on disk corresponding to this NativeLibrary instance.FunctiongetFunction(String functionName)Create a new Function that is linked with a native function that follows the NativeLibrary's calling convention.FunctiongetFunction(String functionName, int callFlags)Create a new Function that is linked with a native function that follows a given calling flags.FunctiongetFunction(String functionName, int callFlags, String encoding)Create a new Function that is linked with a native function that follows a given calling flags.(package private) FunctiongetFunction(String name, Method method)Create a new Function that is linked with a native function that follows the NativeLibrary's calling convention.PointergetGlobalVariableAddress(String symbolName)Look up the given global variable within this library.static NativeLibrarygetInstance(String libraryName)Returns an instance of NativeLibrary for the specified name.static NativeLibrarygetInstance(String libraryName, ClassLoader classLoader)Returns an instance of NativeLibrary for the specified name.static NativeLibrarygetInstance(String libraryName, Map options)Returns an instance of NativeLibrary for the specified name.StringgetName()Returns the simple name of this library.MapgetOptions()Returns this native library instance's options.static NativeLibrarygetProcess()Returns an instance of NativeLibrary which refers to the current process.static NativeLibrarygetProcess(Map options)Returns an instance of NativeLibrary which refers to the current process.(package private) longgetSymbolAddress(String name)Used by the Function class to locate a symbol(package private) static StringmapSharedLibraryName(String libName)Similar to System.mapLibraryName(java.lang.String), except that it maps to standard shared library formats rather than specifically JNI formats.(package private) static StringmatchFramework(String libraryName)Look for a matching framework (OSX)(package private) static StringmatchLibrary(String libName, List searchPath)matchLibrary() is very Linux specific.(package private) static doubleparseVersion(String ver) StringtoString() Methods inherited from class java.lang.Objectclone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitField DetailcallFlagsfinal int callFlagsoptionsfinal Map optionsMethod DetailmatchFrameworkstatic String matchFramework(String libraryName)Look for a matching framework (OSX)getInstancepublic static final NativeLibrary getInstance(String libraryName)Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned. More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.Parameters:libraryName - The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6"), or the full path to the library (e.g. "/lib/libc.so.6").getInstancepublic static final NativeLibrary getInstance(String libraryName, ClassLoader classLoader)Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned. More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.Parameters:libraryName - The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6"), or the full path to the library (e.g. "/lib/libc.so.6").classLoader - The class loader to use to load the native library. This only affects library loading when the native library is included somewhere in the classpath, either bundled in a jar file or as a plain file within the classpath.getInstancepublic static final NativeLibrary getInstance(String libraryName, Map options)Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned. More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.Parameters:libraryName - The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6" or "QuickTime.framework/Versions/Current/QuickTime"), or the full (absolute) path to the library (e.g. "/lib/libc.so.6").options - native library options for the given library (see Library).getProcesspublic static final NativeLibrary getProcess()Returns an instance of NativeLibrary which refers to the current process. This is useful for accessing functions which were already mapped by some other mechanism, without having to reference or even know the exact name of the native library.getProcesspublic static final NativeLibrary getProcess(Map options)Returns an instance of NativeLibrary which refers to the current process. This is useful for accessing functions which were already mapped by some other mechanism, without having to reference or even know the exact name of the native library.addSearchPathpublic static final void addSearchPath(String libraryName, String path)Add a path to search for the specified library, ahead of any system paths. This is similar to setting jna.library.path, but only extends the search path for a single library.Parameters:libraryName - The name of the library to use the path forpath - The path to use when trying to load the librarygetFunctionpublic Function getFunction(String functionName)Create a new Function that is linked with a native function that follows the NativeLibrary's calling convention. The allocated instance represents a pointer to the named native function from the library.Parameters:functionName - Name of the native function to be linked withThrows:UnsatisfiedLinkError - if the function is not foundgetFunctionFunction getFunction(String name, Method method)Create a new Function that is linked with a native function that follows the NativeLibrary's calling convention. The allocated instance represents a pointer to the named native function from the library.Parameters:name - Name of the native function to be linked with. Uses a function mapper option if one was provided to transform the name.method - Method to which the native function is to be mappedThrows:UnsatisfiedLinkError - if the function is not foundgetFunctionpublic Function getFunction(String functionName, int callFlags)Create a new Function that is linked with a native function that follows a given calling flags.Parameters:functionName - Name of the native function to be linked withcallFlags - Flags affecting the function invocationThrows:UnsatisfiedLinkError - if the function is not foundgetFunctionpublic Function getFunction(String functionName, int callFlags, String encoding)Create a new Function that is linked with a native function that follows a given calling flags.Parameters:functionName - Name of the native function to be linked withcallFlags - Flags affecting the function invocationencoding - Encoding to use to convert between Java and native strings.Throws:UnsatisfiedLinkError - if the function is not foundgetOptionspublic Map getOptions()Returns this native library instance's options.getGlobalVariableAddresspublic Pointer getGlobalVariableAddress(String symbolName)Look up the given global variable within this library.Parameters:symbolName - Returns:Pointer representing the global variable addressThrows:UnsatisfiedLinkError - if the symbol is not foundgetSymbolAddresslong getSymbolAddress(String name)Used by the Function class to locate a symbolThrows:UnsatisfiedLinkError - if the symbol can't be foundtoStringpublic String toString()Overrides:toString in class ObjectgetNamepublic String getName()Returns the simple name of this library.getFilepublic File getFile()Returns the file on disk corresponding to this NativeLibrary instance. If this NativeLibrary represents the current process, this function will return null.finalizeprotected void finalize()Close the library when it is no longer referenced.Overrides:finalize in class ObjectdisposeAllstatic void disposeAll()Close all open native libraries.disposepublic void dispose()Close the native library we're mapped to.mapSharedLibraryNamestatic String mapSharedLibraryName(String libName)Similar to System.mapLibraryName(java.lang.String), except that it maps to standard shared library formats rather than specifically JNI formats.Parameters:libName - base (undecorated) name of librarymatchLibrarystatic String matchLibrary(String libName, List searchPath)matchLibrary() is very Linux specific. It is here to deal with the case where /usr/lib/libc.so does not exist, or it is not a valid symlink to a versioned file (e.g. /lib/libc.so.6).parseVersionstatic double parseVersion(String ver)Skip navigation linksOverviewPackageClassTreeDeprecatedIndexHelpJNA API 4.2.0Prev ClassNext ClassFramesNo FramesAll ClassesSummary: Nested Field Constr MethodDetail: Field Constr MethodCopyright 2007-2015 Timothy Wall. All Rights Reserved.
0aad45d008