1
votes

I have java web application which is deployed to Tomcat. Application calls low level C library via JNI. Everything works fine when I deploy my application at first time, but as soon as I trying to redeploy - application crashes with following error: java.lang.UnsatisfiedLinkError: Native Library /opt/apache-tomcat/apache-tomcat-7.0.57/shared/lib/libGenderizer.so already loaded in another classloader

  1. I've created and put my .so object under /opt/apache-tomcat/apache-tomcat-7.0.57/shared/lib.

  2. In catalina.sh (file which starts tomcat) I've added following line which sets library path for tomcat. JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/opt/apache-tomcat/current/shared/lib"

  3. I am redeploying my application using maven mvn tomcat7:redeploy

Could you please help me to resolve current issue? I am doing System.gc() but unfortunately it doesn't help.

   public class GenderService {

            private static Logger logger = Logger.getLogger(GenderService.class);

            static {
                try {
                    System.gc();
                    System.loadLibrary("Genderizer");
                }
                catch(UnsatisfiedLinkError e){
                    logger.error("Native code library failed to load.\n", e);
                }
            }

            private native String genderize(String name);


            public Gender identifyGender(Customer customer){
                Gender gender = determineGender(customer);
                return gender;
            }
    }
1

1 Answers

0
votes

Already asked on SO. See Apache Tomcat Wiki for a helpful answer.