Using the OpenIMAJ Maven Archetype with different versions
The OpenIMAJ tutorial contains instructions for creating a Maven project using a Maven archetype. The tutorial is kept up-to-date with the latest release version of OpenIMAJ. This blog post reiterates the usage of the archetype and looks at how you can change the version of the OpenIMAJ dependencies to a different release version of OpenIMAJ, or to the current snapshot which is built continuously with every commit to the SVN repository (if the unit tests pass!).
To paraphrase the tutorial, in order create a new OpenIMAJ project, run the following command:
mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate |
Maven will then prompt you for some input. Firstly, when prompted, choose the openimaj-quickstart-archetype
and choose the latest version. For the groupId
, enter something that identifies you or a group that you belong to (for example, I might choose uk.ac.soton.ecs.jsh2
for personal projects, or org.openimaj
for OpenIMAJ sub-projects). For the artifactId
enter a name for your project (for example, tutorial01
). The version can be left as 1.0-SNAPSHOT
, and the default package is also OK. Finally enter Y
and codess return to confirm the settings. Maven will then generate a new project in a directory with the same name as the artifactId
you provided.
A complete session with the archetype might look like the following:
homer:~ jsh2$ mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) @ standalone-pom << org.openimaj:openimaj-quickstart-archetype (Maven quickstart archetype for OpenIMAJ) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1 Choose org.openimaj:openimaj-quickstart-archetype version: 1: 1.0.3 2: 1.0.4 3: 1.0.5 Choose a number: 3: 3 Downloading: http://maven.openimaj.org/org/openimaj/openimaj-quickstart-archetype/1.0.5/openimaj-quickstart-archetype-1.0.5.jar Downloaded: http://maven.openimaj.org/org/openimaj/openimaj-quickstart-archetype/1.0.5/openimaj-quickstart-archetype-1.0.5.jar (3 KB at 28.2 KB/sec) Downloading: http://maven.openimaj.org/org/openimaj/openimaj-quickstart-archetype/1.0.5/openimaj-quickstart-archetype-1.0.5.pom Downloaded: http://maven.openimaj.org/org/openimaj/openimaj-quickstart-archetype/1.0.5/openimaj-quickstart-archetype-1.0.5.pom (4 KB at 117.6 KB/sec) Define value for property "groupId": : uk.ac.soton.ecs.jsh2 Define value for property "artifactId": : tutorial1 Define value for property "version": 1.0-SNAPSHOT: : Define value for property "package": uk.ac.soton.ecs.jsh2: : [INFO] Using property: openimajVersion = 1.0.5 Confirm properties configuration: groupId: uk.ac.soton.ecs.jsh2 artifactId: tutorial1 version: 1.0-SNAPSHOT package: uk.ac.soton.ecs.jsh2 openimajVersion: 1.0.5 Y: : Y [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: openimaj-quickstart-archetype:1.0.5 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: uk.ac.soton.ecs.jsh2 [INFO] Parameter: artifactId, Value: tutorial1 [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: uk.ac.soton.ecs.jsh2 [INFO] Parameter: packageInPathFormat, Value: uk/ac/soton/ecs/jsh2 [INFO] Parameter: package, Value: uk.ac.soton.ecs.jsh2 [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: groupId, Value: uk.ac.soton.ecs.jsh2 [INFO] Parameter: openimajVersion, Value: 1.0.5 [INFO] Parameter: artifactId, Value: tutorial1 [INFO] project created from Archetype in dir: /Users/jsh2/tutorial1 [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:07.078s [INFO] Finished at: Mon Jul 09 17:00:53 BST 2012 [INFO] Final Memory: 7M/81M [INFO] ------------------------------------------------------------------------ |
Once Maven has successfully built the project, you can navigate to the project directory:
cd tutorial1 |
build the sample project generated by the archetype with (this might take a while the first time around as the dependencies are downloaded):
mvn assembly:assembly |
and finally, run the sample with:
java -jar target/tutorial1-1.0-SNAPSHOT-jar-with-dependencies.jar |
So, now lets say you want to change the version of OpenIMAJ which the project is using. If you want to change to a different release version of OpenIMAJ, then just open the pom.xml
file created by the archetype and edit the openimaj.version
property defined near the top of the file to reflect the version you want:
... <properties> <openimaj.version>1.0.5</openimaj.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> ... |
If you want to change to the current development version (called a snapshot in Maven parlance), then you currently need to make two changes; from OpenIMAJ 1.1 onwards only the version will need to be changed as above. Firstly, change the version to the current snapshot (1.0.6-SNAPSHOT
at the time of writing):
... <properties> <openimaj.version>1.0.6-SNAPSHOT</openimaj.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> ... |
and secondly, add the following to the repositories
section (note that this won’t be necessary in OpenIMAJ versions beyond 1.1):
<repositories> ... <repository> <id>OpenIMAJ Snapshots maven repository</id> <url>http://snapshots.openimaj.org/</url> </repository> ... </repositories> |
If you don”t know what the latest snapshot version is, you can look it up by clicking here (picking the biggest version number if there are multiple folders).
Once you’ve updated the version, you need to rebuild the project by running mvn assembly:assembly
again. If you’re using the Eclipse integration described in the tutorial, you’ll also need to re-run mvn eclipse:eclipse
.