Solved

UnsatisfiedLinkError in Jbuilder 8, but not when outside!

Posted on 2004-03-26
12
283 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:MorsVitaEst
Comment Utility
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
Comment Utility
>> 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:MorsVitaEst
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No objections :)
0
 

Author Comment

by:MorsVitaEst
Comment Utility
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now