Thursday, August 28, 2014

Defining Maven Compiler Plugin

Hi again,
After a long time away (in South America), when i decided to try to open another Simple Maven Project in Java,
I remembered one of the most annoying things in Maven when opening a new project,
Each time i find myself forgetting the way to define the relevant compiler version in the POM.xml.

"Why should i do that" you say? Because the default value of the compiler is Java 1.5, and now days, when the newest Java version is 8, 
I think we would like to get some new features to the language :)

So, straight forward, this is the way to do that: 
(That's for Lazy me to be able to copy/paste)

A little elaboration:
This all should be under the "<build>" tag, as a plugin, and the relevant attributes are: source and target.
They are regularly set to the same version, in our case we'll set them to the newest JDK version "1.8".

And for "dessert", even if it's a little application that does the stupidest thing, you might want to close is as a Runnable Jar File,
Every common IDE (Like Eclipse or IDEA) gives you the option to export your product, but, aren't we using Maven? so let's do that correctly...

We would do that via the "Maven Assembly Plugin" (The second plugin under the build tag).
You should only define the way you want the jar to be packed (With or without the dependencies), and the Main Class you'd like to run at the start up of the application.

If you want more information please read at the official Maven Site (You'll see much more useful plugins there).
Maven Compiler Plugin
Maven Assembly Plugin

Thank you all for reading,
Demi Ben-Ari