I have an OSGI (more precsiely a Wisdom framework-based) application in which i would like to use the JACOB library to interact with Office (the goal being to transform PPT into images). I can easily add the JACOB jar to my CLASSPATH, but JACOB requires the dll to be available in the java.library.path
environment variable.
Question: How can I add it in my maven build?
EDIT I'm using maven 3
It appears JACOB has some special code which seems directly related to this class of errors. Indeed, there is a
jacob.dll.path
defined inLibraryLoader
by which one can give Jacob an absolute path to access the jacob dll (which do not directly usesSystem.loadLibrary
). Setting that library directly solved my problem.You probably have three possibilities for this use case
MAVEN_OPTS
You could use the
MAVEN_OPTS
environment variable to pass to the Maven build the required JVM option (for the whole build, hence applying to all involved plugin/goal executions):However, this will be also applied to all other builds concerned by the same environment. In a Jenkins job you can still configure this variable per job, hence isolated within a certain build.
.mvn settings
Since Maven 3.3.1, you could have an
.mvn
folder as part of the concerned project and ajvm.config
file as perfect place for such an option.As part of the official release notes
The options will be applied to all modules in case of a multi-module project.
Your
${maven.projectBasedir}/.mvn/jvm.config
file could hence provide the following:The main advantage of this approach is that the configuration is isolated to the concerned project and applied to the whole build as well.
Plugin configurations
You should set it to the concerned plugins and configuration entry, if any. For instance, the Maven Compiler Plugin provides the
compilerArgs
configuration entry for JVM options, the Maven Surefire Plugin provides theargLine
configuration option for the same, and so on.This is the least recommended approach since configuration would be duplicated and often not even possible (up to the plugin configurability). However, if the use case is really isolated to a certain plugin execution (compilation, testing, etc.), then it might still be reasonable.
I am a bit confused about the maven part since this is normally not a part of the runtime library when you use OSGi.
In OSGi, if you use the dll in your OSGi framework then this all can be setup by the OSGi framework. You must package the DLL into the JAR and provide some properties. In runtime, the framework then extracts the library and makes sure it can be found. (There is a bit of an issue with multiple DLLs that depend on each other.)
Here is some practical information about native libraries in OSGi:
http://enroute.osgi.org/appnotes/native-libraries.html