![]() |
![]() ![]() |
|
||
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
|
![]() |
|
![]() |
|
![]() |
![]()
Java Programming on the Mac
by Michael Brewer |
![]() |
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/.
![]() |
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.
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.
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.
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.
Showing messages 1 through 9 of 9.
jar
command. But you'll lose the Mac Menu Bar and other nice Macintosh touches.jar cvfm SimpleChat.jar SimpleChat.manifest *.class
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 |