Maven is an awesome build tool for JAVA, but it has some long parameter names that I don’t like to remember, so I put my often used tasks of maven in batch files.
install.bat
mvn install:install-file -Dfile=%1 -DgroupId=%2 -DartifactId=%3 -Dversion=%4 -Dpackaging=pom -DgeneratePom=true
This installs the specified .jar file in the local repository located in
C:\Documents and Settings\*User*\.m2\repository
where *User* is your username. Four arguments are required: jar_file, group, artifact and version.
new.bat
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=%1 -DartifactId=%2
I use this one to create new projects for stand-alone java programs. Two arguments required: group and artifact.
webnew.bat
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=%1 -DartifactId=%2
This one creates a new project for a web application. Two arguments required: group and artifact.
More maven commands
mvn idea:idea– generate IDEA project filesmvn eclipse:eclipse– generate Eclipse project filesmvn clean package– clean target directory, rebuild and packagemvn jboss:deploy– deploy project to local jboss instancemvn jboss:undeploy– undeploy project from local jboss instance
pom.xml
<build>
<finalName>myProject</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<encoding>utf-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
This is a snipet from pom.xml (maven configuration) file that I often add after creating a new project.
Ant tasks in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-antlr</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
<configuration>
<!-- put Ant tasks here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
This is very useful when you have some specific tasks that you were using in Ant and you don’t know the maven equivalent or if they’re custom made.
This is just a short compilation of things that I do with maven on a regular basis. There’s a lot more to this tool than shown here, and I’m still learning it myself. You can get more information on how to get started with maven here.
0 Responses to “Using maven”