Building applications with Apache Maven

Apache Maven is a build tool like Apache Ant, but with a completely different approach to managing software builds: where Apache Ant is like a procedural programming language for describing how to build your system, Apache Maven is more of a fully-fledged assembly line for building, packaging, testing, and running software projects.

The Maven repository at http://repo.flexive.org/maven2/ contains all [fleXive] libraries with correct dependencies set up. To use it in your Maven project, add the following repository to your pom.xml:

<repository>
    <id>maven.flexive.org</id>
    <name>Flexive repo</name>
    <url>http://repo.flexive.org/maven2</url>
    <layout>default</layout>
</repository>

The repository contains all released versions, including snapshots for all active branches that are updated from our internal continuous integration servers. Use these -SNAPSHOT revisions to use the latest features and bugfixes, but don't use them in a final product!

To resolve all dependencies of [fleXive], you also need to add the following repositories from java.net and JBoss:

<repository>
    <id>maven2-repository.dev.java.net</id>
    <name>Java.net Repository for Maven</name>
    <url>http://download.java.net/maven/2/</url>
    <layout>default</layout>
    <snapshots>
        <updatePolicy>never</updatePolicy>
    </snapshots>
</repository>

<repository>
    <id>maven2-jboss</id>
    <name>JBoss Maven Repository</name>
    <url>http://repository.jboss.org/maven2</url>
    <layout>default</layout>
    <snapshots>
        <updatePolicy>never</updatePolicy>
    </snapshots>
</repository>

<repository>
    <id>maven-dev-repository.dev.java.net</id>
    <name>Java.net Dev Repository for Maven</name>
    <url>https://maven-repository.dev.java.net/repository/</url>
    <layout>legacy</layout>
    <snapshots>
        <updatePolicy>never</updatePolicy>
    </snapshots>
</repository>

Archetypes provide a quick start for new projects. Currently we offer a archetype for a full enterprise application with web and console frontends. Since the archetype includes setup scripts for the H2 database, it can be used without external dependencies like MySQL. However, for administration tasks such as database setup you currently have to use the tools provided by the [fleXive] distribution.

The archetypes are (as the rest of the Maven modules) still under development, so please report rough edges or missing features in our issue tracker.

The archetype flexive-archetype-ear creates a multi-module enterprise application, which will be deployed as an EAR. It also allows easy integration testing with OpenEJB and offers a standalone webserver using Jetty and H2.

To get started, create a new project using the following command:

mvn archetype:generate -DarchetypeGroupId=com.flexive -DarchetypeArtifactId=flexive-archetype-ear -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeRepository=http://repo.flexive.org/maven2/ -DgroupId=mygroup -DartifactId=hello-flexive -Dversion=0.1-SNAPSHOT

This will create a new project called "hello-flexive" in the current directory. The [fleXive] version to be used can be specified in the main module's pom.xml file. By default, it is set to the current release required for all features (currently this is 3.1-SNAPSHOT). For a list of available versions, please look at the Maven repository (e.g. here).

Maven snapshot versions

The snapshot versions in our Maven repository ( 3.0-SNAPSHOT and 3.1-SNAPSHOT) are updated automatically from our internal Continuous Integration server (Hudson) with the latest stable build of the corresponding branch. A build is considered "stable" in this context if no testcase fails. The snapshot versions are a convenient way of getting and testing the latest features, however these builds are not tested manually and may cause all kinds of havoc including data loss. If possible, it is recommended to use stable versions.

The following commands (issued in the project directory) will walk you through the most important features:

mvn package

Compile and package the application. The resulting EAR file can be deployed in any supported application server (for setup instructions, consult Chapter 2, Installing [fleXive] ).

mvn install

Compile, package and install the application. If executed for the first time, the H2 database schemas will also be created in the database/h2 subdirectory.

mvn install -Pflexive-db-setup-h2 (since 3.1)

Compile, package and install the application. Manually activate the profile flexive-db-setup-h2 to reset the H2 database in the database/h2 subdirectory.

cd war , mvn jetty:run (since 3.1)

Start an instance of the Jetty WebServer to deploy our application (including the backend administration application) and OpenEJB. The available applications can be browsed at http://localhost:8080.

Additional information on working with the Maven archetypes can be found in the following blog entries:

Warning: version 3.0.x and embedded containers

Please note that some features are dependent on the [fleXive] version: H2/OpenEJB/Jetty support is only available in 3.1 or later. In order to build your project with [fleXive] 3.0.x, you have to disable the database and consoleapp modules in your root pom.xml. Then you can package an EAR file using the mvn package command.

While you can browse all artifacts at http://repo.flexive.org/maven2/, the following list enumerates those you will most likely end up using in your application.

flexive-ejb

The [fleXive] EJB layer (packaging: ejb). Add this to your EAR module.

<dependency>
    <groupId>com.flexive</groupId>
    <artifactId>flexive-ejb</artifactId>
    <version>3.0.2</version>
    <type>ejb</type>
</dependency>
flexive-shared

The [fleXive] shared classes, including all EJB interfaces. Use this artifact in modules that need to access [fleXive] via EJB, but are not EJBs themselves (e.g. web modules).

<dependency>
    <groupId>com.flexive</groupId>
    <artifactId>flexive-shared</artifactId>
    <version>3.0.2</version>
    <type>jar</type>
</dependency>
flexive-backend

The [fleXive] backend application, including all required libraries and the actual WAR package.

<dependency>
    <groupId>com.flexive</groupId>
    <artifactId>flexive-backend</artifactId>
    <version>3.0.2</version>
    <type>jar</type>
</dependency>
flexive-plugin-jsf-core

The JSF component library (includes flexive-web-shared).

<dependency>
    <groupId>com.flexive</groupId>
    <artifactId>flexive-plugin-jsf-core</artifactId>
    <version>3.0.2</version>
    <type>jar</type>
</dependency>
flexive-web-shared

Shared (framework agnostic) web classes, including authentication filters, servlets for delivering [fleXive] contents.

<dependency>
    <groupId>com.flexive</groupId>
    <artifactId>flexive-web-shared</artifactId>
    <version>3.0.2</version>
    <type>jar</type>
</dependency>