This is an old revision of the document!


Maven

Why use Maven ?

Maven is one of several possible build tools, it's easy to use and supported in Netbeans + Eclipse. Maven is preinstalled on mac (3.0.3), maven is also bundled with Netbeans (3.0.5 we'll use that version to avoid problems).

Advantages of using Maven are numerous :

  • jars are referenced with an xml config file, they are no longer stored in SVN
  • once you get the hang of developing with Maven, you'll notice you need to spend less time getting your dependencies together.
  • it's easier to test if your project can work with an updated version of one of the dependencies.
  • when a company repository is used: the jars and wars you build will be saved there.
  • when a company repository is used: only your current project has to be opened. (improves IDE startup time)
  • you can divide the project in multiple smaller projects, which improves code reusability
  • a buildprogress which is easy to adjust.
  • projects can combine multiple projects into a single war
  • it's easier to see what jars we depend on.
  • There's plugins for a number of things: ftp deployment, creating a test site, …
  • possible future?: archetypes could be used to create new projects from templates :

'mvn archetype:generate eza-inno-sach' would use the template to create a new project, in netbeans this is also simplified (just need to use the search form to find the archetype).

What does it take to convert an existing project to Maven ?

  1. You create a new maven project (jar or war) & copy the source
  2. You configure the POM (set parent to company POM parent, usually MentoringSystems. There is no parent JCP project… yet)
  3. You start resolving dependencies

Resolving dependencies :

  • version number : Most of the existing jars have a version number, if they're not named with a version number you should take a look inside the JAR, META-INF/manifest.mf sometimes contains the version number.
  • use the repository search to find the xml config statement for your dependency, you should be able to use the one in nexus.
  • If you are sure a dependency is missing, try finding it with google (for example: 'maven antlr' or 'maven antlr 2.7.6'.
  • If you have a dependency which won't resolve (can't be found in repository) you should contact repository admin.

Creating a new BUILD project (1 build per customer/product) :

  1. Netbeans : New project

First screen : Maven → Web Project

Next :

  • projectname: follow naming convention : JCPIS_ANALYSE_BUILD_<customer in caps> other projects are named JCPIS_ANALYSE_MODUL_ (for additions), JCPIS_ANALYSE_UI_ (for javascript clients like JCPIS_ANALYSE_UI_ANALYSE / UI_SACH)
  • groupname : de.jcpis.analyse
  • package : leave blank

Next :

  • Server Tomcat
  • When the project is made, you need to configure the POM first :

I recommend copying the POM of JCPIS_ANALYSE_BUILD_EFFEKT & changing 2 properties : artifactId: build-<customer in normal letters> name: JCPIS_ANALYSE_BUILD_<customer in caps>

  1. fiddle with the options in pom to generate a different build.
  2. time to change the context.xml file (located under Web Pages/META-INF/context.xml)

easiest way : copy the file from JCPIS_ANALYSE_BUILD_EFFEKT, adjust it so the path & webapp rootkey are unique

Company repository :

Think of it as the SVN for all our binary project dependencies.

  • It stores all the jars we've used, It provides a proxy so it can cache any future jars.
  • It allows us to combine several repositories in 1 url (needed for netbeans)
  • It stores our projects
  • It allows us to add 3rd party or non maven projects to the repository.
  • It can restrict the version on certain dependencies *haven't looked that far into it yet*
  • It reduces download time for dependencies

Setting up a developer machine :

  1. In case of a new developer on a mac : use a copy of Netbeans, adjusted by our company (Netbeans.app hides the maven config file)
  2. We'll provide a settings.xml file + instructions on where to put it.
  3. Check out MentoringSystems parent pom & build this one first, it contains some settings needed to recover all company projects !
  4. Check out the project you need to work on

(for example, work on model)

possible locations :

bundled maven (mac) : /Applications/NetBeans/NetBeans 7.4.app/Contents/Resources/NetBeans/java/maven/conf/settings.xml

preinstalled maven (mac) : /usr/share/maven/conf/settings.xml

installed maven (windows) : <userdir>/.m2/settings.xml

Important : updating an existing maven project :

Some of the old projects (like jav2013 etc…) were marked as FINAL versions (version nr does not end with snapshot). Before editting these projects, you need to change the versionnumber :

<version>1.0</version>

becomes

<version>1.1-SNAPSHOT</version>

And change the reference in projects where jav2013 is used, This ensures the projects will use your latest version.

depending on the version, a different repository is used. You can't change final versions (repository won't allow it). Think of this as an extra precaution upon production release, you can ALWAYS return to a previous version or you can fix a project to use a previous version whilst development works with a newer version.

JCPIS_ANALYSE overrides

Build projects are essentially overrides, you can override ANY of the other projects by simply copying the file over to the build project, (correct folder structure required) & editting it.

JCPIS_ANALYSE plugins

Several plugin projects exist, making use of detached spring configuration. Examples are JCPIS_ANALYSE_CODIE, JCPIS_ANALYSE_SOFTFAIR.

When adding controllers it would be best to check other projects for the ORDER parameter on SimpleUrlHandlerMapping. In the future it might be better to add naming conventions or start with using spring 3.1 annotations to reduce the xml code.

JCPIS_ANALYSE login plugin

Interface : de.jcpis.analyse.security.AuthenticationFilter

Working implementation : Codie loginfilter.