Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3979114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:07:48+00:00 2026-05-20T05:07:48+00:00

In a Java project, I am using a third-party library that loads some native

  • 0

In a Java project, I am using a third-party library that loads some native library via

System.loadLibrary("libName");

I’d like to be able to influence the search path of this method from within my application, so that the user doesn’t need to specify a correct java.library.path value on the command line (this value depends on the current OS and architecture). E.g on Windows I want to set it to “lib/native/windows”, on Linux 32bit to “lib/native/linux32” etc.

I tried

System.setProperty("java.library.path", ...)

but this is ignored, apparently because the JVM reads this property only once before my code is run.

I also tried to load the native libray before using the Java library that depends on it with

System.load("fullPath/lib")

This call succeeds, but there will still be an UnsatisfiedLinkError when the native library is loaded again with System.loadLibrary().

The only way I found is the following:

  • Add interfaces that abstract the whole API of the external library.
  • Use only these interfaces in the rest of the code.
  • Add classes that implement the interfaces and delegate to the library.
  • Write an own ClassLoader, that
    • overwrites findLibary() so that the native library is found in the correct path
    • overwrites loadClass() and loads all classes of the external library and the wrapper layer by itself instead of trying to delegate to its parent like the default ClassLoader would do
  • Ensure that the interfaces are loaded with the normal ClassLoader and the wrapping classes and the external library are loaded with my own ClassLoader.

This works, but I find it very complicated and it is much effort because I need to add all those interfaces. Is there a simpler way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:07:49+00:00Added an answer on May 20, 2026 at 5:07 am
    1. There is no approved way to change the library path for a running JVM.
    2. You cannot load a native library more than once … and you cannot unload a native library so that you can load it again: https://bugs.java.com/bugdatabase/view_bug?bug_id=4171986

    Based on your comments above (particularly, the behavior of the 3rd-party library), I’d say that your best option is to get the library path right when you launch the JVM.

    Note that there is a hacky way to change the library path (see https://stackoverflow.com/a/24258955/139985) but it involves nasty reflection, and it reportedly doesn’t work for all Java releases. Certainly, it relies on undocumented private implementation details of ClassLoader that could change from one release to the next.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that uses a third party library in the form of
I am using a third party library, i have included into my project. It
I have recently just created Java project using Eclipse that requires 2 JAR files
I have a Java project that I build using an Ant script. I am
I made an android project using eclipse. It looks like: src/ ActivityMain.java lib/ Square.java
In my Eclipse project I'm using a third-party annotation processor, Hibernate Metamodel Generator to
I'm developing a web application in Java and I'm using several third party JAR
we have a third party web-based content management system written in Java. It has
I have a Java project in Eclipse that I maintain using a local git
I worked on a project using eXistdb. XML Java API, etc. After that anytime

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.