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

Compare with Current View Page History

« Previous Version 10 Next »

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.

Basic Setup

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

org.lcsim Source

All of these files can be copied from org.lcsim's root directory. For instructions on obtaining org.lcsim, refer to the build instructions.

After copying over these files from an org.lcsim checkout, 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.

Source code should be put into a src/ directory. Probably the directory path for source code should be org/lcsim,.

Once the above steps are performed, typing maven should build the project into the target/ directory.

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.

  • No labels