About Paris Apostolopoulos

Paris is a senior software engineer focusing on J2EE development, loves Business process modelling and is keen on software quality challenges. He is passionate about Java and Java communities. He is a co-founder and administrator of the first Java User Group in greece(JHUG.gr) and occasional speaker on meet-ups and seminars and regular blogger.

Setup your Java development environment in your new Mac in 10 minutes (updated)

This is just a small update post that references 2 older entries ( a, b) , I just combine them in one, like an one step procedure plus making sure that everything works under the latest at the time being MacOSX 10.9 Mavericks. I am mostly targeting inexperienced or junior programmers trying to setup their environment for the first time. So you just got your shinny new Mac and you are ready for some java development, excellent, lets get started it is fairly easy!  I am going to split the whole thing into 3 simple steps, the only think you need to provide is the folder paths, you can select your own installation directories.
 
 

Step 1: Download the packages

Step 2: Install or extract the packages

The Java 6 and Java 7 downloads are in a dmg form so you just double click them and install them, the setup wizard is fairly easy. Nothing extra or magic required.

For the Ant, Maven and Gradle packages you  need to extract them at a folder of your choice, it is really up to you. So unzip them and if you like rename the unziped folders, giving them a simple name. My path of choice was /Volumes/secondary/libs

So I extracted and renamed them as follows:

  • /Volumes/secondary/libs/ant
  • /Volumes/secondary/libs/maven
  • /Volumes/secondary/libs/gradle

CapturFiles_1

Step 3: Modify your .profile

Open up your terminal navigate to your home profile, usually when you open app the application is already on your home folder if not just to it  cd  /Users/your_user_name , for me it is /Users/papo and type

vi .profile

This will open the vi editor. All you need to do is copy paste the following entries, MAKING SURE that the paths are correct for you. I assume that you already know the basic vi modes (Esc+i=insert mode, Esc+w=write mode, Esc+q=quite).

    #set the home for ant
    export ANT_HOME=/Volumes/secondary/libs/ant
    #set the home for maven
    export MAVEN_HOME=/Volumes/secondary/libs/maven
    #set the home for gradle
    export GRADLE_HOME=/Volumes/secondary/libs/gradle
     
    #creating a special home for Java 7
    export JAVA_7_HOME=$(/usr/libexec/java_home -v1.7)
     
    #creating a special home for Java 6
    export JAVA_6_HOME=$(/usr/libexec/java_home -v1.6)
     
    #making Java7 as our default java for the system
    export JAVA_HOME=$JAVA_7_HOME
     
    #Command line alias so we can switch to java6 or Java7
    alias java6='export JAVA_HOME=$JAVA_6_HOME'
    alias java7='export JAVA_HOME=$JAVA_7_HOME'
     
    #Finally put maven, ant and gradle to the system path
    export PATH=$PATH:$ANT_HOME/bin:$MAVEN_HOME/bin:$GRADLE_HOME/bin

Save your .profile and exit the terminal. Open a new One in order the changes to take effect.

Done

Now you can test your new path environment, type java -version to check that indeed java 7 is the one loaded currently or type java6 so that Java 6 becomes active.

CapturFiles_2

Type ant -version, mvn -version or gradle to check that the tools are available from your command line.

CapturFiles_3

You are done. If you are looking for a nice Java IDE to start coding then head for Eclipse and Netbeans. The latter is more suitable for junior programmers. Both of them are very very powerfull and they provide rich functionality.

Happy coding.
 

Related Whitepaper:

Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code

Use Java? If you do, you know that Java software can be used to drive application logic of Web services or Web applications. Perhaps you use it for desktop applications? Or, embedded devices? Whatever your use of Java code, functional errors are the enemy!

To combat this enemy, your team might already perform functional testing. Even so, you're taking significant risks if you have not yet implemented a comprehensive team-wide quality management strategy. Such a strategy alleviates reliability, security, and performance problems to ensure that your code is free of functionality errors.Read this article to learn about this simple four-step strategy that is proven to make Java code more reliable, more secure, and easier to maintain.

Get it Now!  

7 Responses to "Setup your Java development environment in your new Mac in 10 minutes (updated)"

  1. Divya says:

    It’s really nice to learn…

  2. Mike says:

    Don’t forget IntelliJ. It is the nicest Java IDE and has a free community version as well.

  3. Mike says:

    If you only put those environment variables in .profile it only applies to the command-line. If you also want them to be in effect system-wide (including GUI applications) then you need to put them in /etc/launchd.conf. I believe you need to reboot to get luanchd.conf to be re-read.

    • javapapo says:

      It really depends. I agree that you can do that, it is perfectly fine but personally i dont like messing around with the global environment.

      It is more clear to manage your user based profile. Maybe another user on the same machine would like something else.

      you can always change your global $PATH variable on the .profile and then javaw and java would be picked up accordingly!

  4. 3 easy steps, thanks Paris, useful tips, as always!

Leave a Reply


× three = 15



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books