Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2173
  • Last Modified:

Problem loading dlls from an RCP Plugin

Hello Everybody,

I am developing an Eclipse RCP application. I have a PluginA which is the main plugin and a PluginB which has JNA wrapper classes for the dll's I have to use. I have these dll's (about 7 to 8) at the root level of the PluginB. But when I try to access the JNA wrapper classes, I get an exception
java.lang.UnsatisfiedLinkError: Unable to load library

I tried using
Bundle-NativeCode:libxxx.dll; osname=win32; processor=x86,
but it doesnt work.

Environment:
Eclipse version: 3.4.2
OS: Windows XP
Java version: 1.5

I tested the dll's and JNA wrapper classes in standalone Java application and it works fine. So it is clearly a problem of loading the dll's. I put the dll's in the Windows/System32 folder, then the dll's load successfully. But obviously this is not the solution I want. I want to pack the dll's in pluginB.

Can somebody please help me fix this problem

Thanks
0
pdeplayer
Asked:
pdeplayer
  • 10
  • 7
  • 6
  • +1
1 Solution
 
CEHJCommented:
You need to set java.library.path to include the plugin's dll directory
0
 
Gibu GeorgeCTOCommented:
You can set the java.library.path to point to the dlls, which I think will solve your problem using,  System.setProperty("java.library.path", "c:\\tmp");
0
 
pdeplayerAuthor Commented:
Hello CEHJ,

Thank you for the prompt response. I tried using it already. I set the library path like:
System.setProperty("java.library.path", "F:\\workspace\\sample.app1\\"); // I hardcoded it in my code to test if it works

But unfortunately it didnt work. I also tried setting the JNA path (as I have some JNA wrapper classes), like:
System.setProperty("jna.library.path", "F:\\workspace\\sample.app1\\"); But even this attempt didnt work.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
what is the relationship between plugin A and plugin B?
0
 
objectsCommented:
Thank you for the prompt response. I tried using it already. I set the library path like:
System.setProperty("java.library.path", "F:\\workspace\\sample.app1\\"); // I hardcoded it in my code to test if it works

don't set the java.library.path, its unnecessary (and pointless)

0
 
objectsCommented:
Are you calling loadLibrary() to load *all* your dll's? (you need to)

0
 
pdeplayerAuthor Commented:
I didnt exactly understand the word "relationship" although here is a brief description:

Plugin A is the main application plugin. Plugin B creates a view and contributes this view to Plugin A. For Plugin B to create this view, it has to access the dll's for some information. Hope I answered your question
0
 
CEHJCommented:
The relationship is actually irrelevant unless the plugins are running in different VMs, which i doubt is the case.
0
 
pdeplayerAuthor Commented:
When I try to do System.loadLibrary("libxxx.dll") then I get "no libvlc.dll in java.library.path". And as I understand, loadLibrary loads libraries into memory (Please correct me if I am wrong). And I have about 7 to 8 dll's, of a total size of 10 MB. In the case that I want to load all libraries I will be taking up 10 MB memory. Is this an effective solution (just a question)?

Moreover when I tried all this (wrapper classes and dll's) from a standalone java program, everything works well. Problem is when I migrate to plugins
0
 
CEHJCommented:
>>System.setProperty("java.library.path", "F:\\workspace\\sample.app1\\"); // I hardcoded it in my code to test if it works

That needs to be set before the plugins load of course
0
 
pdeplayerAuthor Commented:
>>>>System.setProperty("java.library.path", "F:\\workspace\\sample.app1\\"); // I hardcoded it in my code to >>test if it works

>>That needs to be set before the plugins load of course

Yes...I set it well before trying to load the classes
0
 
pdeplayerAuthor Commented:
I read a lot of articles yesterday and osgi framework has a way to deal with native libraries. By specifying resources in  "Bundle-NativeCode" in Manifest.mf, this framework loads all the libraries to a location and then points the referring classes to search for the libraries in this location. I played a lot with this Bundle-NativeCode but nothing worked.
0
 
objectsCommented:
> System.loadLibrary("libxxx.dll");

that should be:

System.loadLibrary("xxx");
0
 
objectsCommented:
> When I try to do System.loadLibrary("libxxx.dll") then I get "no libvlc.dll in java.library.path"

do you mean when you load xxx it cannot find vlc?
You need to load dependent dll's first, before you load dll's that depend on them

0
 
CEHJCommented:
>>
> System.loadLibrary("libxxx.dll");

that should be:

System.loadLibrary("xxx");
>>


That should be

System.loadLibrary("libxxx");
0
 
pdeplayerAuthor Commented:
"System.loadLibrary("libxxx");"

How did I miss that :-)? That did the trick for me. I was using .dll in the end. After playing around with the dlls' to determine the dependency hierarchy, I was able to sort it out.

Thought it solved my first question, there is something else, I just found out that these dll's in-turn use another set of dll's (about 50 of them) inside another folder (/dir1) located in the plugin root directory. Can I specify some how that all these dll's be on the classpath or somewhere. I tried adding these folders in the "Classpath" section of the "Runtime" tab (in plugin.xml). Obviously loading all the 50 dll's is not an optimum solution for me.
0
 
objectsCommented:
> How did I miss that :-)?

easy to miss, glad I could spot it for you :)

> e another set of dll's (about 50 of them) inside another folder (/dir1)

you could try using

System.loadLibrary("dir/libxyz");

otherwise you'll need to move them to root directory

0
 
objectsCommented:
> Obviously loading all the 50 dll's is not an optimum solution for me.

If you need them you are going to need to load them.

0
 
CEHJCommented:
>>these dll's in-turn use another set of dll's (about 50 of them) inside another folder (/dir1) located in the plugin root directory. Can I specify some how that all these dll's be on the classpath or somewhere

Again, it's java.library.path that's key here, not the classpath. Are you sure the dlls don't know how to load each other?
0
 
CEHJCommented:
If the answer is that they don't know

a. where to load them:
you need to ensure that their folder is on java.library.path

b. how to load them
You need to load them yourself

Either way java.libary.path needs to be set correctly
0
 
pdeplayerAuthor Commented:
I found another way to deal with this problem. Even though this solution is specific to the libraries I am using, I will mention here what I did. I am talking about the 50 dlls in a dir I had to use and not the initial 8 dll's. These 8 dll's I had to load with System.loadLibrary. I had to copy the directory containing all the dll's  to the root directory of my application and set an argument with this path and pass it to my dll's, so now they know where to look for the set of dll's without having to load them. As I mentioned before this solution is specific to my libraries and I wonder if it will work with others facing the same problem.

A big thanks to CEHJ and objects for your prompt replies.
0
 
objectsCommented:
> Either way java.libary.path needs to be set correctly

as I already mentioned thats incorrect

> I had to copy the directory containing all the dll's  to the root directory of my application

thought u might

0
 
objectsCommented:
Can you explain why you accepted that comment? I had already mentioned that you were looking up the worng name, that comment just pointed out a typo in my comment.

0
 
objectsCommented:
also told you your dll's were in the right location
and that you would probably have to move the additionals dll's to the root directory

:)

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 7
  • 6
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now