I am currently trying to get a Tomcat-Application running with Maven with a native library, which needs a specified java.library.path. Normaly, for running Tomcat with the path, one has to do things like adding the path to Tomcat: How to add a native library in Tomcat? .
But in this case, I want to run Tomcat with the Maven plugin, and unfortunately, I couldn't find any hint on how to set java.library.path for the Tomcat-Maven plugin. Just setting argLine
with -Djava.library.path=XX
does not work. Does anybody have an idea how to include native libraries with the Tomcat-Maven plugin?
One way that should work according to https://groups.google.com/forum/#!msg/maven-nar/1mz9oWj-65U/dbQEK_6DLdYJ is setting the path with System.setProperty("java.library.path", javaLibPath);
and afterwards let the classloader reload this with
Field field = ClassLoader.class.getDeclaredField("sys_paths");
field.setAccessible(true);
field.set(null, null);
Unfortunately, for me this does not work, the error is thrown anyway. (This hint is also given by http://blog.cedarsoft.com/2010/11/setting-java-library-path-programmatically/).
Another way (not to solve the real problem, but to workaround that I don't know a way to load set java.library.path
in the Tomcat-Maven plugin) seems to be to add the library during the programs run, like described for example here: Directory separator should not appear in library name: Macintosh HD/Users/sakkisetty/Documents/dll/FasExtend.dll. Unfortunately, this does not work either.
File f2 = new File("/home/my/absolute/path");
for (File f : f2.listFiles()){
System.out.println("Datei: " + f.getAbsolutePath());
if (f.isFile() && f.getName().endsWith(".so")){
System.out.println("Loading: " + f.getAbsolutePath());
// System.loadLibrary(f.getName());
System.load(f.getAbsolutePath());
}
}
There are two possible results of this: If I try it like this, the same errors are thrown as if the libraries aren't loaded at all. If I use System.loadLibrary
, it does not find the library because the library isn't in the java.library.path
and System.loadLibrary
does not take absolute paths - so all in all, this way does not work either, at least how I tried it.