好久没有使用maven建新项目,创建过程已经记得模模糊糊了,写下这篇日志备忘一下过程,也可以给有需要的同学作为参考。
一、创建maven本地仓库(windows)
1、下载apache-maven-3.5.0-bin.zip,目前(2017-10-22)最新版
2、配置maven环境
解压apache-maven-3.5.0-bin.zip到任意目录;
在windows环境变量->系统变量中新建 变量名:MAVEN_HOME 变量值:E:\java\apache-maven-3.5.0(解压后的路径,到bin文件夹就可) 添加 变量名:Path 变量值:%MAVEN_HOME%\bin; 确定保存,在cmd窗口使用mvn -v验证。
3、修改setting.xml文件,配置本地仓库路径
<settings>
<localRepository>E:\java\repository</localRepository>
</settings>
二、eclipse中创建maven项目(Oxygen.1a版本)
1、window->Preferences->Maven->Installations中添加我们自己配置的maven路径,选中保存;
2、File->new->Maven Project,勾选第一个和第二个(不适用模板),填写好对应信息,Packaging选择打包方式:war,finish完成创建。
3、此时项目有一个WebContent,将里面的META-INF和WEB-INF剪切放到src/main/webapp下,删除WebContent文件夹。
4、右击项目选择Properties->Project Facts,修改java为1.8,Dynamic web module为3.0,右边选择runtime选项卡,勾选tomcat(没有配可以跳过);选择Properties->Deployment Assembly,留下src/main/路径的其他的都remove,最后保存。
配置完成
1、pom.xml红叉,project->clean一下就好。
2、Java Resources红叉,在pom.xml中加入下列代码,clean一下。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
在webapp下建一个index.jsp,运行tomcat,测试成功。