Start a new Maven project with a simple shell script
February 28, 2011 15:39:08 Last update: February 28, 2011 15:39:08
For simple projects,
Example usage:
archetype:generate seemed too heavy for me, but creating the standard Maven file structure by hand is such a chore. So I created this simple script to ease the pain:
#!/bin/sh if [ $# -lt 4 ]; then echo "Usage $0 <projectName> <groupId> <artifactId> <rootPackageName>" exit 1 fi projectName=$1 groupId=$2 artifactId=$3 rootPackageName=`echo $4 | tr . /` mkdir -p src/main/java/$rootPackageName mkdir src/main/resources mkdir -p src/test/java/$rootPackageName cat >pom.xml <<EOF <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>$groupId</groupId> <artifactId>$artifactId</artifactId> <version>1.0.0-SNAPSHOT</version> <name>$projectName</name> <build> <!-- Name the final artifact --> <finalName>\${project.artifactId}</finalName> </build> <dependencies> </dependencies> </project> EOF
Example usage:
./initmvn.sh myProject theGroupId theArtifactId com.example.mainpack