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 7961939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:11:34+00:00 2026-06-04T05:11:34+00:00

Is there a platform-independent Java statement to load a native library from a different

  • 0

Is there a platform-independent Java statement to load a native library from a different directory than the Java source code is in? I would like to use something like this:

public class HelloWorld {
    static {
        System.loadLibrary("../some_project/HelloWorld");
    }

    public static native void print();
}

The problem is that System.loadLibrary() doesn’t support directory separators in the pathname argument. Also, System.load() unfortunately requires an absolute pathname, which not only means I can’t specify a relative directory as above (which I would like to do), but it also requires the argument to include, for example, the preceding “lib” and “.so” extension on the JNI library name on a Linux system.

Is there a standard way of dealing with this? If possible, I would like to avoid writing a bunch of platform-dependent Java code just to construct the correct JNI library name.

  • 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-06-04T05:11:36+00:00Added an answer on June 4, 2026 at 5:11 am

    I believe you’re looking for System.mapLibraryName, which is the method typically used by ClassLoader.findLibrary implementations. For example:

    File lib = new File("../some_project/" + System.mapLibraryName("HelloWorld"));
    System.load(lib.getAbsolutePath());
    

    This will use libHelloWorld.so on Linux and HelloWorld.dll on Windows. Be aware that some operating systems support multiple extensions, and mapLibraryName can only support one, by design. The ones I’m aware of are MacOS (.dylib primarily and .jnilib for legacy) and AIX (.a and .so).

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

Sidebar

Related Questions

I was searching a bit for another platform independent language like Java. Are there
Java has the convienient System.getProperty(user.home) to get the user's home directory in a platform-independent
Just curious to know when java is made platform independent then are there any
Is there a platform-independent method to embed file data into a c++ program? For
Is there a platform-independent way of writing the EOF symbol to a string in
Is there a cross-platform network library for the iPhone? Is ACE available for the
Is there anyway to create a desktop icon (cross platform/browser) from a linked image
Are there any extensible interpreted programming languages written in standard, platform-independent C or C++?
Confused by java compilation process OK i know this: We write java source code,
Is there a platform independent way to detect the number of physical and/or virtual

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.