Personal tools
You are here: Home HowTos How to compile with Maven
Log in


Forgot your password?
 

How to compile with Maven

— filed under:

Some Tango devices and shared libraries come with the maven system build. This HowTo explains how to set up and compile with Apache Maven

I.Maven

Maven is not only a build tool but also a project manager with capabilities to download the required dependencies for you.
More details :

II.Installation

Basic requisites

  • Java (tested with JDK6)
    • The JRE Edition is sufficient for C++ compilation
    • The JDK Edition to compile Java project like TangORB
    • minimal version : Java 5 but 6 is mandatory for the most of Tango's Java libraries and Tango's maven plugins
  • Maven :

    • http://maven.apache.org/download.html

    • Version 2 or earlier (tested with 2.1 ; may work with 2.2.1 ; not tested with 3)

Requisites for Java compilation

  • Nothing else

Requisites for C++ compilation

  • Compiler : any that the CERN's  freehep-nar-plugin can support http://java.freehep.org/freehep-nar-plugin/intro.html (see "aol" section)
    • GCC 4.4 or MSVC 8 (VS2005) are mandatory to compile with Soleil's artifact
  • OS : any that the CERN's  freehep-nar-plugin can support http://java.freehep.org/freehep-nar-plugin/intro.html (see "aol" section)
    • !!! Binaries from Soleil's maven repository are only compliant with 32 bits Linux or Windows

 

    III. Configuration

    Maven configuration

    All overrided configuration can be declared into 2 settings files, where you can define the http proxy, the different public maven repositories ...

    • the user settings file is located to $HOME/.m2/settings.xml

    • the system settings file is located to $M2_HOME/conf/settings.xml

     

    Tango's maven repository

    In order to build a Tango project based on maven, Soleil has set up a maven repository where maven can download automagically the different versions of the declared dependencies.

    The Soleil's maven repository  : http://www2.synchrotron-soleil.fr/controle/maven2/soleil/

    To take account of the above repository, the settings file have to declare it in a new profile section :

    <?xml version="1.0" encoding="UTF-8"?>
    <settings>
        <activeProfiles>
            <activeProfile>soleil-internet</activeProfile>
        </activeProfiles>
        <profiles>
            <profile>
                <id>soleil-internet</id>
                <repositories>
                    <repository>
                        <id>other</id>
                        <url>https://oss.sonatype.org/content/groups/public</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                    </repository>
                    <repository>
                        <id>JBoss</id>
                        <name>jboss-maven2-release-repository</name>
                        <url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
                    </repository>
                    <repository>
                        <id>soleil</id>
                        <url>http://www2.synchrotron-soleil.fr/controle/maven2/soleil</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </snapshots>
                    </repository>
                </repositories>
                <pluginRepositories>
                    <pluginRepository>
                        <id>other-plugin</id>
                        <url>https://oss.sonatype.org/content/groups/public</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                    </pluginRepository>
                    <pluginRepository>
                        <id>soleil-plugins</id>
                        <url>http://www2.synchrotron-soleil.fr/controle/maven2/soleil</url>
                        <releases>
                            <enabled>true</enabled>
                            <updatePolicy>daily</updatePolicy>
                        </releases>
                        <snapshots>
                            <enabled>false</enabled>
                        </snapshots>
                    </pluginRepository>
                </pluginRepositories>
            </profile>
        </profiles>
    </settings>

     

    IV. Building an existing project

     

    The most common way to build is go to the project's directory where a file "pom.xml" exists and type :

    mvn install

    1. Maven begins by download all dependencies needed for the compilation into a local cache (well known as "local repository") located by default to $HOME/.m2/repository
    2. Afterwards maven launch the compilation phase by calling the system compiler
    3. Finally maven install the result into the local repository located by default to $HOME/.m2/repository. This action allows to share the output binaries by the different projects on the machine.

    N.B : The temporary files are also located into the directory "target" directly under the project's directory

    mvn clean

    1. delete the directory "target"

    N.B : You can call the different phases in one command : mvn clean install

     

    In the chapter X, you will find other useful command.

    IV. Create/modify a project

    Pom.xml

    All the specific directives to build a project are defined in the file "pom.xml" located under the project's directory.

     

    The pom.xml defines several informations about the project : the source code management, the developers involved, how to build with the different platform, how to test the project, how to generate the documentation...

     

    The 3 main information that allow to identify a project are :

    1. groupId : define a category of software ; usually the domain of the main maintainer, eventually with a class of software
      • The groupId could be for example : org.tango, fr.soleil, fr.soleil.deviceservers
    2. artifactId : define the name of the project
    3. version : define the version of the project

     

    With these 3 identifiers, maven could resolve the dependencies to download for you.

     

    The Version

    Like the source code management for the source, maven is able to manage the version also for the binaries. For Maven, the notion of version is very important and allows to distinct a binary from the others from the same project.

    So maven comes with the new annotation "-SNAPSHOT" in the end of the version, means the project is in phase of development, allows to distinct also the ouput binaries along the development.

     

    So a simple rules is :

    When a new development begins, increments the version and add "-SNAPSHOT" until the project is noted unstable.

     

    The Super Pom

    To lighten the pom.xml, the common configuration of the different project is defined by a so-call "super pom" acts as a parent in the inheritance in the Object model.

    Soleil has defined 2 major parents : fr.soleil.super-pom-java and fr.soleil.super-pom-C-CPP

     

     

    V. Use from IDE

    Eclipse and M2Eclipse

    Maven can be used with eclipse for Java projects thanks to its plugins system.

    We recommand to use the plugin "m2eclipse" http://www.sonatype.org/m2eclipse/ but others exist (Eclipse IAM ...).

    Configuration:

    • In the preferences of the maven plugin, make it point to your Maven installation and settings files
      Here the image "M2Eclipse-Configuration.jpg"

     

    Netbeans

    Since the version 6.7, Netbeans comes with a default plugin for maven

     

    Configuration :

    • In the preferences of the maven plugin, make it point to your Maven installation

     

    VI. Useful commands

    coming soon

     

     

    Document Actions