Sunday, February 23, 2014

Review of STS 3.5.0.M2

STS 3.5.0.M2 experience so far

After a weekend of grueling frustration trying to convert a Spring Boot application to a war file so as to be able to deploy it to a normal (as opposed to embedded) Tomcat server using STS 3.0.4 release, I was nearly ready to give up and seek out another IDE when I suddenly noticed that Pivotal had just announced the release of STS version 3.5.0.M2.  I figured I had nothing to lose, so why not try it?

What follow are my impressions so far based on some very short (under 1 hour) experiences, and for those who want to cut to the chase, I will just say that my entire weekend of frustration was just *vanquished* within ten minutes of starting STS 3.5.0.M2!!!

I began by testing the critical application I was stuck on all weekend using STS 3.0.4:

gs-convert-jar-to-war

First I added the [new] source from the new dashboard via “Import Getting Started Guide”
    • chose maven as project type since gradle seemed greyed out
  1. Run--> Maven install
BUILD SUCCESS. . . but
        [WARNING] The requested profile "pom.xml" could not be activated because it does not exist.

SUCCESS!  
Davids-MacBook-Pro:gs-convert-jar-to-war-complete dave$ find . -name "gs-convert*.?ar" -print
./target/gs-convert-jar-to-war-0.1.0.war

  1. Run As—> Spring Boot (Hello World runs as expected).
  2. Deploy war onto Tomcat on another server - works as expected:


I am still savoring this!  Meanwhile, no time to waste - I am back to tinkering.  More reports to follow, but just know that you should definitely not wait to download STS 3.5.0.M2!

Sunday, February 16, 2014

Loading Spring Tool Suite (STS) onto OSX 10.9.1


This is my first episode in what hopes to be a series - good for either learning about Spring on a Mac from the Mac Noob point of view, or as a substitute for counting sheep (or both).

Loading Spring Tool Suite (STS) onto OSX 10.9.1

As I began to install the Java SDK in my usual way - which is to simply download the zip file, extract it somewhere, and point to it with a JAVA_HOME environment variable, I began to think that maybe I ought to check out the Java Development Guide for Mac, which seems a little dated and has lots of broken links:

After bumping around through the preceding Apple site for a while, I finally opted to seek out Java assistance elsewhere.

I seemed to encounter two schools of thought for Installing the Java SDK on a Mac: a. Oracle or b. OpenJdk :
-------------------------------------------------------------------------
  a. Oracle (v7.51)

  b. OpenJdk (Open Source - to basically roll your own custom SDK)
    
    . Install git and mercurial (hg) from http://www.macports.org/
    . etc. etc.… (I chose option a)

Java Documentation:
-------------------------------------------------------------------------


1. Setting up JAVA_HOME for version 1.7:
————————————————————————————————————

  a. Edit .bash_profile (or .profile) and add these two lines:

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
export PATH=$JAVA_HOME/bin:$PATH;

  b. Source the .bash_profile to activate the new environment variables in your bash shell.

. ~/.bash_profile



2. STS (for MAC)
-------------------------------------------------------------------------

Problem: STS installer currently requires Java SE 6 (on Mavericks OSX 10.9 anyway)


Solution:

  a. Download the tar.gz-Version of STS, extract that, and go from there:


  b. Choose a destination directory like a file folder on the Desktop, and un-tar the package there:

tar zxf spring-tool-suite-3.4.0.RELEASE-e4.3.1-macosx-cocoa-x86_64.tar.gz

  c. Create a desktop icon (alias) pointing to <dest directory>/springsource/sts-3.4.0.RELEASE/STS using Finder and drag it to the Desktop for easy access.

  d. [optional] Create another Desktop folder called workspaces

  e. Click the new STS icon on the Desktop to run STS

     1. At startup, choose a workspace location (Note: leave the "Use this as the default and do not ask again icon" unchecked for easier access to other workspaces at next startup).


---

Browse run the Spring Guides on http://Spring.io - when ready, take the Tutorials to learn best practices on designing Spring applications. 

Most of the projects can be built with maven, but some also require Gradle.  You can download Gradle from: http://www.gradle.org/downloads

  f. Install Gradle

For a very simple example project which is built using Gradle, as well as instructions for installing Gradle, see the following Guide:

    1. From The STS Dashboard, choose "Guides> Building Java Projects With Gradle"

(your mileage may vary - I got Permission errors trying to run the Gradle binaries straight up, so rather than hack the file system with chmod and chown, etc., I chose to look elsewhere to see whether maybe I was simply doing it wrong).

It was then that I found an alternate gradle install method using HomeBrew documented here :

3. Install Homebrew

Note: here is where things get a little nasty, so read through this section first to see what *not* to do, then at the end I summarize a little in the "Lessons Learned" section.  I thought of editing this as a more straight forward set of steps, but I wanted to record what really happened too - in hopes of helping the Xcode and HomeBrew developers in smoothing out the Noob user experience.  Ideally, I'd like to get some feedback to see if together, we can't eventually put together a cleaner version of this particular section.

So here is the ruby command which supposedly solves world peace:

But, if you are like me and don't already have Xcode installed, the Xcode installer is invoked during the Homebrew install and according to all of the reviews (including this one too now apparently), it can be a little tricky - depending upon what you might already have installed.  In my case, on a new Mavericks Mac (OSX 10.9.1), I didn't yet have Xcode, so on the Popup with three buttons: "Get Xcode" "Cancel" and "Install", I chose "Get Xcode", then on the popup AppStore splash page which appears to be customized for Xcode, I clicked the "Free", followed by "Install", followed by AppStore payment setup with handshakes back and forth to Paypal, etc. (my billing choice in this case)... eventually landing me back in the AppStore without any clue as to what happened with the Xcode installation.  Rather than aborting the ruby command from the terminal window (which was my first impulse), I then did a search on "xcode" in the AppStore, and retried the Xcode install, this time from the normal Appstore menu grid of apps, again pressing "Free" and then "Install App" on the Xcode app, and this seemed to launch the expected rocket launcher icon which then proceeded to download all 2.09 Gig of the Xcode app as expected (time for a lunch break - as this is a *big* download!).  When finished, the Xcode App icon in the AppStore also read "Installed" as expected.  Back to the terminal window to press a key to continue... and everything seemed fine, but then I noticed a little comment towards the end of the install console log: "Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo."

Here is the whole terminal session log:

Davids-MacBook-Pro:proggies dave$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Installing the Command Line Tools (expect a GUI popup):
==> /usr/bin/sudo /usr/bin/xcode-select --install
Password:
xcode-select: note: install requested for command line developer tools
Press any key when the installation has completed.
==> Downloading and installing Homebrew...
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
------------------------------

... which is a little odd, since it did prompt me for a password part way through the Xcode install (as shown in the log)?  Anyway, running "brew doctor" to be safe... I get the same error.  So now I try "sudo su -" and re-run brew doctor as root...

Davids-MacBook-Pro:~ root# brew doctor
You have not agreed to the Xcode license agreements, please run 'xcodebuild -license' (for user-level acceptance) or 'sudo xcodebuild -license' (for system-wide acceptance) from within a Terminal window to review and agree to the Xcode license agreements.
You have not agreed to the Xcode license agreements, please run 'xcodebuild -license' (for user-level acceptance) or 'sudo xcodebuild -license' (for system-wide acceptance) from within a Terminal window to review and agree to the Xcode license agreements.
You have not agreed to the Xcode license agreements, please run 'xcodebuild -license' (for user-level acceptance) or 'sudo xcodebuild -license' (for system-wide acceptance) from within a Terminal window to review and agree to the Xcode license agreements.
Warning: No developer tools installed.
You should install the Command Line Tools.
Run `xcode-select --install` to install them.
Warning: You have not agreed to the Xcode license.
Builds will fail! Agree to the license by opening Xcode.app or running:

    xcodebuild -license

-------------------------------
...so at this point I am feeling pretty silly as it looks like maybe I should have really done the original curl command as root to begin with (but don't bother trying that approach as you will see below).

Instead, I try the suggested command in the error message above "sudo xcodebuild -license" - typing "agree" at the end.  And then the suggested command "xcode-select --install"...

Davids-MacBook-Pro:~ root# xcode-select --install
xcode-select: error: no developer tools were found, and no install could be requested (perhaps no UI is present), please install manually from 'developer.apple.com'.
-------------------------------

So here is where I get frustrated and start over as root with the curl command:


Davids-MacBook-Pro:~ root# ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Don't run this as root!

-------------------------------
OK, so how about logging out of root and trying the curl with sudo?
Davids-MacBook-Pro:proggies dave$ sudo ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
Password:
Don't run this as root!
-------------------------------
...and then, just as I was about to give up and start over from scratch, I tried this:
Davids-MacBook-Pro:proggies dave$ sudo xcode-select --install
xcode-select: note: install requested for command line developer tools
...eh Voila! I got a GUI popup which installed the Xcode app in about 2 minutes!
So now I try this:
Davids-MacBook-Pro:proggies dave$ sudo brew doctor
Password:
Your system is ready to brew.
-------------------------------
Lessons learned...
I think I could have skipped the last few steps and simply used "sudo xcode-select --install" after to agreeing to the license to begin with!  The problem is that none of the instructions say to use sudo on the xcode-select --install command - they just say do this with and do that without sudo, so it's a little like playing Simon says.
Of course, this might have also gone a little smoother if I had simply installed Xcode first to begin with, then installed HomeBrew... but the blog entry I found didn't seem to mention this (or maybe it simply assumed that everyone already has Xcode installed?)
-------------------------------
Anyway, so now, finally I can install maven and gradle (here I first attempted to use sudo on this brew install as well, but I was scolded severely for trying - go figure!):

4. Install Maven

    $ brew install maven
Davids-MacBook-Pro:proggies dave$ brew install maven
######################################################################## 100.0%

🍺  /usr/local/Cellar/maven/3.1.1: 61 files, 6.3M, built in 11 seconds

-------------------------------

5. Install Gradle

Note: As of May, 2013, the new Android build system only supports Gradle versions 1.3/1.4. This means it won’t work with the latest version of Gradle. You’ll have to follow the instructions at gradle.org/installation to install a prior version of Gradle. Otherwise you could simply install the latest version using Homebrew.
    $ brew install gradle
Davids-MacBook-Pro:proggies dave$ brew install gradle
######################################################################## 100.0%
🍺  /usr/local/Cellar/gradle/1.11: 153 files, 44M, built in 2.8 minutes
Need to set up a GRADLE_HOME to point to /usr/local/Cellar/gradle/1.11.  Add this to .bash_profile:
export GRADLE_HOME=/usr/local/Cellar/gradle/1.11;
export PATH=$JAVA_HOME/bin:$GRADLE_HOME/bin:$PATH;
Then activate the new environment variables by sourcing the .bash_profile:
Davids-MacBook-Pro:proggies dave$ . ~/.bash_profile
You can verify you have the correct version of Gradle installed using the following command:
    $ gradle -v

Davids-MacBook-Pro:proggies dave$ gradle -v
------------------------------------------------------------
Gradle 1.11
------------------------------------------------------------
Build time:   2014-02-11 11:34:39 UTC
Build number: none
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421
Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_51 (Oracle Corporation 24.51-b03)
OS:           Mac OS X 10.9.1 x86_64

SUCCESS !!!

Now my STS installation will be cooking with fire!



So Begins the Battle!

Having finally taken the plunge after about a million years worth of false starts and regrets, I finally went out and purchased a new MacBook Pro Mavericks laptop.  My first application to tackle was the Spring Tool Suite (STS) from the wonderful people at Pivotal, a tool which I have always traditionally used on either a PC or a Linux workstation.

After seeing that there seemed to be a mix of opinions on how to go about installing STS on a Mac, I decided to take notes.  Hopefully these notes might help someone else out there who is also struggling, as after a day and a half of battling what seems to be an Apple snub of Java and/or Oracle, combined with my own Mac noobism, I seem to have conquered the fud and at last I am declaring victory!

Enjoy!

Dave McLure