title: Does Tomcat (as a Service) not load native libraries for a Java web application?
body: <p>I am using Tomcat7 and Ubuntu. I have a Java web application which uses some native libraries. When I run the web application within Eclipse it works through Eclipse internal Tomcat server during debugging. However, when I deploy the applcation to a hosted Tomcat service, the application fails when it reaches the point of loading these libraries. </p>
  
  <ol>
  <li>I put the native libraries in /home/me/my_shared_libs, and gave<br>
  folder and file ownership to user "Tomcat7" -- <code>sudo chown</code></li>
  <li>I give all permissions of the native libraries to "Tomcat7" user
  -- <code>sudo chmod</code></li>
  <li>In do <code>sudo vi /usr/share/tomcat7/bin/setenv.sh</code>, and put the following
  in the file <code>export CATALINA_OPTS="-Djava.library.path=/home/me/my_shared_libs"</code></li>
  <li>Then I restart Tomcat -- <code>sudo service tomcat7 restart</code>  And, whenever
  refernce to load native libraries is reached, I get an error about <strong><code>InvocationTargetException</code></strong>.</li>
  </ol>
  
  <p>I am also open to the option of adding the native libraries as part of the the application's .WAR file. (Although I am not sure how to do this in Eclipse).</p>
  
  <p>Log of <code>/var/log/tomcat7/catalina.out</code>--></p>
  
  <pre><code>Jun 30, 2016 8:11:50 PM org.apache.catalina.startup.Catalina start
  INFO: Server startup in 3643 ms
  Load my_native_lib_called. libmachoman.so: cannot open shared object file: No such file or directory
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  I found out something very interesting. Tomcat does pick up the library location that I set above. What happens is I have two types of libraries (.so) files in the location. The first library (libcore.so) calls/loads the the second library (libmachoman.so). libcore.so is found and loaded both libmachoman.so is not, even though both are in the same location.</p>