Creating a Maven Project that Depends on org.lcsim
Overview
Maven can be used as the build system for your project. It automates most of the low-level details of dependencies and building for Java projects. For instance, it can automatically download external JARs required by your project. The org.lcsim project uses this tool for its build system, as well.
Directory Setup
Create a directory for your project and go into it.
mkdir myProject cd myProject
Now, create a directory for your source files, including directories for the org.lcsim base package.
mkdir -p src/org/lcsim
Build Files
The project's root directory needs to contain three Maven configuration files.
- project.xml - main configuration file, listing the project's core meta-information and its dependencies
- maven.xml - Maven settings, such as the default build target
- project.properties - project properties file, including source repository locations, e.g. freehep.org
These can be obtained from org.lcsim's root directory.
cvs -d :pserver:anonymous@cvs.freehep.org:/cvs/lcd lcsim cd lcsim cp project.xml maven.xml project.properties .. cd .. rm -rf lcsim
Customize the following information in project.xml for your project.
<artifactId>myProject</artifactId> <groupId>lcsim</groupId> <currentVersion>0.1</currentVersion> <organization> <name>Example Organization</name> <url>http://www.example.org</url> </organization> <description>This is an example Maven project.</description> <shortDescription>Maven Project</shortDescription> <url>http://www.example.org/myProject</url> <issueTrackingUrl>http://www.example.org/myProject/bugs</issueTrackingUrl> <repository> <connection>scm:cvs:pserver:anonymous@cvs.example.org:/cvs/example:myProject</connection> </repository> <name>myProject</name> <package>org.lcsim</package> <inceptionYear>2005</inceptionYear>
The following lines should be inserted into project.xml to make it depend on org.lcsim, itself.
<dependency> <groupId>lcsim</groupId> <artifactId>lcsim</artifactId> <version>0.9</version> <url>http://www.lcsim.org</url> </dependency>
org.lcsim is not maintained as a downloadable JAR file. Each project user should compile and build this program themselves.
Basic Build Command
The project can be build from the command line with this simple command.
maven
This builds the default jar target, installing project JARs into the ~/.maven/repository directory under lcsim.
Alternately, you can use the Netbeans IDE to build your Maven projects.
Run Plugin
The FreeHep Run Plugin can generate a run script for your project.
To enable this functionality, insert the following into the project.xml file.
<dependency> <groupId>freehep</groupId> <artifactId>freehep-run-plugin</artifactId> <version>1.1.1</version> <url>http://java.freehep.org/maven/freehep/plugins</url> <type>plugin</type> </dependency>
Maven also needs to know what class to be executed. This goes into the project.properties file.
maven.jar.mainclass=my.classpath.myMain
To build the script, execute the following target.
maven -Drun.install=$(pwd) run:install
A run script named after your project should now be placed into the bin directory.
This script sets up the classpath and executes the main function of the specified class.
public static void main(String[] args)
The script can be run from the current directory, as follows.
./bin/myProject [args]
The command line syntax of the script is completely up to you.
JAS
This target will copy the project's JAR into JAS3's extensions directory at ~/.JAS3/extensions.
maven jas:install
The version number will be stripped out of the JAR name, and any existing JAR by the same name will be overwritten.
When JAS loads, it will automatically load this JAR, making your project classes available from within JAS, itself.
Build Script
A full build command for your project could be something like this.
maven -Dmaven.test.skip=true -Drun.install=$(pwd) clean jar:install jas:install run:install
This will do a clean build, skipping tests and installing the run script to the current directory. It also puts the JAR files into the ~/maven/repository area and ~/.JAS3/extensions directories.