You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Haszlakiewicz, Eric" <EH...@transunion.com> on 2010/07/19 07:24:34 UTC

RE: maven-nar-plugin library loading - how to make use of native libraries opaque

>-----Original Message-----
>From: scode@scode.org [mailto:scode@scode.org] On Behalf Of Peter
Schuller
>
>* project C (junixsocket in this case) using maven-nar-plugin to build
>and deploy jar and nar artifacts
>* project B, depending on C
>* project A, depending on B
>
>I now want to simply declare that project A depends on B, and not have
>to worry about anything else. For example, I still want to be able to
>"java -jar XXX.jar" on an uber-jar produced by the maven-shade-plugin
>(or assembly, onejar, etc).
>
>I am aware that there are difficulties resulting from the fact that
>loadLibrary() cannot load an arbitrary library from a .jar file, and
>I'm aware that e.g. jna-posix solves this by unpacking to a temporary
>directory and loading the library by absolute path.
>
>With nar-plugin, once problem was that I never was able to make
>project A actually depend on the artifact (with the appropriate
>platform classifier) other than specifically configuring such a
>runtime dependency myself in the pom file. The second problem is that
>just making it depend on it won't solve the problem since somewhere,
>some code has to exist which jumps through hoops to enable the loading
>of the native library during runtime since putting the .nar file on
>the CLASSPATH won't make loadLibrary() be able to load the library. I
>was unable to find any code that seemed to do this in the nar-plugin,
>but perhaps I am missing it.
>
>Based on browsing the source, my current belief is that
>maven-nar-plugin is not really intended to address this use-case. Is
>that understanding correct, or am I just using it incorrectly?

You can't just include the nar dependency because, as you pointed out,
java won't be able to load things from inside a "nar" file.  I believe
the intended way to do this is you use the unpack options of the nar
plugin to get the actual native libraries present in your build
directory.
Then, what I've done is create a custom assembly descriptor that builds
a tarball which includes any files that the nar plugin unpacked.
I don't know what the "official" best practice is for actually running
the jar file is through.  For many of my projects I've just ended up
with a custom startup script that runs java with the appropriate
options.

In your case, I don't think you can get away from having project A
explicitly know *something* about the fact that there's a native archive
involved.  I'd probably attempt to make project B itself be a nar type
artifact, but I'm not sure exactly how that would all tie together into
the final artifact you create for project A.

eric


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org