Wednesday, August 7, 2013

Build Java 5 project with Maven 3 on Ubuntu 13.04

Don't get me wrong, I love Ubuntu and I find it very good for development; almost everything I need is an "apt-get install" away.
Almost...

Building legacy java 5 project with maven 3

First steps are easy, you install maven through apt-get, download java 5 from Oracle site and install it manually (there seem to be openjdk and cgj only packages).
Then you set your JAVA_HOME to point to your new installation and launch maven as usual
mvn clean install
 And that's what you get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
All maven libs in the Ubuntu package are compiled for java 6...

Do it on your own

At this point you have to get apache's distribution http://maven.apache.org/download.cgi ; say the file you downloaded is apache-maven-3.1.0-bin.tar.gz, the following command are supposed to be executed as root:
mkdir /usr/local/share/maven
cd /usr/local/share/maven
tar -xvzf <path_to>/apache-maven-3.1.0-bin.tar.gz
Then you have to point maven to work with the new installation (in a regular, non root, shell)
export M2_HOME=/usr/local/share/maven/apache-maven-3.1.0
And you're done!

No comments:

Post a Comment