Thursday, August 13, 2009

Installing support for Java development

Previous: Installing support for Ruby development.

Basic software installs


I installed the Java development tools, Eclipse, and Maven with these commands:
sudo apt-get install sun-java6-jdk
sun-java6-plugin maven2 eclipse
To check which version of Java was the default after the install, I ran
java -version
It displayed 1.5.0, so I ran this command to set version 6 as the default:
sudo update-java-alternatives -s java-6-sun
After that when I ran java -version it came back with 1.6.0.

To verify maven2 was installed correctly, I ran the following command:
mvn --version
No problems at this point.

To verify Eclipse was installed correctly, I went to the Applications -> Programming on the main menubar and saw there was an entry for Eclipse. I selected it, saw that it started, and exited. I noticed the version was 3.2. I will check into getting a more recent version later.

Maven configuration


Although maven2 appeared to have installed correctly, I was unable to locate the local repo or the maven home directory or any environment variable settings pertaining to maven. A quick web search failed to turn up any useful information about the default location where apt-get installs maven2.

As far as I could tell, being a n00b and all, the environment variables maven2 supposedly needs to be set were not set, and there was no local repo. I decided to try
mvn archetype:generate
just to see whether it would do anything or complain about missing components or unknown paths or whatever. I chose quickstart when prompted, and it worked perfectly. It also created .m2/repository as it downloaded dependencies. Nice to know.

Upgrading Eclipse to 3.5 "Galileo"


At the time I installed it, the latest Eclipse release wasn't yet included in the Ubuntu distro. John Paulett provides a nice set of instructions for installing it on Ubuntu 9.04 on his site at http://johnpaulett.com/2009/06/26/install-eclipse-galileo-3-5-on-ubuntu-jaunty-9-04/. Using his instructions as a guide, this is how I installed Eclipse 3.5:
  1. Created a directory for Eclipse under /home. John recommends ~/bin/packages/eclipse, and he later installs Galileo in ~/bin/packages/eclipse/eclipse3.5 because he needs multiple versions of Eclipse. I don't need multiple versions, so I installed it in ~/bin/packages.
    cd ~/bin
    mkdir packages
  2. Downloaded the 64-bit version of Eclipse 3.5 (long lines are broken for readability in Blogger):
    cd packages
    wget http://d2u376ub0heus3.cloudfront.net/galileo/
    eclipse-java-galileo-linux-gtk-x86_64.tar.gz
  3. Next, I unpacked the archive in place, in the packages directory:
    tar xzvf eclipse-java-galileo-linux-gtk*.tar.gz
  4. I deviated from John's instructions at this point, and just updated /usr/share/applications/eclipse.desktop to point to the executable I had just installed:
    Exec=/home/dave/bin/packages/eclipse/eclipse

I started Eclipse from the main menu, Applications -> Programming -> Eclipse, and it started the new Galileo version. Eclipse had no trouble opening one of the workspaces I had copied over from my OS X system.

Eclipse configuration


I set the M2_REPO classpath variable in Eclipse to point to the local repo. I started Eclipse and navigated to Window -> Preferences, then expanded the tree menu items Java -> Build Path -> Classpath Variables.

I noticed that this version of Eclipse comes with an M2_REPO already defined. It points to the default location of /Users/dave/.m2. Then I chose Edit and changed the value to /home/dave/.m2.

Migrating Java development projects


I copied my ~/.m2/repository from the MacBook Pro to an external drive, and then from there merged it with the ~/.m2/repository on Ubuntu.

I copied my eclipse-workspaces directory from the MacBook Pro to the external drive, and from there to the ~/projects directory on Ubuntu.

Next step was to try and build the projects I'm currently working on to discover what configuration options I would have to change to get things working on the new system. I've been around the block too many times to expect things to "just work." Somewhere, something must be pointing to a resource that doesn't exist on the new system, or depends on a different version of something than the one I've installed. I decided to try building a Function Point Analysis application I'd been working on last year. It's a good test case for maven2 because it's got multiple components and a hierarchy of POMs.

I was surprised and pleased when mvn compile worked on the first try. I ran mvn test and got two failures out of many, many tests. Old, dusty neurons fired, reminding me that these tests used to fail with maven on my old system, too. They worked under Eclipse. So it was time to see if Eclipse would "just work," too. Wouldn't that be nice? Sure it would. Actually, I knew it wouldn't work because I needed to change the build dependencies in Eclipse to reflect their new locations. But I could at least see that no other, unexpected errors occurred.

The project would not build inside Eclipse because references to external libraries were invalid. I expected this, since I had set things up differently on OS X. I knew I would have to redefine a few things with the new setup. I was satisfied that things were in place and would work. There was just some housekeeping to do since I had decided to organize the files differently on the new system. Java was good to go!

Next: Installing Tomcat - FAIL!

No comments:

Post a Comment