Maven on OSX

Once upon a time, Mac OS X came with Maven pre-installed.  Nowadays we have to install it ourselves, alas.

Luckily, it's fairly simple.  First, you have to install Homebrew; just scroll to the bottom of that website and execute the command provided.   When I pasted the command directly into the Terminal, it didn't work (error: "Illegal variable name.").  But when I went into "sh" first, then it worked.  It asked me to verify that I was OK to some permissions updates, and I also had to install developer tools that I hadn't yet on this machine.  Then it installed.

After that, I followed advice from this popular StackOverflow question and typed:
brew install maven
(while still in "sh").

Now, whenever you are in "sh", you can use the "mvn" command.  At this point, I went on to install Maven Integration for Eclipse.

After installing the plugin, I found that you can right-click on your Eclipse project and go Configure --> Convert to Maven Project.  This asks you to type in the GroupID, ArtifactId, Version, etc..  When I did that, it created a pom.xml descriptor for me in the root of my project folder.

When I double-clicked pom.xml, it automatically opened in the Maven POM Editor.  In here, I found a "Dependency" tab.  When I clicked Add, it asked for GroupID, ArtifactId, Version, etc.  I observed that this looks a LOT like the XML shown in sample pom.xml files around the web.

So, I typed in:

Group ID: org.glassfish.jersey.containers
Artifact ID: jersey-container-servlet
Version: 2.5.1

Where did I get this info?  Just Google around and find a sample pom.xml... it is obvious looking at the XML what the GroupID, ArtifactID and Versions are.

Then I clicked OK, then I Saved pom.xml.   Then it automatically built my workspace.  When I went under Java Resources --> Libraries --> Maven Dependencies, I noticed some familliar Jersey Jar files there.   Did it download those automatically for me??? It must have.  I can't believe I didn't have to manually download the jars and add them to Properties -> Java Build Path

But first I have to go feed my kid some lunch.

Bye.

UPDATE:  OK, Hibernate is working now too.  That is, I have a Java class with Hibernate imports, and they are not red and underlined.  I used:

Group ID: org.hibernate
Artifact Id: hibernate-core
Version: 4.3.5.Final

No comments:

Post a Comment

Translate