I’m still in the learning phase of using Maven, so bare with me. Here is my script to create an executable HelloWorld-jar file using Maven (it requires the file sample-pom.xml listed after the script):
#!/bin/bash## Description: Create a simple Java project using Maven.## Status: Works## Author: draptik## Created: Mon Jun 15 21:17:24 2009## REQUIREMENTS# ============## 1. Maven## 2. This script requires the file "sample-pom.xml"!!!## 3. The "sample-pom.xml" file should be located in the same folder as# this script.## USAGE# =====## 1. Copy this script and "sample-pom.xml" to a newly created test# folder (ie ~/tmp/maventesting/).## 2. Run this script## DETAILS# =======## This script creates a "quickstart" Maven project, then overwrites# the created pom.xml with something more sensible (including some# useful Maven plugins), and runs "java -jar .jar".## User settingscompanyName="org.foo"appName="my-app"## Static filesamplePom="sample-pom.xml"pdinfo="[PDINFO] "## Delete old buildsecho"$pdinfo""====== REMOVING PREVIOUS BUILDS ====================="echo"$pdinfo""rm -rf \"$appName\""rm -rf "$appName"## Create Maven skeleton#### NOTE: You can exchange the first 2 lines with:#### mvn archetype:create \## -DarchetypeGroupId=org.apache.maven.archetypes \#### This will result in a warning that "archetype:create" is## deprecated. The warning states that you should use## "archetype:generate". This archetype is interactive by default. To## skip the interactive part and choose the default (="quickstart")## you have to pass the option "-Dinteractive=false" to Maven.echo"$pdinfo""====== MAVEN CREATION ================================"echo"$pdinfo"""mvn archetype:generate \ -DinteractiveMode=false\ -DarchetypeGroupId=org.apache.maven.archetypes \ -DgroupId="$companyName"\ -DartifactId="$appName"## Show the diff between generated pom.xml and sample-pom.xmlecho"$pdinfo""====== DIFF BETWEEN GENERATED AND MY POM.XML ========"echo"$pdinfo""diff -u \"$appName\"/pom.xml \"$samplePom\" "diff -u "$appName"/pom.xml "$samplePom"## Overwrite generated pom.xmlecho"$pdinfo""====== OVERWRITING GENERATED POM.XML ================"echo"$pdinfo""cp \"$samplePom\" \"$appName\"/pom.xml"cp "$samplePom""$appName"/pom.xml
## Move to newly created projectcd"$appName"## Make an executable jar fileecho"$pdinfo""====== MAKING THE FINAL JAR FILE ===================="echo"$pdinfo""mvn package"mvn package
## Move to target foldercd target
## Run the Hello-World exampleecho"$pdinfo""====== TESTING THE JAR FILE =========================="echo"$pdinfo""java -jar $appName-1.0-SNAPSHOT.jar..."echo"$pdinfo""If the next line does not read \"Hello World!\", something is wrong"java -jar "$appName"-1.0-SNAPSHOT.jar