integration nar with JNA

22 views
Skip to first unread message

LUGAN, Anne-Laure

unread,
Feb 25, 2021, 2:33:03 PM2/25/21
to mave...@googlegroups.com, CATALON, Matthieu

Hello,

 

We are using the nar plugin for the first time and the features are promising !!!

 

We are trying to generate a nar file and integrate this by using JNA which has its own way to load shared libraries.

 

We have encountered many difficulties but at the end but we found a way…

Still we have to do some modifications in the generated NarSystem class. We would like to avoid this bad practice (editing generated code), so we might need your help.

 

We have seen that once NarSystem.loadLibrary() is invoked, Java have the expected entry in Thread.currentThread().getContextLoader() nativeLibraies.

So it sounds like the library is found and loaded.

 

Next, we call the JNA Native library :

myVariable= Native.load(“the name as defined in NarSystem”, MyInterface.class);

Note that we have to copy/paste the filename value.

As we would like to avoid this, do you think it would be possible to make the filename public static so we could use it?

We found that modification could be made at https://github.com/maven-nar/nar-maven-plugin/blob/2c3442e3d1045907b44660d83399d51fbd612a75/src/main/java/com/github/maven_nar/NarSystemMojo.java#L200.

 

Still, it did not work because the JNA library did not see? use ? Thread.currentThread().getContextLoader() nativeLibraries parameter.

So we modify again the NarSystem generated class to extract the loaded path :

        String absolutePath;

        if (unpacked != null) {

            absolutePath= unpacked.getPath();

        } else try {

            final String libPath = getLibPath(loader, aols, mappedNames);

            final JniExtractor extractor = new DefaultJniExtractor(NarSystem.class);

            final File extracted = extractor.extractJni(libPath, fileName);

             absolutePath = extracted.getAbsolutePath();

           

        } catch (final Exception e) {

            e.printStackTrace();

            throw e instanceof RuntimeException ?

                (RuntimeException) e : new RuntimeException(e);

        }

        System.load(absolutePath);

        return absolutePath;

 

With that we finally make it work with the following code :

        String path = NarSystem.loadLibrary();

        NativeLibrary.addSearchPath(NarSystem.fileName, Path.of(path).getParent().toString());

 

Do you think this is the good solution ? We would be ready to contribute if so.

If not, do you have any other solution to our problem ?

 

Best regards,

 

--

Anne-Laure LUGAN

 

The information in this e-mail is confidential. The contents may not be disclosed or used by anyone other than the addressee. Access to this e-mail by anyone else is unauthorised.
If you are not the intended recipient, please notify Airbus immediately and delete this e-mail.
Airbus cannot accept any responsibility for the accuracy or completeness of this e-mail as it has been sent over public networks. If you have any concerns over the content of this message or its Accuracy or Integrity, please contact Airbus immediately.
All outgoing e-mails from Airbus are checked using regularly updated virus scanning software but you should take whatever measures you deem to be appropriate to ensure that this message and any attachments are virus free.

Johannes Schindelin

unread,
Mar 2, 2021, 10:50:47 AM3/2/21
to LUGAN, Anne-Laure, mave...@googlegroups.com, CATALON, Matthieu
Hi Anne-Laure,

Please note that (at least as far as I understand) the `nar-maven-plugin`
is currently unmaintained.

See https://groups.google.com/g/maven-nar/c/kHyC8MA5_nM for details.

Thanks,
Johannes

On Wed, 24 Feb 2021, LUGAN, Anne-Laure wrote:

> Hello,
>
> We are using the nar plugin for the first time and the features are promising !!!
>
> We are trying to generate a nar file and integrate this by using JNA which has its own way to load shared libraries.
>
> We have encountered many difficulties but at the end but we found a way...
> --
> You received this message because you are subscribed to the Google Groups "NAR Maven plugin" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to maven-nar+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/maven-nar/056c13633431460cacfe110e52232362%40CD1-4DDAG05-P02.cdmail.common.airbusds.corp.
>

LUGAN, Anne-Laure

unread,
Mar 4, 2021, 5:34:21 AM3/4/21
to Johannes Schindelin, mave...@googlegroups.com, CATALON, Matthieu
Airbus Amber
Hello,

Thank you for your reply and this piece of information that might make us give up on nar...
It did look promising!

Best regards,

--
Anne-Laure

Johannes Schindelin

unread,
Mar 4, 2021, 7:45:53 AM3/4/21
to LUGAN, Anne-Laure, mave...@googlegroups.com, CATALON, Matthieu
Hi Anne-Laure,

Please note that nothing prevents you from maintaining a fork of the
`nar-maven-plugin`. Or even to step up to the challenge of maintaining
`nar-maven-plugin` yourself...

Ciao,
Johannes
Reply all
Reply to author
Forward
0 new messages