Environment issue with Bonjour API
Hi all,
I've been having one of those really annoying problems that you just KNOW must be some damn simple setting somewhere and can't for the life of you figure it out.
I wanted to write a simple java program to use Apple's DNS Service Discovery APIs to broadcast a service on a wifi network (for the Bonjour zero-configuration protocol). The code itself is very simple (and runs on my friend's computer).
However, when I run this code I get the following runtime exception:
Code :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jdns_sd in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.apple.dnssd.AppleDNSSD.<clinit>(DNSSD.java:596)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.apple.dnssd.DNSSD.<clinit>(DNSSD.java:529)
at server.ServiceAnnouncer.registerService(ServiceAnnouncer.java:22)
at server.Main.main(Main.java:17)
Now I must say that there was some fishy things going on when I was installing the Bonjour SDK. First, it didn't install. I forget what the error message was, but it prompted me to go to Control Panel and uninstall 3 items marked "Java Update blah blah". It installed after that, placing a bunch of files in C:\Program Files\Bonjour SDK\ . However, the files seemed to be different than those on my friend's computer. Namely, I couldn't find a dns_sd.jar file anywhere. So I got that file from my friend, placed it in a folder on the desktop, and added to the project.
In my desperate attempts to fix this, I also added any directory with Bonjour SDK files to the PATH variable and edited the eclipse ini file to run the java vm with the -Djava.library.path option, again adding those directories to the path. All to no avail.
So if anyone knows how I can fix this situation, I would highly appreciate it. Alternatively, if anyone knows how I can purge all java related files, settings, registry values, etc. (WHATEVER THERE MAY BE) out of my system in order to do a clean install with all the files in the right places, that would be good too.
Cheers,
DR
Re: Environment issue with Bonjour API
Hey DarkRoast,
Seems like the issue is that you are using some native methods in your program and the native libraries are missing from the path.
Here is what java docs says about UnsatisfiedLinkError : "Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native"
Here is one link from sun about the native method usages and properties to be set: Sun Native Methods
This user encountered the same problem and resolved it on his own from Apple-Discussions
In case if you want to print what your java library path is, you can do it using following:
Code Java:
public void getSystemProperty() {
String path = System.getProperty("java.library.path");
System.out.println(path);
}
Hope that helps you to sort out the issue.
Goldest
Re: Environment issue with Bonjour API
Thanks, Goldest.
I hadn't seen the Java documentation on native methods, but I had found that thread on the Apple forums. That guy fixed the issue on a *nix box using the make files of the SDK. On Windows, that doesn't help me much.
However, I did get the program running on another way older PC running a fresh install of WinXP and the latest JRE, so that keeps me happy for now.