Maven系列笔记(三)—— 使用Intellij-IDEA创建Maven Web项目
一、使用 Maven 骨架创建 Java Web 项目
打开Intellij-IDEA,选择新建项目。
按照图示的步骤选择Maven组件,勾选“Create from archetype”,从原型创建Maven项目,选择webapp原型。
输入项目组织ID,点击下一步。
-
groupId: 代表组织和整个项目的唯一标志。例如,所有的Maven组件的groupId都是org.apache.maven。
-
artifactId: 具体项目的名称,它于groupId共同确定一个项目在maven repository中的位置。
例如,groupId=org.apache.tomcat, artifactId=tomcat-jdbct的项目,在maven repository中的位置为:C:\Users\Administrator.m2\repository\org\apache\tomcat\tomcat-jdbc。
因为国内连接远程获取原型(原型就是项目的模板,文件结构)速度会非常慢(慢到让人怀疑人生),点击加号添加参数,设置使用本地原型配置。
参数名为archetypeCatalog,值为internal,添加后点击下一步。
archetypeCatalog 表示创建项目的时候,从哪里获取项目原型,值有 :
- internal to use the internal catalog only.(使用内部的原型)
- local to use the local catalog only.(使用本地的原型)
- remote to use the maven’s remote catalog. No catalog is currently provided.(使用远程的原型)
- file://path/to/archetype-catalog.xml to use a specific local catalog. When the catalog file is named archetype-catalog.xml, it can be omitted.(使用本地指定位置的原型)
- http://url/to/archetype-catalog.xml to use a specific remote catalog. When the catalog file is named archetype-catalog.xml, it can be omitted.(使用远程指定位置的原型)
输入文件位置,点击完成。
- version: 用于说明目前项目的版本,在引用依赖的时候确定具体依赖的版本号。
- packaging: 规定项目的输出格式,包括jar、war、pom、apk等,根据实际需要确定。例如,开发一般的java库,可以使用jar packaging;开发android则是apk packaging。