So I'm working on a java project for my raspberry pi and I want to create a bonjour service in java.

So when I'm coding on my mac I have the imports:

import com.apple.dnssd.DNSSD;
import com.apple.dnssd.DNSSDException;
import com.apple.dnssd.DNSSDRegistration;
import com.apple.dnssd.DNSSDService;
import com.apple.dnssd.RegisterListener;

However when I export my application and try to run on my raspberry pi I get the error:

java.lang.NoClassDefFoundError: com/apple/dnssd/RegisterListener

Obviously when executing on my mac these files are on my classpath and are able to be used, but they are not on the raspberry pi. I've tried looking around for a jar with these files but nothing seems to work. I understand that there are some resources at: http://www.macosforge.org/, but I am unsure what I actually need!?


So I have progressed past the error above. I downloaded the Posix mDNSResponder from http://www.macosforge.org/. I then copied this to my raspberry pi. Then in the mDNSPosix folder I executed the makefile:

$ make os=linux

note: I had to install bison and flex for this to work:

$ sudo apt-get install bison
$ sudo apt-get install flex

Once the makefile had finished, I then ran:

$ make os=linux install


$ make os=linux Java

This created a dns_sd.jar which has all the com.apple.dnssd.* classes in it.

So I added this to my project (On a windows machine this time, to ensure that the classes were being included from the jar), and ran on my pi.

The error I am getting now is:

java.lang.UnsatisfiedLinkError: no jdns_sd in java.library.path
    java.lang.Class.forName0(Native Method)


So I fixed this error by moving everything that had been created in the mDNSPoisx/build/prod folder to /usr/lib/

When I try to run my code now I get the following error:

com.apple.dnssd.AppleDNSSDException: DNS-SD Error -65563: SERVICENOTRUNNING
    at com.apple.dnssd.AppleService.ThrowOnErr(DNSSD.java:652)
    at com.apple.dnssd.AppleRegistration.<init>(DNSSD.java:772)
    at com.apple.dnssd.AppleDNSSD._register(DNSSD.java:571)
    at com.apple.dnssd.DNSSD.register(DNSSD.java:241)

I tried running the daemon as described in the readme.txt:

The "make install" concludes by executing the startup script (usually "/etc/init.d/mdns start") to start the daemon running. You shouldn't need to reboot unless you really want to.

But I still get the same error, any ideas?


I tried restarting the mDNS daemon, and tail the logs:

$ sudo sh /etc/init.d/mdns restart; tail -f /var/log/daemon.log 

The following is output:

Feb 10 00:20:01 raspberrypi mDNSResponder: mDNSResponder (Engineering Build) (Feb  9 2013 17:52:27) starting
Feb 10 00:20:01 raspberrypi mDNSResponder: mDNS_AddDNSServer: Lock not held! mDNS_busy (0) mDNS_reentrancy (0)
Feb 10 00:20:01 raspberrypi mDNSResponder: mDNSResponder (Engineering Build) (Feb  9 2013 17:52:27) stopping

Any ideas on what 'Lock not held!' is about?

  • 2
    Have you tried using avahi for your mDNS service? I have that running on my Pi and I have also used Java for hostname resolution via mDNS just fine on the Pi. Edit: I will test this out later and see if I can fix it.
    – Munkeh
    Commented Feb 14, 2013 at 7:51

1 Answer 1


Building the native libraries will most likely be a frustrating experience.

Consider just using http://jmdns.sourceforge.net/ instead. It is a pure Java bonjour implementation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.