Skip to content

Embedded native library in the JAR file#120

Closed
Zlika wants to merge 2 commits intojava-native-access:masterfrom
Zlika:master
Closed

Embedded native library in the JAR file#120
Zlika wants to merge 2 commits intojava-native-access:masterfrom
Zlika:master

Conversation

@Zlika
Copy link
Copy Markdown

@Zlika Zlika commented Sep 10, 2012

With this patch, a native library can now be embedded in a JAR and automatically
extracted from it.
The library is searched in the JAR in the ${os.name}-${os.arch} folder.
The JAR is the LAST location where JNA will try to find the library.
This feature is inhibited if the property jna.nounpack is true.

extracted from it.
The library is searched in the JAR in the
${os.name}-${os.arch} folder.
The JAR is the LAST location where JNA will try to find the library.
This feature is inhibited if the property jna.nounpack is true.
@dblock
Copy link
Copy Markdown
Member

dblock commented Sep 10, 2012

It looks interesting. If you want this in JNA, you need at least a bunch of tests.

@Zlika
Copy link
Copy Markdown
Author

Zlika commented Sep 11, 2012

You're right, I've just added a unit test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @twall comment on this, but I think catching and ignoring exceptions here is a really bad practice. This is just not supposed to fail, and if it does, something has gone awfully wrong.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is a small copy/paste of Native.LoadNativeLibraryFromJar().
In theory I agree that ignoring exceptions is a bad pratice, but such pattern is very common in finally blocks when a stream has to be closed (because there should be no error here, and even if there is one we do not really care).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a commonly ignored exception in Java; there really is no recourse and in practice I've never actually seen the error.

@wolftobias
Copy link
Copy Markdown
Contributor

yes you are right, but please notice in case a stream is closing sometimes a implicit call to flush is made and in that case you as developer are wondering why the stream doesnt deliver its data and you will got no information about the error. Why dont rethrow that exception in the finally block?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a different flag; jna.nounpack specifically forbids unpacking JNA's native bits; it shouldn't be re-used to forbid unpacking additional native bits unless the two situations are identical (I don't think they are).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the idea was to forbid unpacking because, for example, we were not allowed to write in the temp folder. So I thought both situations were similar.

@twall
Copy link
Copy Markdown
Contributor

twall commented Jan 19, 2013

I like this feature, and had been intending on adding it for a while.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prefix is problematic in that the two properties are not terribly consistent across OS versions and JVMs. JNA's more canonical representation would be better.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. However, the advantage of using these prefixes is that it makes it very easy to copy the native libs in the right folders from Maven or even Ant. But you're right, there are not very consistent (I don't understant why there are so many different names for Windows for exemple).

@twall
Copy link
Copy Markdown
Contributor

twall commented Apr 5, 2013

Applied in commit 3823533

@twall twall closed this Apr 5, 2013
mstyura pushed a commit to mstyura/jna that referenced this pull request Sep 9, 2024
Motivation:

The manifest did contain stuff that is not used at all.

Modifications:

Remove unused entries

Result:

Cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants