Revisiting Hibernate with Spring on Mac OS X – Part I

I was getting bored and wanted to revisit Spring and Hibernate on my new found love machine – my Macbook Pro. The Mac OS gets a little getting used to, especially if you one is new to the way Mac works. Things are a little difficult to find – unlike the right click world. Rest assured, you can do much more, but as I said earlier – it gets a little getting used to ūüôā

Anyways, back to the problem. If I have to try something, I usually follow the steps:

a. Google about what I am doing (here I started by saying spring + hibernate + maven sample).

b. I found a few links and decided to Download Spring STS, Maven 3.0.4 and MySQL ( The JDBC connectors etc. could be outsourced to Maven).

I setup everything well. Keep in mind to install MySQL from the .dmg file. If you are like me, you might try to do it from the .tar.gz file initially, but trust me, it introduces a lot more troubles on the Mac OS. Just get it installed by using the .dmg file available by following instructions at: http://www.simonwhatley.co.uk/installing-mysql-on-mac-osx-10-6-snow-leopard.

Now, I also downloaded the MySQL Workbench for Mac OS at : http://dev.mysql.com/downloads/workbench/

I started working out a sample from : http://singgihpraditya.wordpress.com/2009/03/19/simple-maven2-spring-25-jpa-and-hibernate-integration/ but I ran into trouble when I ran the POM file РI wanted to see if the project would build properly. You can run the POM file without writing a single line of code and check if the required libraries will be downloaded properly.

It started failing by saying something like :

Downloading: ->
    http://repo1.maven.org/maven2/javax/transaction ->
      /jta/1.0.1B/jta-1.0.1B.jar
[WARNING] Unable to get resource from repository central ->
    (http://repo1.maven.org/maven2)
...
[INFO] Failed to resolve artifact.

required artifacts missing:
 javax.transaction:jta:jar:1.0.1B

Now, this essentially means that the Maven runtime is not able to find the required JAR file in the repository it is searching. The key factors are : which Maven and which repository.

On a Mac OS, the default Maven is usually /usr/bin/mvn. So, to change that in Spring STS, one has to ‘Add’ a ¬†Maven runtime by pointing to the correct Maven installation of your choice instead of using the embedded one.

Secondly, the default repository is ~/.m2/repo. To change that in Spring STS, go to Preferences -> Maven -> User settings and point to the correct user settings file (which is <Maven directory>/conf/settings.xml). and update user settings.

Make sure that you have a local repository like this:

<localRepository>/Users/trishulmukherjee/.m2/repository/</localRepository

>

Now, in order to install the JTA jars, remember to explicitly go to the Maven installation directory as configured above, download the JTA jar files from

http://java.sun.com/products/jta/

and run:

mvn install:install-file \
  -Dfile=./jta-1_0_1B-classes.zip \
  -DgroupId=javax.transaction \
  -DartifactId=jta -Dversion=1.0.1B \
  -Dpackaging=jar

and run the ./mvn <….> command since otherwise, the JAR file will get installed in the wrong repository and Maven runtime will again fail to detect the JTA jar files. Also, make sure that the path to the zip file is correct because Maven is dumb and it won’t even warn if the file is in a different location. It really pissed me off when I found out my mistake.

So thats it! Run the pom file and it should download all the required files without errors.

Advertisements

Getting started with Richfaces 4 and Maven

I tried to create a basic Richfaces project using the document : http://docs.jboss.org/richfaces/latest_4_X/Developer_Guide/en-US/pdf/Developer_Guide.pdf but ran into trouble with the following line:

mvn archetype:generate -DarchetypeGroupId=org.richfaces.archetypes -DarchetypeArtifactId=richfaces-archetype-simpleapp -DarchetypeVersion=4.0.0-SNAPSHOT -DgroupId=org.docs.richfaces -DartifactId=new_project.


As of Dec 2011, the issue is that my installation of Maven (ver. 3.0.3) would fail since it can’t find the required archetype. ¬†The latest archetype version being 4.1.0.Final, this ¬†works only when the ‘archetypeVersion’ in the above command line is changed to ‘4.1.0.Final’.

Hope this helps someone who’s just getting started with Richfaces and Maven.