Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Java: How do I dynamically load a library from a folder?

Java: How do I dynamically load a library from a folder?
Thread Tools
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Oct 30, 2004, 01:53 PM
 
Is there a way that I can load a library contained in some random folder (whose location I know) within the code of a java application? My application uses several libraries and so I'd like to keep them inside of a resources folder that is contained inside the application folder. I just want the user to be able to double-click the main jar file and for my jar file to automatically load the needed libraries from the resources folder.

Edit: BTW, I forgot to mention, I need to be able to load both regular jar-libraries and native libraries. The folder layout I have looks like this:

-+ Application Folder/
---- My App.jar
---+ libs/
------ library1.jar
------ library2.jar
---+ native libs/
------ thing.jnilib
------ thing.dll
(Last edited by itistoday; Oct 31, 2004 at 11:31 AM. )
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Nov 1, 2004, 05:10 PM
 
ok, it seems like no one knows... The reason I want to do this is simply because I want it to be done in the Mac-style: simple, yet powerful. I don't want the users to have to type out in the terminal "java -Djava.library.path=...blah". I want them to just double click this application, and for it to work. On all systems. Why is this so difficult?
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Nov 1, 2004, 07:34 PM
 
Originally posted by itistoday:
ok, it seems like no one knows... The reason I want to do this is simply because I want it to be done in the Mac-style: simple, yet powerful. I don't want the users to have to type out in the terminal "java -Djava.library.path=...blah". I want them to just double click this application, and for it to work. On all systems. Why is this so difficult?
Just unroll the jars and roll them inside your jar. That's how this is generally done.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
Nov 2, 2004, 11:06 AM
 
Class.forName

and

Classloader

Read the API docs.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Nov 2, 2004, 01:55 PM
 
Originally posted by Kristoff:
Class.forName

and

Classloader

Read the API docs.
But Classloader's are a pain. For any class that I want to use I'll have to go through the whole shick of type-casting teach class and calling the classloader right?

Arkham_c: I'll try that when it's nearly completion for distribution, but when I'm testing it, it's a pain to do that, plus I think that only works for jar libraries, but not native libraries...
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Nov 2, 2004, 07:21 PM
 
Originally posted by itistoday:
But Classloader's are a pain. For any class that I want to use I'll have to go through the whole shick of type-casting teach class and calling the classloader right?

Arkham_c: I'll try that when it's nearly completion for distribution, but when I'm testing it, it's a pain to do that, plus I think that only works for jar libraries, but not native libraries...
For testing, any jars put in ~/Library/Java/Extensions are automatically added to the classpath.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Professional Poster
Join Date: Oct 2001
Status: Offline
Reply With Quote
Nov 2, 2004, 07:26 PM
 
Originally posted by Arkham_c:
For testing, any jars put in ~/Library/Java/Extensions are automatically added to the classpath.
Yeah, that's what my setup is. I actually tried to put the native libraries in the same folder as the application and it seems that if they're in the same folder then they're loaded... so I think I'll try your suggestion with the jar libraries later on when the app is coming to completion. If I can't get it to work someone suggested to me to use a java installer called IzPack and install the proper libraries in their proper system-wide library folders on the users machines (though I'd rather not do this, as this is un-maclike and could cause problems).

Thanks everyone!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:18 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2