A POM dependency contains native libraries (DLLs inside a JAR file). How do I programmatically look up the path of the downloaded JAR file so I can pass it into "java.library.path"?
相关问题
- How to resolve Maven exec plugin: classpath too lo
- Maven: How to read the Parent POM version
- How to make a local dependency depend on a feature
- Dependency javax.mail:mail:1.4 not found
- How to use a “custom jar” in IntelliJ IDEA?
相关文章
- What is a good way to deploy a Perl application?
- Maven directory structure
- The Gradle failure may have been because of Androi
- Passing the Maven Debug Flag from Hudson
- How to fix a missing ld library for -lfl while com
- C# - Application to show all dependencies between
- Why does this makefile execute a target on 'ma
- Unable to resolve dependency for ':app@debug/c
If the DLL is inside the JAR, then you will need to copy it out to a directory before it can be loaded. (JARs that include native libraries usually do this themselves.) If your JAR isn't doing this, then you can use Class.getResourceAsStream() and write this to a directory that you've added to the
java.library.path
.For an example of this, see loadNativeLibrary in JNA. It uses this technique to load it's own library (a JNI library) from a JAR.
You can use the maven dependency plugin to copy the artifacts to a predefined path:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
Since
System.load()
can't load libraries from within a jar, you will have to use a custom loader which extracts the library to a temporary file at runtime. Projects With JNI discusses this approach and provide code for the custom loader.An alternative would be to unpack the dependency, for example using
dependency:unpack
.Answering my own question: http://web.archive.org/web/20120308042202/http://www.buildanddeploy.com/node/17
In short, you can use the maven-dependency-plugin:unpack goal to extract the libraries into a known path, and pass that into
java.library.path
: