You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

Example Maven Project

Overview

The SLAC CVS contains a sample module called ExampleMavenProject that can be used as a template for your own Maven-based projects.

Obtaining

To obtain the ExampleMavenProject module, execute this CVS command.

cvs -d :pserver:anonymous@cvs.freehep.org:/cvs/lcd co ExampleMavenProject

This project is ready to use as a template or a platform for experimentation with package imports, Java code execution, etc.

Anatomy of the Project

Directories

The directory into which the project was checked-out will be called the "base" directory. By default, it will be called "Example Maven Project".

This directory should contain two subdirectories.

src
test

The src dir is the root area for Java source code. (All the code for your project should be placed someplace under src.)

The test dir contains unit tests that use the JUnit testing framework.

Maven Build Files

The ExampleMavenProject module contains the following Maven files, all of which should be included in a new Maven project.

build.sh
maven.xml
project.properties
project.xml

build.sh is a helper script for building the project with a set of maven commands.

maven.xml sets-up some project build defaults.

The project.properties file is used to set named variables (properties) that determine certain project behavior, such as whether deprecation warnings are shown or the tests are skipped. You can put any custom maven settings into this file.

For instance, to show Java deprecation messages when compiling, remove the "#" from in front of this line in the project.properties file.

#maven.compile.deprecation=on

The project.xml file is the primary Maven configuration file that lists all the project's meta-information and its dependencies.

There are two additional test files.

src/ExampleMavenProject.java
test/ExampleMavenProjectTest.java

The src/ExampleMavenProject.java is a simple example of a Java source file.

The file test/ExampleMavenProjectTest.java is a very basic test case example that runs the main of a project class with some dummy arguments.

Building

To build the project from the command-line on Linux, Cygwin, etc.

cd ExampleMavenProject
./build.sh

Or you can use Maven directly.

maven -Drun.install=$(pwd) -Dmaven.test.skip=true clean jar:install jas:install run:install

Including both jar:install and jas:install is used only for illustrative purposes, as the jar:install target is executed by jas:install.

Testing

Now, test the run script.

./bin/ExampleMavenProject

This message should be printed to the screen.

ExampleMavenProject - Hello world!

Freehep Run Plugin

The cross-platform script creation is done using the Freehep Run Plugin, which is listed as a dependency in the project.xml file.

Java files can be added into src or test.

Classes placed here can access packages in the org.lcsim framework and all of its dependencies.

Simply rerun the build command given above to compile any classes that you add.

Using as a Template

To use ExampleMavenProject as a template for your own new project, replace the "ExampleMavenProject" string with the actual name of your own project in project.xml.

The CVS directories should all be removed.

find . -name "CVS" -exec rm -rf '{}' \; &> /dev/null

Then add to your CVS project all the files listed under the Anatomy section using CVS's import and add commands.

cvs import -m "Initial commit of MyProject" myProjectDir vendor initial

The above is an example only.

Contact your system administrator about adding a project to your local repository. Contact Tony Johnson if you want to use the LCD CVS at SLAC.

  • No labels