| Sign In/My Account | View Cart

O'Reilly Emerging Telephony Conference January 24-26 2006, San Francisco, CA

Content:
• | All Articles
• | Apache and Web Serving
• | AppleScript
• | Cocoa Programming
• | Database and Sys Admin
• | Designing for Aqua
• | Developing for Mac OS X
• | Digital Photography
• | Email and Related
• | Java on Mac OS X
• | Mac Weblogs
• | Mac OS X Conference
• | Mac OS X Innovators
• | Music and iTunes
• | Networking and Wireless
• | Product Reviews
• | QuickTime and iMovie
• | Terminal App and Unix
• | Switch to OS X
|  | Running Mac OS X Tiger Mac OS X Tiger in a Nutshell FileMaker Pro 8: The Missing Manual iWork '05: The Missing Manual Switching to the Mac: The Missing Manual, Tiger Edition iLife '05: The Missing Manual iPod Shuffle Fan Book GarageBand 2: The Missing Manual Podcasting Hacks Mac OS X: The Missing Manual, Tiger Ed Degunking Your Mac, Tiger Edition Mac OS X Tiger Pocket Guide Learning Unix for Mac OS X Tiger Mac OS X Tiger for Unix Geeks Essential Mac OS X Panther Server Administration Making Music on the Apple Mac iMovie HD & iDVD 5: The Missing Manual iPod and iTunes: The Missing Manual iPhoto 5: The Missing Manual Office 2004 for Macintosh: The Missing Manual AppleScript: The Missing Manual All About Your iPod Photo (PDF) Revolution in The Valley Mac Annoyances iBook Fan Book PowerBook Fan Book Cult of Mac iPod and iTunes Hacks Modding Mac OS X Mac OS X Power Hound |  |
Print |  | Add to Project
Tags: rendezvous java zeroconf osx programming Bookmark with del.icio.us
## Java Programming on the Mac A Rendezvous with Java by Michael Brewer 08/31/2004 During WWDC this year, Apple released Java source for Rendezvous. You can now write Java applications that can call on a Rendezvous service discovery on Mac OS X, Windows, and any POSIX system using code supplied by Apple. Apple included the Java libraries in the Rendezvous for Windows Technology Preview. Everyone else needs to get the source from Apple to build the Java libraries. In order to get the source, you need to connect to Apple's Darwin CVS server. Apple's CVS how-to was written for TCSH and needs updating, so don't bother with it. But I'll walk you through it -- don't worry. The very first thing you need to do is to agree to the Apple Public Source License (APSL) while logged in with your Apple ID. Once you have the legalese taken care of, launch Terminal and type in the following two commands:
    export CVS_RSH=ssh
    export CVSROOT=:ext:apsl@anoncvs.opensource.apple.com:/cvs/apsl
Open a new TextEdit (or any other text editor you prefer) window and paste the following into the document:
    checkout -P

    update -P -d

    diff -u -d -b -w

    rdiff -u

    cvs -z3
Saving .cvsrc
If you're using TextEdit, make sure the document is plain text (opposed to the RTF option). Now save this file as ~/.cvsrc as you can see in the screenshot. Select the Use "." button from the resulting window. The text editor may save the file with a .txt extension -- you can find out by typing `ls -A` in Terminal. If this is the case, `mv .cvsrc.txt .cvsrc` will remedy it. Entering `man cvs` into Terminal will provide you with all of the information you need on these commands -- I'll leave that bit of research up to you in the interest of brevity.
Finder protects you from yourself -- this time it's OK.
You're now ready to check out the source. Type `cvs co mDNSResponder` into Terminal. You may get a message stating that the authenticity of "anoncvs.opensource.apple.com" can't be established and asking if you're sure you want to continue. I can't find any documentation from Apple on what their RSA key fingerprint should be, so I had to assume I was not the victim of a man-in-the-middle attack and reply `yes` to this prompt. You will only see this prompt the first time you connect. At the prompt for your password, enter your Apple ID and its passphrase separated by a colon (e.g. steve@mac.com:insanelygreat) as the password. If you entered the right password, your Terminal will be spammed with a listing of all of the resources being checked out and they will be copied to ~/mDNSResponder/.
Compiling the Java libraries in Xcode.
Back in Finder, open the mDNSResponder folder and the mDNSMacOSX subfolder. Open the mDNSResponder.pbproj file -- launching Xcode. Expand the Targets section with the disclosure triangle and select the dns_sd.jar and libjdns_sd.jnilib targets, then choose Build from Xcode's Build menu. This will compile the targets to a build folder in mDNSMacOSX, open the mDNSResponder/mDNSMacOSX/build folder from Terminal, copy dns_sd.jar into /Library/Java/Extensions/, and put libjdns_sd.jnilib into /usr/lib/java/.
    sudo cp dns_sd.jar /Library/Java/Extensions/

    sudo cp libjdns_sd.jnilib /usr/lib/java/
Still inside Terminal, go to the ~/mDNSResponder/Clients/Java/ folder and type `javac SimpleChat.java`. This will create the SimpleChat.class file along with TargetListModel.class, TargetListElem.class, SwingQueryListener.class, SwingBrowseListener.class, SimpleChat$1.class, and ListenerThread.class. Once those files are compiled, you can double-click on SimpleChat.class to run the application. Great, it runs. But chatting by yourself is no fun. You need to run SimpleChat somewhere else before Rendezvous can swing into action. If you don't have a separate computer to test out the program, you can always use fast user-switching. Fast user-switching might actually be preferable in this case because if you're using a separate computer, you need to make sure you have the `dns_sd.jar` and `libjdns_sd.jnilib` files in place on it as well. Make sure you have the application in a place accessible by both users. I used my ~/Public folder. Login as another user and then navigate to the first user's Public folder and open SimpleChat.class.
Hmmm, something went wrong.
What is this error? Reading through this article and following the steps, it is sometimes easy to overlook some details. If you saw that same error, you forgot to copy all of the other class files to Public along with `SimpleChat.class`. Now you either need to go back to your first computer or your first user and copy the rest of the files. When all of the files are there, SimpleChat will run and you can chat to yourself or your own willing Mr. Watson.
The first transmission.
There has got to be a better way of distributing the application, though, right? There is. Apple has wisely provided Jar Bundler. Jar Bundler will take all of your Java application's resources and bundle them up into a Macintosh application bundle. This means that the Java application will only execute in a Macintosh environment, but it's a good way to tailor a distribution of all of your cross-platform Java code into a more Mac-like experience. Open Jar Bundler from /Developer/Applications/Java Tools/. Choose SimpleChat.class as the Main class for the bundle. Check the "Use Macintosh Menu Bar" and "Disable .app Package Navigation" checkboxes. I'm also using the Fire icon from Brandon's Chat Icons. You could let Jar Bundler use Apple's default Java application icon, but this gives SimpleChat a bit of style.
Packaging up the Java application.
Switch to the Classpath and Files tab, and add all of the other class files -- unfortunately you have to add them individually. I've found that it makes it a bit easier to find the class files when you sort the file list by Date Modified in descending order. Change to the Properties tab and set the Version to `1.0`, Identifier to `com.apple.SimpleChat`, Get-Info String to SimpleChat 1.0, and Bundle Name to `SimpleChat`. You're finally ready to select Create Application -- name it `SimpleChat`. Now you can easily distribute SimpleChat, assuming that the Java Rendezvous libraries are already installed on the destination Mac. ### Final Thoughts Congratulations! You've just rolled Java Rendezvous libraries and built a Rendezvous enabled chat client from open source code, while learning how you can deploy this code -- usually reserved for geeks -- in an attractive package. With Apple’s gift to the community in the form of these Java libraries, I can't wait to see some cross-platform, Rendezvous-enabled applications out there. It'll be great to be able to enjoy a wide array of zero-configuration networking with a larger pool of people than just other Mac users.
| Related Reading Mac OS X for Java Geeks By Will Iverson Table of Contents Index Sample Chapter Read Online--Safari Search this book on Safari: Code Fragments only
Michael Brewer is a developer based near Charlotte, North Carolina. His interests include web development of various flavors, databases, and Java. One of the off-shoots of these activities is his website Brewed Thoughts. Return to MacDevCenter.com. ### Related Articles: jRendezvous: Java and Rendezvous Working Together With Rendezvous making IP networking simple, and Java making cross platform network programming possible, a beautiful friendship emerges -- jRendezvous. It allows Java programs running anywhere (not just Mac OS X) to participate in Rendezvous networks. Java programs can listen for, and advertise, services on the network with ease. Seth Ladd shows you how this works. Post your questions and comments here. You must be logged in to the O'Reilly Network to post a talkback. Showing messages 1 through 9 of 9. not possible to start up 2004-10-29 02:56:30 Lianne [Reply | View] Hi, I have the code and I used javac *.java, because javac SimpleChat.java does not work (SwingBrowseListener and SwingQueryListener not found). javac *.java went well. But if I start up SimpleChat or BrowserApp (with java -cp . SimpleChat), I get the error message: Exception in thread "main" java.lang.NoClassDefFoundError: com/apple/dnssd/ResolveListener. I think the ResolveListener is in the .lib file. I even put this file in the . dir. But it is not working. If I use the .jar file, it is working. But I like to change code, so I need to use java(c). What Am I doing wrong? Can't compile SimpleChat.java 2004-10-12 23:31:27 doenermord [Reply | View] So why might it be that I can't run SimpleChat.java through javac? Do I have something in my env not setup properly that it can't resolve the symbol for "SwingBrowseListener"? Can't compile SimpleChat.java 2004-10-13 07:29:52 mbrewer [Reply | View] SwingBrowseListener.java is another source file that needs to be compiled. Make sure you have that and the six other Java source files in the same folder when you compile SimpleChat.java. Can't compile SimpleChat.java 2004-10-13 07:39:43 doenermord [Reply | View] Yeah it's odd. It must be an env issue, as I can individually compile all of the classes in the folder except for SimpleChat and BrowserApp. It's like it can't find SwingBrowseListener, SwingQueryListener, or SwingResolveListener, even when the files are sitting right there. Accessing Apple's CVS 2004-09-13 08:38:08 cmurrell [Reply | View] I'm having a tough time getting access to the source. I logged into their developer connection and agreed to the APSL, but am unable to authenticate with Apple's CVS server. Accessing Apple's CVS 2004-09-13 13:57:40 mbrewer [Reply | View] What error message do you receive? Accessing Apple's CVS 2004-10-02 10:25:48 cmurrell [Reply | View] Got to the code. It took a week or so to receive an email back from Apple, verifying the agreement (or something). Now time for some fun. Launchable Jar file 2004-08-31 17:43:39 mbrewer [Reply | View] Would you rather just create a Jar file that you can share with other platforms as well as easily launch on Mac OS X just like an application package? Instead of creating an application package with Jar Bundler, you can use the `jar` command. But you'll lose the Mac Menu Bar and other nice Macintosh touches. `jar cvfm SimpleChat.jar SimpleChat.manifest *.class` Launchable Jar file 2004-09-04 03:44:09 VernonS [Reply | View] The Mac Menu Bar, at least, can be addressed by setting system properties within the applicaton. No impact to the application on any platform other than the Mac, and the Menu Bar will appear as expected. |  | Sponsored by:

Copyright © 2000-2005 O’Reilly Media, Inc. All Rights Reserved. All trademarks and registered trademarks appearing on the O'Reilly Network are the property of their respective owners. For problems or assistance with this site, email