UnsatisfiedLinkError in Jbuilder 8, but not when outside!

I'm trying to access a dll file via JNI. When I run the standard DOS prompt and arguments, it runs fine, returning the results I need.

I then adapt part of the Java code to input it into a project in Jbuilder 8, and I plac the dll file in the PATH, so i can be seen. However, when I try to access the dll during runtime, Jbuilder returns an java.lang.UnsatisfiedLinkError.

I have tried many things, placing the same file in multiple paths that appear in the PATH variable, in the place the class files reside, and I've tried changing the properties of the project itself to allow certain paths to be included in the search. All to no avail.

From what my tests have proven, the problem lies within Jbuilder 8, not Java or my inability to refer to it via the PATH variable. I've done some reading and edited the jdk.config file, using the:

vmparam -Djava.library.path=c:\windows\system32

But still it doesn't want to find the dll. Anything else I'm missing?
Who is Participating?
NetminderConnect With a Mentor Commented:
Closed, 500 points refunded.

doronb: there is a "points for" question for you at http://www.experts-exchange.com/Q_20949831.html

Site Admin
If I understand correctly, you shouldn't edit any config files that come with JBuilder8, what you should do is edit the "Project Properties" for the current project and add the runtime configuration to include your special params.
MorsVitaEstAuthor Commented:
I've tried that, using many different variations. One main difference I made to the code to access the dll is this, it was accessed directly in a short main method, and then the method would quit. I changed it to no main method, except the one I use in my larger program. After creating a test class to access the one that loads the dll, in the DOS window, it works fine.

JBuilder is the problem, I've recompiled the dll many times, each time working in the original version, and then not working in the main project file. I've added all the paths even in area you suggested, but nothing, just more java.lang.UnsatisfiedLinkError.

What's strange is that it can obviously find the file in the PATH, as it would leave a custom error message if it couldn't find it, yet it chooses not to load the necessary method from within the dll.

The only other explanation is the introduction of package names, as my project has different package names to that of the smaller project (with the short Main class). However, there is simply an extension of them (let's say it was google.api.com, then I added another two extensions, string.find.google.api.com). Could this be the problem?

An expert on the intricacies of JBuilder would be appreciated.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Working with DLL's as far as I remember is pretty simple, defining the native method, loading the library and that's about that.  Package names as far as I know don't even get into this.  JBuilder shouldn't be interfering with anything as far as I know if the DLL is located with all the other classes (respective to the package names).

Does the code that JBuilder compiles actually work from a DOS prompt window, or do you also have to compile the java code using javac with the regular JDK for things to work?
MorsVitaEstAuthor Commented:
Well, everything compiles fine in JBuilder, and the problem only occurs during runtime, when the dll is accessed. I can't run it in a DOS windows since I can't actually figure out how to do that :) I've tried with a custom .bat script to run the java -classpath etc in one go, but it doesn't work properly, since I'm assuming that JBuilder has a lot of custom variables put into that. This would probably be the key to making it work, if I can find a method to run my files outside of JBuilder. The problem is catching all the several directories that the files lie in. I currently have three lcoations for files.

The home directory:
... jbproject\untitled1\classes

Then the classes reside in the following directories.


The Main method lies in spellchecker\frontend\OpenDocument.class

The files are also all labelled in packages, spellchecker.backend, spellchecker.backend.edu.princeton.wordnet, and spellchecker.frontend. The bat file I have to run it is:


set MYCLASSES=spellchecker/frontend;spellchecker/backend;spellchecker/backend/edu/princeton/wordnet
set MYNATIVELIB=c:\wnjn\java\CUSTOM\jar

call "%MYJAVA%\java" -classpath "%MYCLASSES%" -Djava.library.path="%MYNATIVELIB%" spellchecker.frontend.OpenDocument


The error I get is:

Exception in thread "main" java.lang.NoClassDefFoundError: spellchecker/frontend/OpenDocument

I'm guessing more needs to be done to make it run properly.
>> set MYNATIVELIB=c:\wnjn\java\CUSTOM\jar

Is c:\wnjn\java\CUSTOM\jar the location where your DLL file exists?

>> Exception in thread "main" java.lang.NoClassDefFoundError: spellchecker/frontend/OpenDocument

This means one of the classes wasn't found/resolved properly, is spellchecker.frontend.OpenDocument the class that accesses the DLL and therefor can't be resolved, or is it missing entirely?

>> ...since I'm assuming that JBuilder has a lot of custom variables put into that...

As far as I remember, JBuilder doesn't add anything to the JVM params unless you're debugging your app, or you've specified the params yourself.

>> ...if I can find a method to run my files outside of JBuilder...

>> set MYCLASSES=spellchecker/frontend;spellchecker/backend;spellchecker/backend/edu/princeton/wordnet

This is wrong, it should be:

set MYCLASSES=jbproject\untitled1\classes

because Java takes the package name and automatically converts it to the correct path to find each and every class!

Hope this helps,
MorsVitaEstAuthor Commented:
Thanks, that helped a lot, so now it manages to run, but once again, only up until the point where the dll is accessed (which is when I click a particular button in the GUI). The same error message appears once more.

And yes, MYNATIVELIB is where the dll is located, I chose a different area in case it couldn't read the default system32 one.

Still supremely puzzled over why it won't find it... It works with the other, smaller version that doesn't include all the different classes and packages...
Again, if I remember correctly, IF there is some problem with the declaration of the native method in the Java files as opposed to the actual method signature in the DLL, that is expressed by the UnsatisfiedLinkException...
MorsVitaEstAuthor Commented:
Ok, I've sorted the problem, despite creating package names for the other smaller program, and the same file being read, it didn't work in JBuilder 8. So I tried a different tack, after reading here:


I realised that this might be the problem. Slight as it may be, without any knowledge of C, I edited the native Java method in the C code, and added the package names for my program in the methods, and recompiled the entire thing. The smaller program didn't work, but then I tried in my large program, and it worked perfectly!

Turns out that JBuilder 8 needs the precise package names in the methods to read the from the dll file.

I'll give you 100 points for helping me, and the .bat file commands which are useful when I plan to run it quickly without JBuilder popping up. Thanks again.
No objections :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.