Oct
19
2011
Mac For Developers
Author: Doc180As a Java\Python\IOS Developer, who uses Mac as the primary development environment, I have learned few tips and tricks along the way.This article is my attempt at sharing what I had learned in my brief journey.
The Initiation:
The first thing to do, while starting your development in Mac, is to get the Mac Development package installed. Register as an Apple Developer. Its free at http://developer.apple.com/programs/register/. Now if you are planning to develop and distribute applications for OS X or IO S devices, then you need to enroll as Mac and (or) IPhone Developer respectively. Its a subscription service and starts at 99$ per month, for individual developer. More information here.
Once you have registered yourself as an Apple Developer (or Mac or Iphone developer), you need to install the latest version of Xcode (4 as of this writing). Xcode is an objective C\C\C++ IDE. More importantly, it comes bundled with some nice developer tools like FileMerge, Make, Property List Editor etc. You will find these tools to be extremely useful.You can find Xcode here or you can download from the App Center (Installed in your Mac). If you only have Apple Developer Account, then you might have to shell some money to download Xcode, but its worth it. (Xcode is very useful for a Developer in Mac, even if you are not planning to develop apps for Iphone, you will still use it for general package compilation tasks and writing apple scripts to automate tasks).
Setting Up Environment Variable:
Setting up the environment variables is more complicated that it needs be in Mac. Its one of the things that stumped me in the beginning. To summarize, I know of three ways.
Using your terminal.(Updating bash profile). The environment variable not be visible to GUI Applications.
- How?: Fire up terminal and enter “export PATH=$PATH:/<your new path>”
Updating environment.plist properties. Some GUI Application (like IntelliJ IDEA) may still not see variables set this way and hence this mechanism is not adequate. Prior to Snow Leopard (10.6), GUI Applications launched using spotlight, will not read the environment variable set in environment.plist.
- How? If you had downloaded Xcode, then you would have Property List Editor installed in your machine. From Xcode 4, property list editor is integrated, as part of Xcode. Prior to Xcode 4, you could just fire up your Property List Editor ( Use spotlight, Cmd + Space and search for property list editor),then create an environment.plist file under ~/.MacOSX folder (~ stands for your home directory). From Xcode 4, onwards, you need to open up Xcode 4 and create a new File (Cmd + N) and choose Resource -> Property List (under Mac OS X) and create a environment.plist file under the same directory as above. Then you can add, properties as key value pairs.
By using Launchd. Probably the best solution, that will work universally across all kind of apps, that were invoked using any possible mechanism. But will need rebooting of system, for changes to take effect.
- How?
- Open terminal.
- Enter “sudo emacs /etc/launchd.conf” (You could use any of your preferred text editor. This file may not exists, so create one if its not available).
- Edit this file and add the environmental variables.For example:
setenv JAVA_VERSION 1.6
setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
setenv MAVEN_OPTS -Xmx1024M
setenv M2_HOME /Applications/Dev/apache-mavenSave the file and reboot your system.
Like I mentioned, the last method will work universally. So I suggest that you use it. (Please let me know if there are better ways).
Preparing your Mac for Java Development:
By default, Mac comes prebuilt with a list of JDK versions. Please note that, it takes time for Apple to release updated JDK Version.
Check the version of JDK: Using “javac -version” in terminal.
List and Switch JDK Versions: You can see the list of available JDKs using using a utility called “Java Preferences”(use spotlight).If you do have multiple versions installed, you could change your current version to an older version, by just dragging that version to the top of the list, in the General tab. The Java_Home environmental variable will be changed automatically for you.
Get the Java_Home directory: Its not easy to remember the Java_home, thankfully there is a command to find it for you. Fire up your terminal and enter the following command. “/usr/libexec/java_home”
Download the Java Document and the source code: If you want to integrate Java API Docs with your IDE and have java source code available for debugging and reference, then you have to download the source and documents separately from Apple Developer Downloads. Search for “Java for Mac OS X Developer Package”.Download the correct package for your OS X Version and install it. We will see on how to incorporate this in Intellij in a future article.
Preparing Your Mac For Python Development:
Python comes pre installed with your Mac. It is highly recommended to update your python to a newer version. You can find newer version of python here. http://www.python.org/download/releases/. For more usage instruction, see here. Mac also comes installed with IDLE, a python IDE. But the best python IDE in my opinion is Pycharm ( From the Jetbrains Team). One of the added advantage of python in Mac is, it could be used for scripting Mac applications.(in place of Apple Script).
Changing a Program’s Initialization Parameter:
This is a question, that might occur to a new Mac convert. For instance if you want to change JVM arguments of Intellij IDEA, you will usually change the corresponding .ini file in windows.Mac’s Equivalent is “info.plist”. For example, to change the init params of application (Lets say IDEA.), Cmd + Click on the application’s Icon in the dock. You will be taken to the program’s installation directory. Context click on the application finder item and choose “Show Package Content” and search for “info.plist” file within this directory.(usually it will be under contents). You can edit the info.plist, using the property list editor. (Double click on the file and it will automatically open it up in property list editor, provided you installed Xcode package.).
General Development Tools Recommendation:
I am not the qualified enough to provide a comprehensive recommendation on the tools that you need to install in Mac. Check MacAppStorm for more detailed recommendations, So I am just going to list the tools that I use…
- For Version Management: Cornerstone for subversion and GitX for Github.(Although I stick to terminal for Git).
- For Comparing and Merging Files: FileMerge comes prepackaged as part of Xcode developer bundle and it is very handy. Kaleidoscope is probably the best but its not free.
- For FTP Transfer: Cyberduck (Free) and Transmit FTP (Paid).
- Text Editor: BBEdit (Paid), Textwrangler (Free) and Emacs.( GNU Version and a more user friendly version specifically for Mac called “Aquamacs”).
Finally one word of caution: Sometimes Mac update will overwrite you default version of SDK or dev tools. For instance, one Mac Update, removed all my previous version of Java and updated all my simlinks to the latest version (1.6). Another time, Mac decided to remove my Maven 2 and replaced it with Maven 3. So pay attention to what is being updated, when you get a software update alert.