Is there any option/plugin for maven command line interface that allow us to create a new project ? I mean for something user friendly like npm is.
Something like typing on a console $ xptocli init
?
Is there any option/plugin for maven command line interface that allow us to create a new project ? I mean for something user friendly like npm is.
Something like typing on a console $ xptocli init
?
I actually got so frustrated with the very long maven command that you have to write that I wrote a bash script for this exact purpose. I call it mvnproj
and saved it in usr/local/bin
. Here is the code
if [ $# -eq 4 ]; then
cd $1
mvn archetype:generate -DgroupId=$4.$3.$2 -DartifactId=$2 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false;
elif [ $# -eq 3 ]; then
mvn archetype:generate -DgroupId=$3.$2.$1 -DartifactId=$1 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false;
elif [ $# -eq 2 ]; then
mvn archetype:generate -DgroupId=$2.$1 -DartifactId=$1 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false;
else
mvn archetype:generate -DgroupId=$1 -DartifactId=$1 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false;
fi
You can call it in 4 different ways
mvnproj dir projname groupname tld
mvnproj projname groupname tld
mvnproj projname groupname
mvnproj projname
For 1. dir
is the directory where you want it placed, in 2-4, it will be placed in the directory you are currently in. projname
is the name of your project, groupname
is your company's name, and tld
is the top level domain of your company. Example calls
mvnproj /tmp example stackoverflow com
mvnproj example stackoverflow com
mvnproj example stackoverflow
mvnproj example
You can use Maven's Archetype Plugin to create a new project:
$ mvn archetype:generate -B \
-DgroupId=org.mygroup \
-DartifactId=myartifact \
-DarchetypeArtifactId=maven-archetype-quickstart
From the official maven documentation
In order to create the simplest of Maven projects, execute the following from the command line:
Note: The Archetype Plugin (mvn archetype:generate
) allows the user to create a Maven project, this plugin is included with maven by default.
mvn -B archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
Once you have executed this command, you will notice that a directory named my-app has been created under C:\Users\yourname\my-app (in windows 7) and this directory contains a file named pom.xml that should look like this:
<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>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven Quick Start Archetype</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>