Alex's Personal Blog

News and updates for friends and family

Articles tagged with maven

Better Builds with Maven [DRAFT]

Posted: Sun, 11 Mar 2007 by

As a software developer I'm constantly looking for tools and techniques to make the development process easier. I used to use a strict command-line environment and XEmacs for my Java Development until I was introduced to Eclipse which is a very nice, extensible IDE for Java and other languages (though it does Java best). The fact that I can refactor code (rename a class for example), constantly build in the background to check for errors, handle version control and project dependencies all in one place was a God-send. There was still one glaring flaw, however. Ant builds, while flexible, can be a pain to setup, even with an IDE, and because there's no standard for how to setup builds (because it's so flexible) the setup process can tend to be a bit frustrating. This is where Maven comes in. Maven is a Java tool who's mission is to standardize building a project and managing its dependencies. When creating a new project you create a simple XML document called a POM (Project Object Model) which describes the project as well as what its dependencies are.Maven defines a standard directory structure for creating projects. Because a standard is defined (though it can be overridden) there's no reading through complicated build.xml files to figure out what's going on or what targets you need to run in order to get the desired effect. This means that new developers to a project can get up to speed much faster. This also greatly simplifies the maintenance that needs to be done on the build setup of a project.With Maven the days of storing a project's dependencies in a child lib/ directory are over. When you build a project Maven will automatically download all the necessary dependencies and install them in your local repository. The local repository is for all Maven projects to use so, for example, if you use JUnit for testing purposes Maven would download the appropriate version (whichever you define), store it and make it available for use with all projects. This means you don't have to store your binary dependencies in version control. Maven handles it all for you.Maven doesn't stop there though. It can also handle generating documentation, building a website for your project and deploying your project to a shared repository for others to use and more. If that's not enough you can also integrate specialized Ant tasks into your Maven builds which will make the transition from Ant to Maven much more simple.Having said all this wonderful stuff about Maven there is a reasonable learning curve, though it's not nearly as bad as Ant's. For assistance here are some helpful links to get started with: The Official Apache Maven Site Maven in 5 Minutes - A great place to start! Maven Getting Started Guide - Once you've gone through the 5 Minute guide above this is a nice, more in-depth tutorial. Better Builds with Maven - Free online book that is a great introduction and also goes into quite a bit of depth. Proximity - For those that would like to host their own Maven repositories and Proxy external repositories this a very easy setup tool to accomplish just that.Happy coding!

Updated: 2012-02-24 11:34:25 -0800

Trouble with Maven

Posted: Tue, 11 Mar 2008 by

I've tried to use Maven during my Java development but have found it rather frustrating for a few reasons.

The documentation is a bit sparse - Most of what you need is represented but setting up your own settings, deploying artifacts a repository and other more advanced subjects are under represented. Deploying artifacts is painful - This mostly goes along with the first point. The syntax, once figured out is far from obvious and much to verbose for my taste. That's one of the drawbacks of extreme flexibility... extreme complexity.

Because I tend to be a perfectionist when it comes to code I write at home I had taken a break from coding Java for a while (except at work of course).

Recently I've had some really good ideas pop into my head as well as how to implement those ideas so I wanted to get started again with Maven. I was able to utilize the the Q4E project which is a Maven plugin for Eclipse which I've found more stable and consistent than the original M2Eclipse plugin (though I haven't tried it in a while so it may have improved). This combined with my already POM-enabled projects in source control made for a pretty easy return to Java development. Unfortunately there was some frustration just around the corner.

When my new application was getting bulky enough to start needing some logging I decided to start using log4j which is commonly used in Java development. All I needed to do was add it to my project's POM as a dependency and Maven should have taken care of downloading it and adding it to my CLASSPATH but unfortunately that wasn't the case. Maven wasn't able to figure out how to get 3 of log4j's dependencies. Usually in a case like this it gives good suggestions on where to download them. Unfortunately the links that were given kept redirecting me somewhere on the Java site that wasn't what I was after. After struggling with the issue for a few hours I gave up and started using the Java SDK's (inferior, IMHO) logging mechanism but not being able to use log4j continued to nag at me.

This morning I decided to give it another try and this time the first thing I did was a google search which brought me to this blog entry. While installing a separate piece of software, Artifactory for a Maven Repository Proxy, this was something I had done using Proximity in the past so I was pretty familiar with what to expect. As I already had a server machine setup and ready to run Tomcat I was able to install Artifactory pretty quickly. Once installed I followed the instructions in the blog post and in the Artifactory documentation for setting up Maven to look at the repository proxy first and 2 of the 3 missing dependencies were downloaded no problem. I had to do an explicit search for jms-1.1.jar to get the last dependency but I followed similar instructions for installing it into my new repository. Long story short I'm now able to use log4j in my Java coding. I can also easily deploy the artifacts I create to my own repository with ease.

Now I need to stop messing around with all this stuff and continue my coding.

Updated: 2012-02-25 17:32:35 -0800