Major Maven goals
Maven is a project management tool.
It has many goals which can build and deploy your projects.
This article introduces about how to use goals with sample commnds.
Generate project
First, you must generate test project.
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
This command with those parameters will be able to generate a project.
The archetypeGroupId
parameter shuld be specifiled a package prepared by maven.
You can also create original archetypeGroupId
by myself.
The groupId
shuld be specified a name of package you like.
The artifactId
shuld be specified a name of project you like.
Executing this command, you have to input any parameter to generate project.
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 312:
enter
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
enter(1.1)
Define value for property 'version': 1.0-SNAPSHOT: :
enter
Confirm properties configuration:
groupId: com.mycompany.app
artifactId: my-app
version: 1.0-SNAPSHOT
package: com.mycompany.app
Goals
The mvn command has various subcommands called "goal"
.
You can create a jar or deploy a war with various ways of specifying goals.
Basically, if you know types and actions of goals, you will be able to use maven.
Also, maven has the concept of a plugin.
You can extend maven’s behavior by developing a plugin.
I will introduce about the major goals and it’s usage below.
I can’t introduce maven everything in this article.
So a person who is interested in other goals, please see the following URL further.
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
Please execute the mvn command in the directory where pom.xml is located.
mvn compile
It can create .class
files which are compiled by java under the target/classes path.
mvn test-compile
It can create .class
files of test cases which are compiled by java under the target/test-classes path.
mvn test
It can create .class
files and test .class
files which are compiled by java under the target/classes and target/test-classes path.
Then run the test based on test .class
files and save the result in target/surefire-reports.
Maven’s default test framework is JUnit.
It’s definition is described in the pom.xml.
mvn package
It can create .class
files and test .class
files which are compiled by java under the target/classes and target/test-classes path.
Then run the test based on test .class
files and save results in the target/surefire-reports path.
It can generate a jar file under the target/ path.
In other words, it executes compile, test-compile, test and jar:jar at once.
You can see the test results statistically using the Surefire plugin.
http://maven.apache.org/surefire/maven-surefire-report-plugin/
mvn clean
It will delete the target directory.
It must be executed before compile, test-compile, test or package etc.
mvn install
It can deploy the created artifact (jar file and pom.xml) to the local maven repository.
For example: /root/.m2/repository/com/mycompany/app/my-app/1.0-SNAPSHOT/
It shuld be executed when other projects need to refer to artifacts.
mvn site
Based on pom.xml, project information can be output to HTML.
You can check the list of jars and so on used by the project.
mvn idea:idea
It converts a project into a folder structure that can operate on IntelliJ.
You execute this comand if you want to develop on IntelliJ with existing project.
It will generate .iml
, .ipr
, .iws
files.
mvn eclipse:eclipse
It converts a project into a folder structure that can operate on Eclipse.
You execute this comand if you want to develop on Eclipse with existing project.
It will generate .classpath
, .project
files.
Plugins
I will explain the famous plugin for maven.
Several plugins can be used even in the default state.
mvn jar:jar
It can generate a jar file under the target/ path.
http://maven.apache.org/plugins/maven-jar-plugin/
mvn war:war
It can generate a war file under the target/ path.
Execute when you want to create web application.
http://maven.apache.org/plugins/maven-war-plugin/
This command should fail if you run it on this test project.
Because this test project is not a project for web applications.
If you want to create a project for Web application, you can create it using the following command.
* mvn archetype:generate -DarchetypeGroupId=maven-archetype-webapp -DgroupId=com.mycompany.web.app -DartifactId=my-web-app
For other type of archetypeGroupId to create the project please check the following URL.
http://maven.apache.org/guides/introduction/introduction-to-archetypes.html
Tips
To use the mvn command you basically need access to the Internet.
If you run it under the proxy please add the proxy setting in pom.xml.
There is also a tutorial on maven.
If you do not know anything about maven, you try this one (I recommend it).
http://maven.apache.org/guides/getting-started/
Comments
Post a Comment