Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Example Maven Project

Overview

The If you want to get started quickly without worrying about the details, the SLAC CVS contains a sample Maven project module called ExampleMavenProject that can be checked-out with this used as a template for your own Maven-based projects.

Obtaining

To obtain the ExampleMavenProject module, execute this CVS command.

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

This project is " ready to go" and can be used use as a template or a platform for experimentation with package imports, Java code execution, etc.

Building

To build the example project from the command-line , assuming there is an sh shell available, e.g. on Linux, Cygwin, etc.

No Format
cd ExampleMavenProject
./build.sh

...

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

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 it by running the automatically generated run script.

No Format
./bin/ExampleMavenProject

It should print this messageThis message should be printed to the screen.

No Format
ExampleMavenProject - Hello world!

Now you can add Java Java files can be added into src or test.

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

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

Anatomy of the Project

The ExampleMavenProject module contains the following files.

No Format

build.sh
maven.xml
project.properties
project.xml
src
src/ExampleMavenProject.java
test
test/ExampleMavenProjectTest.java

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 that determine certain project behavior, such as whether deprecation warnings are shown.

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

The src dir contains Java source files.

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

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

The file test/ExampleMavenProjectTest.java is a simple example test case.

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 remainder of this tutorial shows how to create a Maven/org.lcsim project from scratch, in case you are wondering about the detailsCVS directories should all be removed.

No Format

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.

No Format

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

The above is an example only.

Tip

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.