Tuesday, October 12, 2010

Jetty Maven Plug-in vs Native Libraries.

My web application at http://owlcms.googlecode.com uses a native library to drive a LED display.  I could not get it to reload correctly under the Jetty Maven Plug-in because of a
java.lang.UnsatisfiedLinkError: Native Library foo.dll already loaded in another classloader

The solution is very easy:
  • Find the jar that invokes the native library.
  • Locate the dependency  for that jar in the pom.xml file.
  • Move the dependency so that it is inside the dependencies section  of the Jetty plugin.  By making it a dependency of the Jetty plugin (as opposed to a dependency of your application), Jetty won't try to reload it and won't mess up the classloaders
Kudos to David Yu's suggestion on a forum.

1 comment:

jf said...

Actually, you may need to *copy* the dependency to the plugin. And mark the dependency in the application as having the scope provided.