 |
 |
Java: How do I dynamically load a library from a folder?
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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!
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|