maven command to create your application
How do I make my first Maven project?
We are going to jump headlong into creating your first Maven project! To create our first Maven project we are going to use Maven's archetype mechanism. An archetype is defined as an original pattern or model from which all other things of the same kind are made . In Maven, an archetype is a template of a project which is combined with some user input to produce a working Maven project that has been tailored to the user's requirements. We are going to show you how the archetype mechanism works now, but if you would like to know more about archetypes please refer to our Introduction to Archetypes .
On to creating your first project! In order to create the simplest of Maven projects, execute the following from the command line:
mvn archetype:create \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app
Once you have executed this command, you will notice a few things have happened. First, you will notice that a directory named my-app has been created for the new project, and this directory contains a file named pom.xmlthat 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>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
pom.xml contains the Project Object Model (POM) for this project. The POM is the basic unit of work in Maven. This is important to remember because Maven is inherently project-centric in that everything revolves around the notion of a project. In short, the POM contains every important piece of information about your project and is essentially one-stop-shopping for finding anything related to your project. Understanding the POM is important and new users are encouraged to refer to the Introduction to the POM .
This is a very simple POM but still displays the key elements every POM contains, so let's walk through each of them to familiarize you with the POM essentials:
- project This is the top-level element in all Maven pom.xml files.
- modelVersion This element indicates what version of the object model this POM is using. The version of the model itself changes very infrequently but it is mandatory in order to ensure stability of use if and when the Maven developers deem it necessary to change the model.
- groupId This element indicates the unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.
- artifactId This element indicates the unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form <artifactid>-<version>.<extension> (for example, myapp-1.0.jar ).</extension></version></artifactid>
- packaging This element indicates the package type to be used by this artifact (e.g. JAR, WAR, EAR, etc.). This not only means if the artifact produced is JAR, WAR, or EAR but can also indicate a specific lifecycle to use as part of the build process. (The lifecycle is a topic we will deal with further on in the guide. For now, just keep in mind that the indicated packaging of a project can play a part in customizing the build lifecycle.) The default value for the packaging element is JAR so you do not have to specify this for most projects.
- version This element indicates the version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development. We will discuss the use of snapshots and how they work further on in this guide.
- name This element indicates the display name used for the project. This is often used in Maven's generated documentation.
- url This element indicates where the project's site can be found. This is often used in Maven's generated documentation.
- description This element provides a basic description of your project. This is often used in Maven's generated documentation.
For a complete reference of what elements are available for use in the POM please refer to our POM Reference . Now let's get back to the project at hand.
After the archetype generation of your first project you will also notice that the following directory structure has been created:
my-app
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- mycompany
| `-- app
| `-- App.java
`-- test
`-- java
`-- com
`-- mycompany
`-- app
`-- AppTest.java
As you can see, the project created from the archetype has a POM, a source tree for your application's sources and a source tree for your test sources. This is the standard layout for Maven projects (the application sources reside in ${basedir}/src/main/java and test sources reside in ${basedir}/src/test/java , where ${basedir} represents the directory containing pom.xml ).
If you were to create a Maven project by hand this is the directory structure that we recommend using. This is a Maven convention and to learn more about it you can read our Introduction to the Standard Directory Layout .
Now that we have a POM, some application sources, and some test sources you are probably asking ...
http://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project
如果是建一个web项目的话 需要在命令中加上
-DarchetypeArtifactId=maven-archetype-webapp
http://today.java.net/pub/a/today/2007/03/01/building-web-applications-with-maven-2.html
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mcc.ineo4j -DartifactId=ineo4j-work
maven command to create your application的更多相关文章
- Jenkins参数化构建(二)之 Maven command line使用Jenkins参数
安装Extened Choice Parameter插件 General模块选择‘参数化构建过程’ 3. maven command line中使用 clean test -DsuiteXmlFi ...
- maven 笔记:maven Could not create the Java Virtual Machine
1.安装好maven,在cmd中运行mvn –v,报错:“maven Could not create the Java Virtual Machine” 2.分析:这是跟jvm有关,在cmd中运行 ...
- Java SE series:1. environment configure and Hello world! [We use compiler and packager to create an application!]
1. cli (command line interface) and gui (graphic user interface) use javahome path, search classpath ...
- hive udaf 用maven打包运行create temporary function 时报错
用maven打包写好的jar,在放到hive中作暂时函数时报错. 错误信息例如以下: hive> create temporary function maxvalue as "com. ...
- kivy Create an application
http://kivy.org/docs/guide/basic.html#quickstart I followed this tutorial about how to create basic ...
- Jenkins参数化构建(一)之 Maven Command Line传递TestNG构建参数
1. Maven使用 -D参数名称 将参数传递至所运行项目 Maven指定TestNg.xml文件 clean test -DsuiteXmlFile=src/main/resources/testn ...
- IDEA MAVEN Failed to create a Maven project 'C:/gitProjects/mayProj/pom.xml' already exists in VFS
When adding the module to an existing module that already has a POM, it is necessary to manually spe ...
- [NativeScript] Create new application and run emulator
Install: npm i -g nativescript Create: tns create <app_name> --ng Run: tns emulate ios List al ...
- maven command line specified settings.xml
1. using argument parameter --settings / or -s for shot mvn install --settings c:\user\settings.xml ...
随机推荐
- 【SPFA】POJ1860-Currency Exchange
[题目大意] 给出每两种货币之间交换的手续费和汇率,求出从当前货币s开始交换,能否赚. [思路] 反向运用SPFA,判断是否有正环.每次队首元素出队之后,判断一下到源点s的距离是否增大,增大则返回tr ...
- 在线HTTP速度测试(响应时间测试)及浏览器兼容测试
一.前言 网站的响应时间,是判断一个网站是否是好网站的重要的因素之一.百度首页的响应时间在全国各个省份小于10ms.这个响应时间远远好于竞争对手.根据美丽说的技术负责人分析,美丽说访问速度提升10%, ...
- C++ 刷题常用函数总结
平时常用C++刷一些算法题,C++内置了许多好用的工具函数,但时间一长总是容易忘记,这里简单做一下总结,方便复习! <stdlib.h> atoi(const char* str) 将一串 ...
- 利用Everything开启http服务测试移动端浏览器环境
一.Everything 简介 Everything本身是一款小巧的文件搜索神器,可以快速的搜索电脑中的文件,速度非常快. 二.使用Everything的http服务 在做移动端浏览器页面时,有时需要 ...
- HDU 4706 Children's Day (水题)
Children's Day Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- js 闭包范式概述
在前几篇文章中我介绍过js的闭包,这一篇主要简单的介绍一下js中闭包的范式. 那么何谓闭包的范式呢? 首先回想一下闭包的概念,闭包是外部函数与函数内部之间通信的桥梁,通过对函数的返回,使得外部的函数能 ...
- unix环境高级编程----进程控制wait()
一.wait()函数 当一个进程中调用wait()函数的时候 (1)假设其全部的子程序都还在执行,则堵塞 (2)假设一个子进程已终止.则等待父进程获取其终止状态. (3)假设没有子进程,则返回错误. ...
- cmake和make区别
大家都知道,写程序大体步骤为: 1.用编辑器编写源代码,如.c文件. 2.用编译器编译代码生成目标文件,如.o. 3.用链接器连接目标代码生成可执行文件,如.exe. 但如果源文件太多,一个一个编译时 ...
- web语义化,从松散到实战
GitHub:http://liu12fei08fei.github.io/html/4semantic.html web语义化,从松散到实战 在这篇文章之前,我放弃了很多次,写关于语义化方面的文章: ...
- jQuery 二级菜单,一次显示一个小类 鼠标点击显示小类
jQuery 二级菜单,一次显示一个小类 鼠标点击显示小类 本例有另外2个关联案例,演示地址分别为2.php,3.php 演示 XML/HTML Code <div class="ar ...