Tomcat link-os Java native libraries error on reload

T Tobia Scapin 3 years 7 months ago
190 1 0

I'm using LinkOS Java libraries to print from my webapp to USB printers running in a Tomcat 8 java container in Windows environment.
The ZSDK_API.jar is included in the webapp libraries and zDriverAdapter and ZebraNativeUsbAdapter_32 files are stored in tomcat /bin directory.
With this configuration, I can print and linkOS works as required.

But when I have to reload or update my project, Tomcat reloads the web application and after this process I get

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.

I found that the inner error is:

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.

Do you have any suggestion?

Please Register or Login to post a reply

1 Replies

J Javier Molina

Have you checked if enabling antiJARLocking or antiResourceLocking in your context.xml has any effect? Apache Tomcat 7 Configuration Reference (7.0.92) - The Context Container

If that doesn't help, you could put (for development only, not recommended for production) the ZSDK_API and all other .jar files inside a location loaded by the common class loader so that the classes in ZSDK_API are not reloaded and therefore they don't attempt to load the DLL more than once. Note that this is considered a hack and it may cause problems if different webapps use different versions of some dependency.

If initial tests work with that configuration, I would suggest creating a new directory and adding that to common.loader in tomcat/conf/catalina.properties. By default it will look similar to this:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar

If you create tomcat/lib/zsdk and put all the jars there, you would update common.loader as such:

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/lib/zsdk/*.jar

By doing that, you make it easier for yourself to update the ZSDK-specific files because you know they are confined to that specific directory, instead of having to check which files belong to tomcat and which ones belong to ZSDK.

Javier Molina
Technical Architect, Kutir Mobility
Posted on behalf of Zebra Technologies

CONTACT
Can’t find what you’re looking for?