Solved

UnsatisfiedLinkError in Jbuilder 8, but not when outside!

Posted on 2004-03-26
12
291 Views
Last Modified: 2010-05-18
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?
0
Comment
Question by:MorsVitaEst
  • 5
  • 5
12 Comments
 
LVL 9

Expert Comment

by:doronb
ID: 10697352
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.
0
 

Author Comment

by:MorsVitaEst
ID: 10699623
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.
0
 
LVL 9

Expert Comment

by:doronb
ID: 10700229
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?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:MorsVitaEst
ID: 10700788
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.

spellchecker\frontend
spellchecker\backend
spellchecker\backend\edu\princeton\wordnet

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 MYJAVA=%JAVA_HOME%\bin
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.
0
 
LVL 9

Expert Comment

by:doronb
ID: 10706439
>> 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,
Doron
0
 

Author Comment

by:MorsVitaEst
ID: 10709460
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...
0
 
LVL 9

Expert Comment

by:doronb
ID: 10710317
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...
0
 

Author Comment

by:MorsVitaEst
ID: 10793898
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:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20183453.html

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.
0
 
LVL 9

Expert Comment

by:doronb
ID: 10795109
No objections :)
0
 

Author Comment

by:MorsVitaEst
ID: 10797625
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 10820602
Closed, 500 points refunded.

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

Netminder
Site Admin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question