Project setup with Maven at the Command Line
30 Jan 2014Introduction
A few utilities exist to manage your build, dependencies, test running for Java projects. One that I’ve seen that is quite intuitive (once you wrap your head around the xml structure) is Maven. According to the website, Maven is a “software project management and comprehension tool”.
The main benefit I’ve seen already is how the developer’s work-cycle is managed using the “POM” (project object model). The POM is just an XML file that accompanies your project to describe to Maven what your requirements are to build, test & package your software unit.
An excellent, short post can be found on the Maven website called “Maven in 5 minutes”.
Today’s post will focus on Maven installation and getting a “Hello, world” project running.
Installation
I’m on a Debian-flavored Linux distribution, so you may need to translate slightly between package managers. To get Maven installed, issue the following command at the prompt:
Check that everything has installed correctly with the following command:
You should see some output not unlike what I’ve got here:
If you’re seeing output like what I’ve got above - that’s it. You’re installed now.
First Project
Getting your first application together is pretty easy. A “quick start” approach is to use the quick start templates to generate a project structure like so:
Maven will then go out and grab all that it needs from the web to get your project setup. It’s now generated a project structure for you (in a directory called “hello”) that looks like this:
Editing the file that they put into the source folder for you (at src/main/java/org/temp/App.java), you can see that your job is already done:
Build it and give it a run!
You should see some output like this:
Most important line there is “Hello World!”.
There is so much more that you can do with Maven for your projects. Check out the documentation - that’s it for today.