Load Shared Library by specifying the file path and name..


typically, you can load a library like so:

   System.loadLibrary ( "my_library" );

If I'm not mistaken, that will load a library called "my_library" (.dll, ...) from either the current directory (if it exists), or by searching the dir's in the system's PATH variable, until it's found...

However, if I wished to load it like so:

   System.loadLibrary( getClass().getResource( "my_library.dll" ).getFile() );

Would that work?


P.S. I can't test this myself at the mo..
LVL 25
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software engineerCommented:
>> Would that work?
No. System.loadLibrary() takes a String as argument
zzynxSr. Software engineerCommented:
Sorry. Ignore me.
InteractiveMindAuthor Commented:
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

zzynxSr. Software engineerCommented:
>> System.loadLibrary( getClass().getResource( "my_library.dll" ).getFile() );

Second attempt... ;°)

I think that since


returns a complete path + filename it won't work.

Maybe in that case you should better use

         System.load( getClass().getResource( "my_library.dll" ).getFile() );

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>Would that work?

No, it needs to be a file AFAIK and on java.library.path
Correction, it should work if the path it returns happens to be on java.library.path
Check the JDIC implementation, they are doing this kind of loading( even the java.library.path doesn't have the path of the library ) if the application runs through the java webstart.

Best Regards,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.