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 ...
随机推荐
- PHP渗透中的奇淫技巧--检查相等时的漏洞
PHP是现在网站中最为常用的后端语言之一,是一种类型系统 动态.弱类型的面向对象式编程语言.可以嵌入HTML文本中,是目前最流行的web后端语言之一,并且可以和Web Server 如apache和n ...
- 【原创】实战padding oracle漏洞
首先关于padding oracle漏洞的原理请看: 步入正传~~ 搭建漏洞利用环境Perl 环境下载地址:链接:http://pan.baidu.com/s/1skFxVm1 密码:anuw 首先查 ...
- 【BZOJ】4565: [Haoi2016]字符合并
4565: [Haoi2016]字符合并 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 690 Solved: 316[Submit][Status ...
- Windows Phone background Audio 后台音频
Windows Phone 后台音频的确不是什么新鲜的话题了,但发现目前在WP平台的音频播放应用多多少少会有一些瑕疵,所以在此给大家在此介绍下这个功能给有需要的朋友们. 首先介绍下我们的应用在后台播放 ...
- hdu 4452 Running Rabbits 模拟
Running RabbitsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 洛谷OJ U552 守墓人 线段树模板题
题目描述 Description 在一个荒凉的墓地上 有一个令人尊敬的守墓人, 他看守的墓地从来 没有被盗过, 所以人们很放心的把自己的先人的墓 安顿在他那 守墓人能看好这片墓地是必然而不是偶然... ...
- hdu 1199 Color the Ball 离散线段树
C - Color the Ball Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- trigger、procedure和event如何同步
最近遇到一个需求涉及存储过程,被突然问题到如何同步问题问到了,赶紧补课学习一下. 首先,先看一下trigger.procedure和event的定义都是什么? trigger: 触发器是一个被指定关联 ...
- Go语言Web框架gwk介绍 (三)
上一篇忘了ChanResult ChanResult 可以用来模拟BigPipe,定义如下 type ChanResult struct { Wait sync.WaitGroup Chan chan ...
- CentOS使用chkconfig增加开机服务提示service xxx does not support chkconfig的问题解决
在shell文件的第二行增加如下内容即可: # chkconfig: 2345 10 90 #服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10. # descrip ...