Login  Register

Re: Loading libraries from an executable JAR is seriously hard.

Posted by Sven Gothel on Apr 05, 2012; 10:40am
URL: https://forum.jogamp.org/Loading-libraries-from-an-executable-JAR-is-seriously-hard-tp3885657p3886839.html

On 04/05/2012 11:53 AM, bkuker [via jogamp] wrote:
>
>
> It sounds from some other posts like you are planing to drop the architecture
> specific jars in favor of one all-encompassing JAR.

I never said that - nope. I especially emphasized that the platform specific
native JARs are very efficient when it comes to networking (Applets ..).

However, I am open to give the fat-jar method a thought as a fall-back.

> If that is the case I

[as a fall-back]

> would assume you are going to have to use architecture specific directories
> anyway?
>
> [arch]/[libname].[so,dll,whatever]

as I mentioned .. yes

>
> Currently it looks like the code goes:
>
> 1. Try to load library from natives jar in same location as gluegen jar.
> 2. Try to load library from library.path
>
> could it be as simple as:
>
> 1. Try to load library from natives jar in same location as gluegen jar.
> 2. Try to load library from
> SomeJogAmpClass.class.getClassLoader().getResource([arch]/[library]).
> 3. Try to load library from library.path
>
> I assume once you have an input stream for the library you can copy it to
> whatever temp place it goes to and loadLibrary(). Resources are commonly
> used, easy to understand, and in a pinch if someone needed to do something
> crazy in a standalone app they could do it with a custom classloader.
>
A custom ClassLoader has it's own restrictions here,
hence I chose to use specific GlueGen methods to utilize this functionality.
For example in an IDE or Applet environment we cannot guarantee an entry point
where a user switches to a new ClassLoader, we provide. Note that native
libraries, static data and classes are only valid from the loading ClassLoader.

We have somehow solved this problem in Android, but it's quite tricky
and we don't want to force people to deal with such problems.

However, the fat JAR can be achieved with the current API model, yes.

~Sven



signature.asc (910 bytes) Download Attachment