一.maven的安装
1.下载maven 网址:http://maven.apache.org/ 2.在某个目录建立maven目录,我的是C:\Java\maven 3.解压下载好的maven到C:\Java\maven目录下 4.添加系统变量 新建变量名 MAVEN_HOME ,变量值: C:\Java\maven\apache-maven-3.2.5 5.更改path:在末尾追加 ;%MAVEN_HOME%\bin 6.cmd切换到命令行窗口,运行 mvn -v 7.如果出现版本信息,说明maven已经安装好
二.本地仓库的建立及默认存储地址的更改
1.存储目录的建立,我是在maven中建了一个文件夹respository,完整目录C:\Java\maven\respository 2.到C:\Java\maven\apache-maven-3.2.5\conf中拷贝settings.xml文件到C:\Java\maven\respository 3.修改C:\Java\maven\apache-maven-3.2.5\conf及C:\Java\maven\respository中的settings.xml中的本地仓库地址
4.配置mirror(采用阿里云的maven仓库)
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
5.配置profile(采用阿里云的maven仓库地址)
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
6.修改默认编译的jdk版本为1.7(如果要用1.8)参考1.7的配置,修改settings.xml,在profiles节点下面增加如下配置
<profile>
<id>jdk-1.7</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.7</jdk>
</activation>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
</profile>
7,把该settings.xml拷贝一份到C:\Java\maven\respository下
三.maven在eclipse中的配置
1.eclipse中需要安装m2eclipse插件 2.配置,Window-->preferences-->maven 3.按1,2,3,4的步骤配置maven的路径
4.配置User Settings
四.STS创建maven项目
1.新建Maven Project
2.选择Archetype
3.输入Group Id Artifact Id,完成创建
五.STS创建springMVC maven项目
1.新建Spring Legacy Project
2.输入项目名称,选择模板(Templates)
3.输入顶级包名,完成创建
4.创建后的工程目录如下
六.jetty插件的安装
1.在web工程的pom.xml中<project>标签中增加如下配置
<build>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<reload>manual</reload>
<webApp>
<contextPath>/</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
</plugins>
</build>
2.在maven的本地仓库配置文件settings.xml中的<pluginGroups>标签中增加如下配置:
<pluginGroups>
<!--
pluginGroup | Specifies a further group identifier to use for plugin
lookup. <pluginGroup>com.your.plugins</pluginGroup>
-->
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
3.右键pomx.ml-->run as-->maven build-->输入 jetty:run-->回车(启动容器),接着就可以http://localhost:8080/模块名/list这样的形式访问了